Skip to content

feat: Add Conversation snippets #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ ACCOUNT_SMS_CALLBACK_URL="https://example.org/webhooks/sms-status"
# Application
APPLICATION_NAME="My Test Application"

# Conversation
CONV_DISPLAY_NAME="Customer Chat"
CONV_EVENT_ID="23"
CONV_ID="CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a"
CONV_MEMBER_ID="MEM-63f61863-4a51-4f6b-86e1-46edebio0391"
CONV_MEMBER_STATE="invited"
CONV_NAME="customer_chat"
CONV_NEW_DISPLAY_NAME="Support Meeting"
CONV_NEW_NAME="support_meeting"

# Messages
MESSAGES_TO_NUMBER="447900000001"
MESSAGES_API_URL="https://api.nexmo.com/v1/messages"
Expand Down
148 changes: 142 additions & 6 deletions SNIPPETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This file was generated by running [AggregateSnippets.java](src/main/java/Aggreg
- [**Initialize**](#initialize)
- [**Account**](#account)
- [**Application**](#application)
- [**Conversation**](#conversation)
- [**Number Insight**](#number-insight)
- [**JWT**](#jwt)
- [**Meetings**](#meetings)
Expand Down Expand Up @@ -175,6 +176,127 @@ System.out.println("Application Updated:");
System.out.println("Old: " + existingApplication.toJson());
System.out.println("New: " + application.toJson());
```
## Conversation
### Get Member

```java
var member = client.getConversationsClient().getMember(CONV_ID, CONV_MEMBER_ID);
System.out.println(member);
```
### Delete Conversation

```java
client.getConversationsClient().deleteConversation(CONV_ID);
```
### Delete Event

```java
client.getConversationsClient().deleteEvent(CONV_ID, CONV_EVENT_ID);
```
### Create Conversation

```java
var conversation = client.getConversationsClient().createConversation(
Conversation.builder()
.name(CONV_NAME)
.displayName(CONV_DISPLAY_NAME)
.build()
);
System.out.println(conversation);
```
### List User Conversations

```java
var conversations = client.getConversationsClient().listUserConversations(USER_ID);
conversations.forEach(System.out::println);
```
### Get Conversation

```java
var conversation = client.getConversationsClient().getConversation(CONV_ID);
System.out.println(conversation);
```
### Update Member

```java
var updated = client.getConversationsClient().updateMember(
UpdateMemberRequest.builder()
.conversationId(CONV_ID)
.memberId(CONV_MEMBER_ID)
.state(CONV_MEMBER_STATE)
.build()
);
System.out.println(updated);
```
### Get Event

```java
var event = client.getConversationsClient().getEvent(CONV_ID, CONV_EVENT_ID);
System.out.println(event);
```
### Create Custom Event

```java
var event = client.getConversationsClient().createEvent(
CONV_ID, CustomEvent.builder()
.from(CONV_MEMBER_ID)
.body(Map.of("your", "data"))
.build()
);
System.out.println(event);
```
### Create Event

```java
var event = client.getConversationsClient().createEvent(
CONV_ID, MessageEvent.builder(MessageType.TEXT)
.from(CONV_MEMBER_ID)
.text("Hello World!")
.build()
);
System.out.println(event);
```
### Create Member

```java
var member = client.getConversationsClient().createMember(
CONV_ID, Member.builder()
.channelType(ChannelType.APP)
.state(CONV_MEMBER_STATE)
.user(USER_ID)
.build()
);
System.out.println(member);
```
### List Conversations

```java
var conversations = client.getConversationsClient().listConversations();
conversations.forEach(System.out::println);
```
### Update Conversation

```java
var updated = client.getConversationsClient().updateConversation(
CONV_ID, Conversation.builder()
.name(CONV_NEW_NAME)
.displayName(CONV_NEW_DISPLAY_NAME)
.build()
);
System.out.println(updated);
```
### List Events

```java
var events = client.getConversationsClient().listEvents(CONV_ID);
events.forEach(System.out::println);
```
### List Members

```java
var members = client.getConversationsClient().listMembers(CONV_ID);
members.forEach(System.out::println);
```
## Number Insight
### Basic Insight

Expand Down Expand Up @@ -2657,6 +2779,16 @@ post("/webhooks/notification", (req, res) -> {
).toJson();
});
```
### Stop Audio Stream

```java
var response = client.getVoiceClient().stopStream(VOICE_CALL_ID);
```
### Unsubscribe From DTMF Events

```java
client.getVoiceClient().removeDtmfListener(VOICE_CALL_ID);
```
### Transfer Call NCCO

```java
Expand Down Expand Up @@ -2761,6 +2893,11 @@ Spark.port(3000);
Spark.get("/webhooks/answer", answerRoute);
Spark.post("/webhooks/answer", answerRoute);
```
### Stop Text To Speech

```java
var response = client.getVoiceClient().stopTalk(VOICE_CALL_ID);
```
### Record Call

```java
Expand Down Expand Up @@ -2794,6 +2931,11 @@ Spark.port(3000);
Spark.get("/webhooks/answer", answerRoute);
Spark.post("/webhooks/recordings", recordingRoute);
```
### Subscribe To DTMF Events

```java
client.getVoiceClient().addDtmfListener(VOICE_CALL_ID, VOICE_EVENT_URL);
```
### Stream Audio To Call

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

client.getVoiceClient().createCall(new Call(VOICE_TO_NUMBER, VONAGE_VIRTUAL_NUMBER, ncco.getActions()));
```
GE_VIRTUAL_NUMBER, ncco.getActions()));
```
age").build());

client.getVoiceClient().createCall(new Call(VOICE_TO_NUMBER, VONAGE_VIRTUAL_NUMBER, ncco.getActions()));
```
11 changes: 11 additions & 0 deletions src/main/java/com/vonage/quickstart/EnvironmentVariables.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package com.vonage.quickstart;

import com.vonage.client.ApiRegion;
import com.vonage.client.conversations.MemberState;
import com.vonage.client.numbers.Feature;
import com.vonage.client.numbers.SearchPattern;
import com.vonage.client.numbers.Type;
Expand Down Expand Up @@ -83,6 +84,12 @@ public static String envVar(String key) {
ACCOUNT_SECRET_ID = envVar("ACCOUNT_SECRET_ID"),
ACCOUNT_SMS_CALLBACK_URL = envVar("ACCOUNT_SMS_CALLBACK_URL"),
APPLICATION_NAME = envVar("APPLICATION_NAME"),
CONV_DISPLAY_NAME = envVar("CONV_DISPLAY_NAME"),
CONV_ID = envVar("CONV_ID"),
CONV_MEMBER_ID = envVar("CONV_MEMBER_ID"),
CONV_NAME = envVar("CONV_NAME"),
CONV_NEW_NAME = envVar("CONV_NEW_NAME"),
CONV_NEW_DISPLAY_NAME = envVar("CONV_NEW_DISPLAY_NAME"),
MESSAGES_TO_NUMBER = envVar("MESSAGES_TO_NUMBER"),
MESSAGES_MESSAGE_ID = envVar("MESSAGES_MESSAGE_ID"),
MESSAGES_IMAGE_URL = envVar("MESSAGES_IMAGE_URL"),
Expand Down Expand Up @@ -159,6 +166,7 @@ public static String envVar(String key) {
VONAGE_PRIVATE_KEY_CONTENTS = envVar("VONAGE_PRIVATE_KEY_CONTENTS").getBytes();

public static final int
CONV_EVENT_ID = Integer.parseInt(envVar("CONV_EVENT_ID")),
VIBER_VIDEO_DURATION = Integer.parseInt(envVar("VIBER_VIDEO_DURATION")),
VIBER_VIDEO_FILE_SIZE = Integer.parseInt(envVar("VIBER_VIDEO_FILE_SIZE")),
VIBER_VIDEO_TTL = Integer.parseInt(envVar("VIBER_VIDEO_TTL")),
Expand All @@ -177,6 +185,9 @@ public static String envVar(String key) {
public static final Instant
SUBACCOUNT_START_DATE = Instant.parse(envVar("SUBACCOUNT_START_DATE"));

public static final MemberState
CONV_MEMBER_STATE = MemberState.fromString(envVar("CONV_MEMBER_STATE"));

public static final Type
NUMBER_TYPE = Type.fromString(envVar("NUMBER_TYPE"));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2025 Vonage
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.vonage.quickstart.conversation;

import com.vonage.client.VonageClient;
import com.vonage.client.conversations.Conversation;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class CreateConversation {
public static void main(String[] args) throws Exception {
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();

var conversation = client.getConversationsClient().createConversation(
Conversation.builder()
.name(CONV_NAME)
.displayName(CONV_DISPLAY_NAME)
.build()
);
System.out.println(conversation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2025 Vonage
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.vonage.quickstart.conversation;

import com.vonage.client.VonageClient;
import com.vonage.client.conversations.CustomEvent;
import static com.vonage.quickstart.EnvironmentVariables.*;
import java.util.Map;

public class CreateCustomEvent {
public static void main(String[] args) throws Exception {
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();

var event = client.getConversationsClient().createEvent(
CONV_ID, CustomEvent.builder()
.from(CONV_MEMBER_ID)
.body(Map.of("your", "data"))
.build()
);
System.out.println(event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2025 Vonage
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.vonage.quickstart.conversation;

import com.vonage.client.VonageClient;
import com.vonage.client.common.MessageType;
import com.vonage.client.conversations.MessageEvent;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class CreateEvent {
public static void main(String[] args) throws Exception {
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();

var event = client.getConversationsClient().createEvent(
CONV_ID, MessageEvent.builder(MessageType.TEXT)
.from(CONV_MEMBER_ID)
.text("Hello World!")
.build()
);
System.out.println(event);
}
}
Loading