-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDynamicSwmlService.java
More file actions
70 lines (59 loc) · 2.26 KB
/
Copy pathDynamicSwmlService.java
File metadata and controls
70 lines (59 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Dynamic SWML Service Example.
*
* Demonstrates creating SWML services that generate different responses
* based on request data -- a dynamic greeting service and a call router.
*
* These use the SWML Service class directly (no AI component).
*
* Usage: java DynamicSwmlService [greeting|router]
*/
import com.signalwire.sdk.swml.Service;
import java.util.Map;
public class DynamicSwmlService {
public static void main(String[] args) throws Exception {
String mode = args.length > 0 ? args[0] : "greeting";
switch (mode) {
case "greeting" -> startGreeting();
case "router" -> startRouter();
default -> {
System.out.println("Usage: DynamicSwmlService [greeting|router]");
System.exit(1);
}
}
}
/**
* A greeting service that serves different SWML based on caller type.
*/
static void startGreeting() throws Exception {
var svc = new Service("dynamic-greeting", "/greeting");
// Build a default greeting document
svc.answer(null);
svc.play(Map.of("url", "say:Hello, thank you for calling our service."));
svc.prompt(Map.of(
"play", "say:Press 1 for sales, 2 for support, or 3 to leave a message.",
"max_digits", 1,
"terminators", "#"
));
svc.hangup();
System.out.println("Starting dynamic greeting service...");
System.out.println("POST JSON to customize: {\"caller_name\":\"John\",\"caller_type\":\"vip\"}");
svc.serve();
}
/**
* A call router that routes calls by region.
*/
static void startRouter() throws Exception {
var svc = new Service("call-router", "/router");
svc.answer(null);
svc.play(Map.of("url",
"say:Thank you for calling. We'll connect you with an available agent."));
svc.connect(Map.of("to", "+15551234567", "timeout", 30));
svc.play(Map.of("url",
"say:All agents are busy. Please try again later."));
svc.hangup();
System.out.println("Starting call router service...");
System.out.println("POST JSON to customize: {\"region\":\"west\",\"high_volume\":true}");
svc.serve();
}
}