Skip to content

Commit 5ea1e65

Browse files
authored
feat: Add Conversation snippets (#119)
* feat: Add Conversation snippets * feat: Add missing Voice snippets * chore: Run AggregateSnippets * refactor: Rename new voice snippets
1 parent e1fc900 commit 5ea1e65

26 files changed

+905
-11
lines changed

.env-example

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ ACCOUNT_SMS_CALLBACK_URL="https://example.org/webhooks/sms-status"
1919
# Application
2020
APPLICATION_NAME="My Test Application"
2121

22+
# Conversation
23+
CONV_DISPLAY_NAME="Customer Chat"
24+
CONV_EVENT_ID="23"
25+
CONV_ID="CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a"
26+
CONV_MEMBER_ID="MEM-63f61863-4a51-4f6b-86e1-46edebio0391"
27+
CONV_MEMBER_STATE="invited"
28+
CONV_NAME="customer_chat"
29+
CONV_NEW_DISPLAY_NAME="Support Meeting"
30+
CONV_NEW_NAME="support_meeting"
31+
2232
# Messages
2333
MESSAGES_TO_NUMBER="447900000001"
2434
MESSAGES_API_URL="https://api.nexmo.com/v1/messages"

SNIPPETS.md

+142-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This file was generated by running [AggregateSnippets.java](src/main/java/Aggreg
66
- [**Initialize**](#initialize)
77
- [**Account**](#account)
88
- [**Application**](#application)
9+
- [**Conversation**](#conversation)
910
- [**Number Insight**](#number-insight)
1011
- [**JWT**](#jwt)
1112
- [**Meetings**](#meetings)
@@ -175,6 +176,127 @@ System.out.println("Application Updated:");
175176
System.out.println("Old: " + existingApplication.toJson());
176177
System.out.println("New: " + application.toJson());
177178
```
179+
## Conversation
180+
### Get Member
181+
182+
```java
183+
var member = client.getConversationsClient().getMember(CONV_ID, CONV_MEMBER_ID);
184+
System.out.println(member);
185+
```
186+
### Delete Conversation
187+
188+
```java
189+
client.getConversationsClient().deleteConversation(CONV_ID);
190+
```
191+
### Delete Event
192+
193+
```java
194+
client.getConversationsClient().deleteEvent(CONV_ID, CONV_EVENT_ID);
195+
```
196+
### Create Conversation
197+
198+
```java
199+
var conversation = client.getConversationsClient().createConversation(
200+
Conversation.builder()
201+
.name(CONV_NAME)
202+
.displayName(CONV_DISPLAY_NAME)
203+
.build()
204+
);
205+
System.out.println(conversation);
206+
```
207+
### List User Conversations
208+
209+
```java
210+
var conversations = client.getConversationsClient().listUserConversations(USER_ID);
211+
conversations.forEach(System.out::println);
212+
```
213+
### Get Conversation
214+
215+
```java
216+
var conversation = client.getConversationsClient().getConversation(CONV_ID);
217+
System.out.println(conversation);
218+
```
219+
### Update Member
220+
221+
```java
222+
var updated = client.getConversationsClient().updateMember(
223+
UpdateMemberRequest.builder()
224+
.conversationId(CONV_ID)
225+
.memberId(CONV_MEMBER_ID)
226+
.state(CONV_MEMBER_STATE)
227+
.build()
228+
);
229+
System.out.println(updated);
230+
```
231+
### Get Event
232+
233+
```java
234+
var event = client.getConversationsClient().getEvent(CONV_ID, CONV_EVENT_ID);
235+
System.out.println(event);
236+
```
237+
### Create Custom Event
238+
239+
```java
240+
var event = client.getConversationsClient().createEvent(
241+
CONV_ID, CustomEvent.builder()
242+
.from(CONV_MEMBER_ID)
243+
.body(Map.of("your", "data"))
244+
.build()
245+
);
246+
System.out.println(event);
247+
```
248+
### Create Event
249+
250+
```java
251+
var event = client.getConversationsClient().createEvent(
252+
CONV_ID, MessageEvent.builder(MessageType.TEXT)
253+
.from(CONV_MEMBER_ID)
254+
.text("Hello World!")
255+
.build()
256+
);
257+
System.out.println(event);
258+
```
259+
### Create Member
260+
261+
```java
262+
var member = client.getConversationsClient().createMember(
263+
CONV_ID, Member.builder()
264+
.channelType(ChannelType.APP)
265+
.state(CONV_MEMBER_STATE)
266+
.user(USER_ID)
267+
.build()
268+
);
269+
System.out.println(member);
270+
```
271+
### List Conversations
272+
273+
```java
274+
var conversations = client.getConversationsClient().listConversations();
275+
conversations.forEach(System.out::println);
276+
```
277+
### Update Conversation
278+
279+
```java
280+
var updated = client.getConversationsClient().updateConversation(
281+
CONV_ID, Conversation.builder()
282+
.name(CONV_NEW_NAME)
283+
.displayName(CONV_NEW_DISPLAY_NAME)
284+
.build()
285+
);
286+
System.out.println(updated);
287+
```
288+
### List Events
289+
290+
```java
291+
var events = client.getConversationsClient().listEvents(CONV_ID);
292+
events.forEach(System.out::println);
293+
```
294+
### List Members
295+
296+
```java
297+
var members = client.getConversationsClient().listMembers(CONV_ID);
298+
members.forEach(System.out::println);
299+
```
178300
## Number Insight
179301
### Basic Insight
180302

@@ -2657,6 +2779,16 @@ post("/webhooks/notification", (req, res) -> {
26572779
).toJson();
26582780
});
26592781
```
2782+
### Stop Audio Stream
2783+
2784+
```java
2785+
var response = client.getVoiceClient().stopStream(VOICE_CALL_ID);
2786+
```
2787+
### Unsubscribe From DTMF Events
2788+
2789+
```java
2790+
client.getVoiceClient().removeDtmfListener(VOICE_CALL_ID);
2791+
```
26602792
### Transfer Call NCCO
26612793

26622794
```java
@@ -2761,6 +2893,11 @@ Spark.port(3000);
27612893
Spark.get("/webhooks/answer", answerRoute);
27622894
Spark.post("/webhooks/answer", answerRoute);
27632895
```
2896+
### Stop Text To Speech
2897+
2898+
```java
2899+
var response = client.getVoiceClient().stopTalk(VOICE_CALL_ID);
2900+
```
27642901
### Record Call
27652902

27662903
```java
@@ -2794,6 +2931,11 @@ Spark.port(3000);
27942931
Spark.get("/webhooks/answer", answerRoute);
27952932
Spark.post("/webhooks/recordings", recordingRoute);
27962933
```
2934+
### Subscribe To DTMF Events
2935+
2936+
```java
2937+
client.getVoiceClient().addDtmfListener(VOICE_CALL_ID, VOICE_EVENT_URL);
2938+
```
27972939
### Stream Audio To Call
27982940

27992941
```java
@@ -3010,9 +3152,3 @@ Ncco ncco = new Ncco(TalkAction.builder("This is a text to speech call from Vona
30103152

30113153
client.getVoiceClient().createCall(new Call(VOICE_TO_NUMBER, VONAGE_VIRTUAL_NUMBER, ncco.getActions()));
30123154
```
3013-
GE_VIRTUAL_NUMBER, ncco.getActions()));
3014-
```
3015-
age").build());
3016-
3017-
client.getVoiceClient().createCall(new Call(VOICE_TO_NUMBER, VONAGE_VIRTUAL_NUMBER, ncco.getActions()));
3018-
```

src/main/java/com/vonage/quickstart/EnvironmentVariables.java

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package com.vonage.quickstart;
2323

2424
import com.vonage.client.ApiRegion;
25+
import com.vonage.client.conversations.MemberState;
2526
import com.vonage.client.numbers.Feature;
2627
import com.vonage.client.numbers.SearchPattern;
2728
import com.vonage.client.numbers.Type;
@@ -83,6 +84,12 @@ public static String envVar(String key) {
8384
ACCOUNT_SECRET_ID = envVar("ACCOUNT_SECRET_ID"),
8485
ACCOUNT_SMS_CALLBACK_URL = envVar("ACCOUNT_SMS_CALLBACK_URL"),
8586
APPLICATION_NAME = envVar("APPLICATION_NAME"),
87+
CONV_DISPLAY_NAME = envVar("CONV_DISPLAY_NAME"),
88+
CONV_ID = envVar("CONV_ID"),
89+
CONV_MEMBER_ID = envVar("CONV_MEMBER_ID"),
90+
CONV_NAME = envVar("CONV_NAME"),
91+
CONV_NEW_NAME = envVar("CONV_NEW_NAME"),
92+
CONV_NEW_DISPLAY_NAME = envVar("CONV_NEW_DISPLAY_NAME"),
8693
MESSAGES_TO_NUMBER = envVar("MESSAGES_TO_NUMBER"),
8794
MESSAGES_MESSAGE_ID = envVar("MESSAGES_MESSAGE_ID"),
8895
MESSAGES_IMAGE_URL = envVar("MESSAGES_IMAGE_URL"),
@@ -159,6 +166,7 @@ public static String envVar(String key) {
159166
VONAGE_PRIVATE_KEY_CONTENTS = envVar("VONAGE_PRIVATE_KEY_CONTENTS").getBytes();
160167

161168
public static final int
169+
CONV_EVENT_ID = Integer.parseInt(envVar("CONV_EVENT_ID")),
162170
VIBER_VIDEO_DURATION = Integer.parseInt(envVar("VIBER_VIDEO_DURATION")),
163171
VIBER_VIDEO_FILE_SIZE = Integer.parseInt(envVar("VIBER_VIDEO_FILE_SIZE")),
164172
VIBER_VIDEO_TTL = Integer.parseInt(envVar("VIBER_VIDEO_TTL")),
@@ -177,6 +185,9 @@ public static String envVar(String key) {
177185
public static final Instant
178186
SUBACCOUNT_START_DATE = Instant.parse(envVar("SUBACCOUNT_START_DATE"));
179187

188+
public static final MemberState
189+
CONV_MEMBER_STATE = MemberState.fromString(envVar("CONV_MEMBER_STATE"));
190+
180191
public static final Type
181192
NUMBER_TYPE = Type.fromString(envVar("NUMBER_TYPE"));
182193

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package com.vonage.quickstart.conversation;
23+
24+
import com.vonage.client.VonageClient;
25+
import com.vonage.client.conversations.Conversation;
26+
import static com.vonage.quickstart.EnvironmentVariables.*;
27+
28+
public class CreateConversation {
29+
public static void main(String[] args) throws Exception {
30+
VonageClient client = VonageClient.builder()
31+
.applicationId(VONAGE_APPLICATION_ID)
32+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
33+
.build();
34+
35+
var conversation = client.getConversationsClient().createConversation(
36+
Conversation.builder()
37+
.name(CONV_NAME)
38+
.displayName(CONV_DISPLAY_NAME)
39+
.build()
40+
);
41+
System.out.println(conversation);
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package com.vonage.quickstart.conversation;
23+
24+
import com.vonage.client.VonageClient;
25+
import com.vonage.client.conversations.CustomEvent;
26+
import static com.vonage.quickstart.EnvironmentVariables.*;
27+
import java.util.Map;
28+
29+
public class CreateCustomEvent {
30+
public static void main(String[] args) throws Exception {
31+
VonageClient client = VonageClient.builder()
32+
.applicationId(VONAGE_APPLICATION_ID)
33+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
34+
.build();
35+
36+
var event = client.getConversationsClient().createEvent(
37+
CONV_ID, CustomEvent.builder()
38+
.from(CONV_MEMBER_ID)
39+
.body(Map.of("your", "data"))
40+
.build()
41+
);
42+
System.out.println(event);
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package com.vonage.quickstart.conversation;
23+
24+
import com.vonage.client.VonageClient;
25+
import com.vonage.client.common.MessageType;
26+
import com.vonage.client.conversations.MessageEvent;
27+
import static com.vonage.quickstart.EnvironmentVariables.*;
28+
29+
public class CreateEvent {
30+
public static void main(String[] args) throws Exception {
31+
VonageClient client = VonageClient.builder()
32+
.applicationId(VONAGE_APPLICATION_ID)
33+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
34+
.build();
35+
36+
var event = client.getConversationsClient().createEvent(
37+
CONV_ID, MessageEvent.builder(MessageType.TEXT)
38+
.from(CONV_MEMBER_ID)
39+
.text("Hello World!")
40+
.build()
41+
);
42+
System.out.println(event);
43+
}
44+
}

0 commit comments

Comments
 (0)