-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSwmlServiceRoutingExample.java
More file actions
53 lines (46 loc) · 2 KB
/
Copy pathSwmlServiceRoutingExample.java
File metadata and controls
53 lines (46 loc) · 2 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
/**
* SWML Service Routing Example.
*
* Demonstrates building multiple SWML document sections and serving
* different content based on the path -- all from a single Service instance.
*
* Paths served:
* /main -> Default greeting
* /customer -> Customer service greeting
* /product -> Product information greeting
*/
import com.signalwire.sdk.swml.Service;
import java.util.Map;
public class SwmlServiceRoutingExample {
public static void main(String[] args) throws Exception {
// Main service at /main
var mainSvc = new Service("main-service", "/main");
mainSvc.answer(null);
mainSvc.play(Map.of("url", "say:Hello from the main service!"));
mainSvc.hangup();
// Customer service at /customer
var customerSvc = new Service("customer-service", "/customer");
customerSvc.answer(null);
customerSvc.play(Map.of("url", "say:Hello from customer service!"));
customerSvc.prompt(Map.of(
"play", "say:Press 1 for account management, 2 for technical support.",
"max_digits", 1,
"terminators", "#"
));
customerSvc.hangup();
// Product service at /product
var productSvc = new Service("product-service", "/product");
productSvc.answer(null);
productSvc.play(Map.of("url", "say:Hello from the product service!"));
productSvc.play(Map.of("url",
"say:We offer voice, video, and messaging APIs for modern applications."));
productSvc.hangup();
// Start all three services on different ports
// In production you'd use a single server with routing; here we start main.
System.out.println("Starting SWML routing example...");
System.out.println(" Main: http://localhost:3000/main");
System.out.println(" Customer: (use AgentServer for multi-route hosting)");
System.out.println(" Product: (use AgentServer for multi-route hosting)");
mainSvc.serve();
}
}