-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSwmlServiceExample.java
More file actions
104 lines (91 loc) · 3.4 KB
/
Copy pathSwmlServiceExample.java
File metadata and controls
104 lines (91 loc) · 3.4 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Basic SWML Service Example.
*
* Uses the Service class directly to build and serve SWML documents
* without AI components -- voicemail, IVR menu, call transfer, and recording.
*/
import com.signalwire.sdk.swml.Service;
import java.util.Map;
public class SwmlServiceExample {
public static void main(String[] args) throws Exception {
String mode = args.length > 0 ? args[0] : "voicemail";
switch (mode) {
case "voicemail" -> startVoicemail();
case "ivr" -> startIvr();
case "transfer" -> startTransfer();
case "record" -> startRecording();
default -> {
System.out.println("Usage: SwmlService [voicemail|ivr|transfer|record]");
System.exit(1);
}
}
}
static void startVoicemail() throws Exception {
var svc = new Service("voicemail", "/voicemail");
svc.answer(null);
svc.play(Map.of("url",
"say:Hello, you've reached the voicemail service. Please leave a message after the beep."));
svc.sleep(1000);
svc.record(Map.of(
"format", "mp3",
"stereo", false,
"beep", true,
"max_length", 120,
"terminators", "#"
));
svc.play(Map.of("url", "say:Thank you for your message. Goodbye!"));
svc.hangup();
System.out.println("Starting voicemail service...");
svc.serve();
}
static void startIvr() throws Exception {
var svc = new Service("ivr", "/ivr");
svc.answer(null);
svc.prompt(Map.of(
"play", "say:Welcome. Press 1 for sales, 2 for support, or 3 to leave a message.",
"max_digits", 1,
"terminators", "#",
"digit_timeout", 5.0,
"initial_timeout", 10.0
));
svc.hangup();
System.out.println("Starting IVR service...");
svc.serve();
}
static void startTransfer() throws Exception {
var svc = new Service("transfer", "/transfer");
svc.answer(null);
svc.play(Map.of("url",
"say:Thank you for calling. We'll connect you with the next available agent."));
svc.connect(Map.of(
"from", "+15551234567",
"timeout", 30,
"answer_on_bridge", true
));
svc.play(Map.of("url",
"say:All agents are busy. Please leave a message."));
svc.record(Map.of("format", "mp3", "max_length", 120, "terminators", "#"));
svc.hangup();
System.out.println("Starting transfer service...");
svc.serve();
}
static void startRecording() throws Exception {
var svc = new Service("record", "/record");
svc.answer(null);
svc.recordCall(Map.of(
"control_id", "call_recording",
"format", "mp3",
"stereo", true,
"direction", "both",
"beep", true
));
svc.play(Map.of("url",
"say:This call is being recorded. Please tell us about your experience."));
svc.sleep(30000);
svc.stopRecordCall(Map.of("control_id", "call_recording"));
svc.play(Map.of("url", "say:Thank you for your time. Goodbye!"));
svc.hangup();
System.out.println("Starting recording service...");
svc.serve();
}
}