Skip to content

Commit 5761f85

Browse files
committed
feat: Add Conversation snippets
1 parent e1fc900 commit 5761f85

21 files changed

+619
-5
lines changed

.env-example

Lines changed: 10 additions & 0 deletions
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_NAME="support_meeting"
30+
CONV_NEW_DISPLAY_NAME="Support Meeting"
31+
2232
# Messages
2333
MESSAGES_TO_NUMBER="447900000001"
2434
MESSAGES_API_URL="https://api.nexmo.com/v1/messages"

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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 43 additions & 0 deletions
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+
}
Lines changed: 44 additions & 0 deletions
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+
}
Lines changed: 44 additions & 0 deletions
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+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.ChannelType;
26+
import com.vonage.client.conversations.Member;
27+
import static com.vonage.quickstart.EnvironmentVariables.*;
28+
29+
public class CreateMember {
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 member = client.getConversationsClient().createMember(
37+
CONV_ID, Member.builder()
38+
.channelType(ChannelType.APP)
39+
.state(CONV_MEMBER_STATE)
40+
.user(USER_ID)
41+
.build()
42+
);
43+
System.out.println(member);
44+
}
45+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 static com.vonage.quickstart.EnvironmentVariables.*;
26+
27+
public class DeleteConversation {
28+
public static void main(String[] args) throws Exception {
29+
VonageClient client = VonageClient.builder()
30+
.applicationId(VONAGE_APPLICATION_ID)
31+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
32+
.build();
33+
34+
client.getConversationsClient().deleteConversation(CONV_ID);
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 static com.vonage.quickstart.EnvironmentVariables.*;
26+
27+
public class DeleteEvent {
28+
public static void main(String[] args) throws Exception {
29+
VonageClient client = VonageClient.builder()
30+
.applicationId(VONAGE_APPLICATION_ID)
31+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
32+
.build();
33+
34+
client.getConversationsClient().deleteEvent(CONV_ID, CONV_EVENT_ID);
35+
}
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 static com.vonage.quickstart.EnvironmentVariables.*;
26+
27+
public class GetConversation {
28+
public static void main(String[] args) throws Exception {
29+
VonageClient client = VonageClient.builder()
30+
.applicationId(VONAGE_APPLICATION_ID)
31+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
32+
.build();
33+
34+
var conversation = client.getConversationsClient().getConversation(CONV_ID);
35+
System.out.println(conversation);
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 static com.vonage.quickstart.EnvironmentVariables.*;
26+
27+
public class GetEvent {
28+
public static void main(String[] args) throws Exception {
29+
VonageClient client = VonageClient.builder()
30+
.applicationId(VONAGE_APPLICATION_ID)
31+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
32+
.build();
33+
34+
var event = client.getConversationsClient().getEvent(CONV_ID, CONV_EVENT_ID);
35+
System.out.println(event);
36+
}
37+
}

0 commit comments

Comments
 (0)