-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuickstartRest.java
More file actions
51 lines (44 loc) · 1.86 KB
/
Copy pathQuickstartRest.java
File metadata and controls
51 lines (44 loc) · 1.86 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
/**
* README quickstart — the REST Client block.
*
* The `region: quickstart` span below is included byte-for-byte into README.md
* via `<!-- include: examples/QuickstartRest.java#quickstart -->`, so the doc
* code is this compiled, gate-run example and can never drift.
*
* Requires env vars: SIGNALWIRE_PROJECT_ID, SIGNALWIRE_API_TOKEN, SIGNALWIRE_SPACE.
*
* NOTE: play() and datasphere search() take generated, typed request objects
* (Calling.PlayRequest / DatasphereDocuments.SearchRequest), not raw Maps —
* create()/list()/phoneNumbers().search() still take Maps.
*/
// region: quickstart
import com.signalwire.sdk.rest.RestClient;
import com.signalwire.sdk.rest.namespaces.generated.Calling;
import com.signalwire.sdk.rest.namespaces.generated.DatasphereDocuments;
import java.util.List;
import java.util.Map;
public class QuickstartRest {
public static void main(String[] args) throws Exception {
var client = RestClient.builder()
.project("your-project-id")
.token("your-api-token")
.space("example.signalwire.com")
.build();
// Create an AI agent
client.fabric().aiAgents().create(Map.of(
"name", "Support Bot",
"prompt", Map.of("text", "You are a helpful support agent.")
));
// Control a live call
client.calling().play("call-id", Calling.PlayRequest.builder()
.play(List.of(Map.of("type", "tts", "params", Map.of("text", "Hello!"))))
.build());
// Search for phone numbers
client.phoneNumbers().search(Map.of("areacode", "512"));
// Semantic search across documents
client.datasphere().documents().search(DatasphereDocuments.SearchRequest.builder()
.queryString("billing policy")
.build());
}
}
// endregion: quickstart