From 5761f85d0387412ad4e773d89cfa92c2c9dfa7fd Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Thu, 13 Mar 2025 11:09:39 +0000 Subject: [PATCH 1/4] feat: Add Conversation snippets --- .env-example | 10 +++++ .../quickstart/EnvironmentVariables.java | 11 +++++ .../conversation/CreateConversation.java | 43 ++++++++++++++++++ .../conversation/CreateCustomEvent.java | 44 ++++++++++++++++++ .../quickstart/conversation/CreateEvent.java | 44 ++++++++++++++++++ .../quickstart/conversation/CreateMember.java | 45 +++++++++++++++++++ .../conversation/DeleteConversation.java | 36 +++++++++++++++ .../quickstart/conversation/DeleteEvent.java | 36 +++++++++++++++ .../conversation/GetConversation.java | 37 +++++++++++++++ .../quickstart/conversation/GetEvent.java | 37 +++++++++++++++ .../quickstart/conversation/GetMember.java | 37 +++++++++++++++ .../conversation/ListConversations.java | 37 +++++++++++++++ .../quickstart/conversation/ListEvents.java | 37 +++++++++++++++ .../quickstart/conversation/ListMembers.java | 37 +++++++++++++++ .../conversation/ListUserConversations.java | 37 +++++++++++++++ .../conversation/UpdateConversation.java | 43 ++++++++++++++++++ .../quickstart/conversation/UpdateMember.java | 44 ++++++++++++++++++ .../ApplicationAuthWithKeyContents.java | 3 +- .../ApplicationAuthWithKeyPath.java | 2 +- .../quickstart/initialize/BasicAuth.java | 2 +- .../quickstart/initialize/FullAuth.java | 2 +- 21 files changed, 619 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/vonage/quickstart/conversation/CreateConversation.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/CreateCustomEvent.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/CreateEvent.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/CreateMember.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/DeleteConversation.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/DeleteEvent.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/GetConversation.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/GetEvent.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/GetMember.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/ListConversations.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/ListEvents.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/ListMembers.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/ListUserConversations.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/UpdateConversation.java create mode 100644 src/main/java/com/vonage/quickstart/conversation/UpdateMember.java diff --git a/.env-example b/.env-example index 0f6f04c..a7ea400 100644 --- a/.env-example +++ b/.env-example @@ -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_NAME="support_meeting" +CONV_NEW_DISPLAY_NAME="Support Meeting" + # Messages MESSAGES_TO_NUMBER="447900000001" MESSAGES_API_URL="https://api.nexmo.com/v1/messages" diff --git a/src/main/java/com/vonage/quickstart/EnvironmentVariables.java b/src/main/java/com/vonage/quickstart/EnvironmentVariables.java index ad026b4..0b54483 100644 --- a/src/main/java/com/vonage/quickstart/EnvironmentVariables.java +++ b/src/main/java/com/vonage/quickstart/EnvironmentVariables.java @@ -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; @@ -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"), @@ -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")), @@ -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")); diff --git a/src/main/java/com/vonage/quickstart/conversation/CreateConversation.java b/src/main/java/com/vonage/quickstart/conversation/CreateConversation.java new file mode 100644 index 0000000..752b7f3 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/CreateConversation.java @@ -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); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/CreateCustomEvent.java b/src/main/java/com/vonage/quickstart/conversation/CreateCustomEvent.java new file mode 100644 index 0000000..80dfe1c --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/CreateCustomEvent.java @@ -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); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/CreateEvent.java b/src/main/java/com/vonage/quickstart/conversation/CreateEvent.java new file mode 100644 index 0000000..bd4972d --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/CreateEvent.java @@ -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); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/CreateMember.java b/src/main/java/com/vonage/quickstart/conversation/CreateMember.java new file mode 100644 index 0000000..a9b75e6 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/CreateMember.java @@ -0,0 +1,45 @@ +/* + * 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.ChannelType; +import com.vonage.client.conversations.Member; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class CreateMember { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var member = client.getConversationsClient().createMember( + CONV_ID, Member.builder() + .channelType(ChannelType.APP) + .state(CONV_MEMBER_STATE) + .user(USER_ID) + .build() + ); + System.out.println(member); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/DeleteConversation.java b/src/main/java/com/vonage/quickstart/conversation/DeleteConversation.java new file mode 100644 index 0000000..7df99e3 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/DeleteConversation.java @@ -0,0 +1,36 @@ +/* + * 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 static com.vonage.quickstart.EnvironmentVariables.*; + +public class DeleteConversation { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + client.getConversationsClient().deleteConversation(CONV_ID); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/DeleteEvent.java b/src/main/java/com/vonage/quickstart/conversation/DeleteEvent.java new file mode 100644 index 0000000..35383d5 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/DeleteEvent.java @@ -0,0 +1,36 @@ +/* + * 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 static com.vonage.quickstart.EnvironmentVariables.*; + +public class DeleteEvent { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + client.getConversationsClient().deleteEvent(CONV_ID, CONV_EVENT_ID); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/GetConversation.java b/src/main/java/com/vonage/quickstart/conversation/GetConversation.java new file mode 100644 index 0000000..ef34cc9 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/GetConversation.java @@ -0,0 +1,37 @@ +/* + * 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 static com.vonage.quickstart.EnvironmentVariables.*; + +public class GetConversation { + 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().getConversation(CONV_ID); + System.out.println(conversation); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/GetEvent.java b/src/main/java/com/vonage/quickstart/conversation/GetEvent.java new file mode 100644 index 0000000..df23df4 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/GetEvent.java @@ -0,0 +1,37 @@ +/* + * 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 static com.vonage.quickstart.EnvironmentVariables.*; + +public class GetEvent { + 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().getEvent(CONV_ID, CONV_EVENT_ID); + System.out.println(event); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/GetMember.java b/src/main/java/com/vonage/quickstart/conversation/GetMember.java new file mode 100644 index 0000000..ef7c0ff --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/GetMember.java @@ -0,0 +1,37 @@ +/* + * 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 static com.vonage.quickstart.EnvironmentVariables.*; + +public class GetMember { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var member = client.getConversationsClient().getMember(CONV_ID, CONV_MEMBER_ID); + System.out.println(member); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/ListConversations.java b/src/main/java/com/vonage/quickstart/conversation/ListConversations.java new file mode 100644 index 0000000..fe3efe4 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/ListConversations.java @@ -0,0 +1,37 @@ +/* + * 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 static com.vonage.quickstart.EnvironmentVariables.*; + +public class ListConversations { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var conversations = client.getConversationsClient().listConversations(); + conversations.forEach(System.out::println); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/ListEvents.java b/src/main/java/com/vonage/quickstart/conversation/ListEvents.java new file mode 100644 index 0000000..5571ab9 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/ListEvents.java @@ -0,0 +1,37 @@ +/* + * 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 static com.vonage.quickstart.EnvironmentVariables.*; + +public class ListEvents { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var events = client.getConversationsClient().listEvents(CONV_ID); + events.forEach(System.out::println); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/ListMembers.java b/src/main/java/com/vonage/quickstart/conversation/ListMembers.java new file mode 100644 index 0000000..e86c7bc --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/ListMembers.java @@ -0,0 +1,37 @@ +/* + * 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 static com.vonage.quickstart.EnvironmentVariables.*; + +public class ListMembers { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var members = client.getConversationsClient().listMembers(CONV_ID); + members.forEach(System.out::println); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/ListUserConversations.java b/src/main/java/com/vonage/quickstart/conversation/ListUserConversations.java new file mode 100644 index 0000000..8a7de2c --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/ListUserConversations.java @@ -0,0 +1,37 @@ +/* + * 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 static com.vonage.quickstart.EnvironmentVariables.*; + +public class ListUserConversations { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var conversations = client.getConversationsClient().listUserConversations(USER_ID); + conversations.forEach(System.out::println); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/UpdateConversation.java b/src/main/java/com/vonage/quickstart/conversation/UpdateConversation.java new file mode 100644 index 0000000..98d441e --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/UpdateConversation.java @@ -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 UpdateConversation { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var updated = client.getConversationsClient().updateConversation( + CONV_ID, Conversation.builder() + .name(CONV_NEW_NAME) + .displayName(CONV_NEW_DISPLAY_NAME) + .build() + ); + System.out.println(updated); + } +} diff --git a/src/main/java/com/vonage/quickstart/conversation/UpdateMember.java b/src/main/java/com/vonage/quickstart/conversation/UpdateMember.java new file mode 100644 index 0000000..d439531 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/conversation/UpdateMember.java @@ -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.UpdateMemberRequest; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class UpdateMember { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var updated = client.getConversationsClient().updateMember( + UpdateMemberRequest.builder() + .conversationId(CONV_ID) + .memberId(CONV_MEMBER_ID) + .state(CONV_MEMBER_STATE) + .build() + ); + System.out.println(updated); + } +} diff --git a/src/main/java/com/vonage/quickstart/initialize/ApplicationAuthWithKeyContents.java b/src/main/java/com/vonage/quickstart/initialize/ApplicationAuthWithKeyContents.java index 5501e42..a27d3d2 100644 --- a/src/main/java/com/vonage/quickstart/initialize/ApplicationAuthWithKeyContents.java +++ b/src/main/java/com/vonage/quickstart/initialize/ApplicationAuthWithKeyContents.java @@ -28,8 +28,7 @@ * Example of configuring a VonageClient with Application (JWT) authentication credentials. */ public class ApplicationAuthWithKeyContents { - public static void main(String[] argv) throws Exception { - + public static void main(String[] args) throws Exception { VonageClient client = VonageClient.builder() .applicationId(VONAGE_APPLICATION_ID) .privateKeyContents(VONAGE_PRIVATE_KEY_CONTENTS) diff --git a/src/main/java/com/vonage/quickstart/initialize/ApplicationAuthWithKeyPath.java b/src/main/java/com/vonage/quickstart/initialize/ApplicationAuthWithKeyPath.java index b3fd556..3263356 100644 --- a/src/main/java/com/vonage/quickstart/initialize/ApplicationAuthWithKeyPath.java +++ b/src/main/java/com/vonage/quickstart/initialize/ApplicationAuthWithKeyPath.java @@ -28,7 +28,7 @@ * Example of configuring a VonageClient with Application (JWT) authentication credentials. */ public class ApplicationAuthWithKeyPath { - public static void main(String[] argv) throws Exception { + public static void main(String[] args) throws Exception { VonageClient client = VonageClient.builder() .applicationId(VONAGE_APPLICATION_ID) diff --git a/src/main/java/com/vonage/quickstart/initialize/BasicAuth.java b/src/main/java/com/vonage/quickstart/initialize/BasicAuth.java index 941bc90..0dd27b6 100644 --- a/src/main/java/com/vonage/quickstart/initialize/BasicAuth.java +++ b/src/main/java/com/vonage/quickstart/initialize/BasicAuth.java @@ -28,7 +28,7 @@ * Example of configuring a VonageClient with an API secret. */ public class BasicAuth { - public static void main(String[] argv) throws Exception { + public static void main(String[] args) throws Exception { VonageClient client = VonageClient.builder().apiKey(VONAGE_API_KEY).apiSecret(VONAGE_API_SECRET).build(); } } diff --git a/src/main/java/com/vonage/quickstart/initialize/FullAuth.java b/src/main/java/com/vonage/quickstart/initialize/FullAuth.java index c66b002..cc6b76e 100644 --- a/src/main/java/com/vonage/quickstart/initialize/FullAuth.java +++ b/src/main/java/com/vonage/quickstart/initialize/FullAuth.java @@ -29,7 +29,7 @@ * both API secret and Application (JWT) authentication credentials. */ public class FullAuth { - public static void main(String[] argv) throws Exception { + public static void main(String[] args) throws Exception { VonageClient client = VonageClient.builder() .apiKey(VONAGE_API_KEY) .apiSecret(VONAGE_API_SECRET) From 2f4b078e445e2f355dcada3c894123eebde34788 Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Thu, 13 Mar 2025 11:24:29 +0000 Subject: [PATCH 2/4] feat: Add missing Voice snippets --- .../quickstart/voice/StopAudioStream.java | 36 +++++++++++++++++++ .../vonage/quickstart/voice/StopSpeech.java | 36 +++++++++++++++++++ .../quickstart/voice/SubscribeDtmf.java | 36 +++++++++++++++++++ .../quickstart/voice/UnsubscribeDtmf.java | 36 +++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 src/main/java/com/vonage/quickstart/voice/StopAudioStream.java create mode 100644 src/main/java/com/vonage/quickstart/voice/StopSpeech.java create mode 100644 src/main/java/com/vonage/quickstart/voice/SubscribeDtmf.java create mode 100644 src/main/java/com/vonage/quickstart/voice/UnsubscribeDtmf.java diff --git a/src/main/java/com/vonage/quickstart/voice/StopAudioStream.java b/src/main/java/com/vonage/quickstart/voice/StopAudioStream.java new file mode 100644 index 0000000..ec4e43b --- /dev/null +++ b/src/main/java/com/vonage/quickstart/voice/StopAudioStream.java @@ -0,0 +1,36 @@ +/* + * 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.voice; + +import com.vonage.client.VonageClient; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class StopAudioStream { + public static void main(String... args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var response = client.getVoiceClient().stopStream(VOICE_CALL_ID); + } +} diff --git a/src/main/java/com/vonage/quickstart/voice/StopSpeech.java b/src/main/java/com/vonage/quickstart/voice/StopSpeech.java new file mode 100644 index 0000000..afe144c --- /dev/null +++ b/src/main/java/com/vonage/quickstart/voice/StopSpeech.java @@ -0,0 +1,36 @@ +/* + * 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.voice; + +import com.vonage.client.VonageClient; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class StopSpeech { + public static void main(String... args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var response = client.getVoiceClient().stopTalk(VOICE_CALL_ID); + } +} diff --git a/src/main/java/com/vonage/quickstart/voice/SubscribeDtmf.java b/src/main/java/com/vonage/quickstart/voice/SubscribeDtmf.java new file mode 100644 index 0000000..b9c79f4 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/voice/SubscribeDtmf.java @@ -0,0 +1,36 @@ +/* + * 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.voice; + +import com.vonage.client.VonageClient; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class SubscribeDtmf { + public static void main(String... args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + client.getVoiceClient().addDtmfListener(VOICE_CALL_ID, VOICE_EVENT_URL); + } +} diff --git a/src/main/java/com/vonage/quickstart/voice/UnsubscribeDtmf.java b/src/main/java/com/vonage/quickstart/voice/UnsubscribeDtmf.java new file mode 100644 index 0000000..5d76427 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/voice/UnsubscribeDtmf.java @@ -0,0 +1,36 @@ +/* + * 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.voice; + +import com.vonage.client.VonageClient; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class UnsubscribeDtmf { + public static void main(String... args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + client.getVoiceClient().removeDtmfListener(VOICE_CALL_ID); + } +} From f3992b9e50cba6a7535990f90952c460d307f67d Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Thu, 13 Mar 2025 11:26:41 +0000 Subject: [PATCH 3/4] chore: Run AggregateSnippets --- .env-example | 2 +- SNIPPETS.md | 148 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 143 insertions(+), 7 deletions(-) diff --git a/.env-example b/.env-example index a7ea400..88bab12 100644 --- a/.env-example +++ b/.env-example @@ -26,8 +26,8 @@ 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_NAME="support_meeting" CONV_NEW_DISPLAY_NAME="Support Meeting" +CONV_NEW_NAME="support_meeting" # Messages MESSAGES_TO_NUMBER="447900000001" diff --git a/SNIPPETS.md b/SNIPPETS.md index 38a9c75..70f66e3 100644 --- a/SNIPPETS.md +++ b/SNIPPETS.md @@ -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) @@ -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 @@ -2657,6 +2779,11 @@ post("/webhooks/notification", (req, res) -> { ).toJson(); }); ``` +### Stop Audio Stream + +```java +var response = client.getVoiceClient().stopStream(VOICE_CALL_ID); +``` ### Transfer Call NCCO ```java @@ -2922,6 +3049,16 @@ Spark.port(3000); Spark.get("/webhooks/answer", answerRoute); Spark.post("/webhooks/dtmf", inputRoute); ``` +### Subscribe DTMF + +```java +client.getVoiceClient().addDtmfListener(VOICE_CALL_ID, VOICE_EVENT_URL); +``` +### Stop Speech + +```java +var response = client.getVoiceClient().stopTalk(VOICE_CALL_ID); +``` ### Send DTMF To Call ```java @@ -2960,6 +3097,11 @@ client.getVoiceClient().startTalk(VOICE_CALL_ID, payload); ```java client.getVoiceClient().createCall(new Call(VOICE_TO_NUMBER, VONAGE_VIRTUAL_NUMBER, VOICE_ANSWER_URL)); ``` +### Unsubscribe DTMF + +```java +client.getVoiceClient().removeDtmfListener(VOICE_CALL_ID); +``` ### ASR Input ```java @@ -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())); -``` From 2d193e4b705450c48873988498dc017a2a6c0bab Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Thu, 13 Mar 2025 11:34:35 +0000 Subject: [PATCH 4/4] refactor: Rename new voice snippets --- SNIPPETS.md | 30 +++++++++---------- ...{StopSpeech.java => StopTextToSpeech.java} | 2 +- ...beDtmf.java => SubscribeToDtmfEvents.java} | 2 +- ...mf.java => UnsubscribeFromDtmfEvents.java} | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) rename src/main/java/com/vonage/quickstart/voice/{StopSpeech.java => StopTextToSpeech.java} (98%) rename src/main/java/com/vonage/quickstart/voice/{SubscribeDtmf.java => SubscribeToDtmfEvents.java} (97%) rename src/main/java/com/vonage/quickstart/voice/{UnsubscribeDtmf.java => UnsubscribeFromDtmfEvents.java} (97%) diff --git a/SNIPPETS.md b/SNIPPETS.md index 70f66e3..b5b8408 100644 --- a/SNIPPETS.md +++ b/SNIPPETS.md @@ -2784,6 +2784,11 @@ post("/webhooks/notification", (req, res) -> { ```java var response = client.getVoiceClient().stopStream(VOICE_CALL_ID); ``` +### Unsubscribe From DTMF Events + +```java +client.getVoiceClient().removeDtmfListener(VOICE_CALL_ID); +``` ### Transfer Call NCCO ```java @@ -2888,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 @@ -2921,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 @@ -3049,16 +3064,6 @@ Spark.port(3000); Spark.get("/webhooks/answer", answerRoute); Spark.post("/webhooks/dtmf", inputRoute); ``` -### Subscribe DTMF - -```java -client.getVoiceClient().addDtmfListener(VOICE_CALL_ID, VOICE_EVENT_URL); -``` -### Stop Speech - -```java -var response = client.getVoiceClient().stopTalk(VOICE_CALL_ID); -``` ### Send DTMF To Call ```java @@ -3097,11 +3102,6 @@ client.getVoiceClient().startTalk(VOICE_CALL_ID, payload); ```java client.getVoiceClient().createCall(new Call(VOICE_TO_NUMBER, VONAGE_VIRTUAL_NUMBER, VOICE_ANSWER_URL)); ``` -### Unsubscribe DTMF - -```java -client.getVoiceClient().removeDtmfListener(VOICE_CALL_ID); -``` ### ASR Input ```java diff --git a/src/main/java/com/vonage/quickstart/voice/StopSpeech.java b/src/main/java/com/vonage/quickstart/voice/StopTextToSpeech.java similarity index 98% rename from src/main/java/com/vonage/quickstart/voice/StopSpeech.java rename to src/main/java/com/vonage/quickstart/voice/StopTextToSpeech.java index afe144c..5e7bf20 100644 --- a/src/main/java/com/vonage/quickstart/voice/StopSpeech.java +++ b/src/main/java/com/vonage/quickstart/voice/StopTextToSpeech.java @@ -24,7 +24,7 @@ import com.vonage.client.VonageClient; import static com.vonage.quickstart.EnvironmentVariables.*; -public class StopSpeech { +public class StopTextToSpeech { public static void main(String... args) throws Exception { VonageClient client = VonageClient.builder() .applicationId(VONAGE_APPLICATION_ID) diff --git a/src/main/java/com/vonage/quickstart/voice/SubscribeDtmf.java b/src/main/java/com/vonage/quickstart/voice/SubscribeToDtmfEvents.java similarity index 97% rename from src/main/java/com/vonage/quickstart/voice/SubscribeDtmf.java rename to src/main/java/com/vonage/quickstart/voice/SubscribeToDtmfEvents.java index b9c79f4..036e2c5 100644 --- a/src/main/java/com/vonage/quickstart/voice/SubscribeDtmf.java +++ b/src/main/java/com/vonage/quickstart/voice/SubscribeToDtmfEvents.java @@ -24,7 +24,7 @@ import com.vonage.client.VonageClient; import static com.vonage.quickstart.EnvironmentVariables.*; -public class SubscribeDtmf { +public class SubscribeToDtmfEvents { public static void main(String... args) throws Exception { VonageClient client = VonageClient.builder() .applicationId(VONAGE_APPLICATION_ID) diff --git a/src/main/java/com/vonage/quickstart/voice/UnsubscribeDtmf.java b/src/main/java/com/vonage/quickstart/voice/UnsubscribeFromDtmfEvents.java similarity index 97% rename from src/main/java/com/vonage/quickstart/voice/UnsubscribeDtmf.java rename to src/main/java/com/vonage/quickstart/voice/UnsubscribeFromDtmfEvents.java index 5d76427..0af00a0 100644 --- a/src/main/java/com/vonage/quickstart/voice/UnsubscribeDtmf.java +++ b/src/main/java/com/vonage/quickstart/voice/UnsubscribeFromDtmfEvents.java @@ -24,7 +24,7 @@ import com.vonage.client.VonageClient; import static com.vonage.quickstart.EnvironmentVariables.*; -public class UnsubscribeDtmf { +public class UnsubscribeFromDtmfEvents { public static void main(String... args) throws Exception { VonageClient client = VonageClient.builder() .applicationId(VONAGE_APPLICATION_ID)