From aa7ffcf98d3a2af6152dc613a3871c5ea09e330b Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Tue, 4 Mar 2025 15:21:33 +0000 Subject: [PATCH 1/5] feat: Add MMS text/file/content messages --- SNIPPETS.md | 37 +++++++++++++++ .../messages/mms/SendMmsContent.java | 47 +++++++++++++++++++ .../quickstart/messages/mms/SendMmsFile.java | 43 +++++++++++++++++ .../quickstart/messages/mms/SendMmsText.java | 43 +++++++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 src/main/java/com/vonage/quickstart/messages/mms/SendMmsContent.java create mode 100644 src/main/java/com/vonage/quickstart/messages/mms/SendMmsFile.java create mode 100644 src/main/java/com/vonage/quickstart/messages/mms/SendMmsText.java diff --git a/SNIPPETS.md b/SNIPPETS.md index 7055531..64c0e54 100644 --- a/SNIPPETS.md +++ b/SNIPPETS.md @@ -806,6 +806,17 @@ var response = client.getMessagesClient().sendMessage( System.out.println("Message sent successfully. ID: " + response.getMessageUuid()); ``` ### MMS +#### Send MMS Text + +```java +var response = client.getMessagesClient().sendMessage( + MmsTextRequest.builder() + .from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .text("This is an MMS message with text") + .build() +); +System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); +``` #### Send MMS Video ```java @@ -828,6 +839,32 @@ var response = client.getMessagesClient().sendMessage( ); System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); ``` +#### Send MMS Content + +```java +var response = client.getMessagesClient().sendMessage( + MmsContentRequest.builder() + .from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .addAudio(MESSAGES_AUDIO_URL) + .addImage(MESSAGES_IMAGE_URL) + .addVideo(MESSAGES_VIDEO_URL) + .addFile(MESSAGES_FILE_URL) + .addVcard(MESSAGES_VCARD_URL) + .build() +); +System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); +``` +#### Send MMS File + +```java +var response = client.getMessagesClient().sendMessage( + MmsFileRequest.builder() + .from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .url(MESSAGES_FILE_URL) + .build() +); +System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); +``` #### Send MMS Image ```java diff --git a/src/main/java/com/vonage/quickstart/messages/mms/SendMmsContent.java b/src/main/java/com/vonage/quickstart/messages/mms/SendMmsContent.java new file mode 100644 index 0000000..7d7ded4 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/messages/mms/SendMmsContent.java @@ -0,0 +1,47 @@ +/* + * 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.messages.mms; + +import com.vonage.client.VonageClient; +import com.vonage.client.messages.mms.MmsContentRequest; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class SendMmsContent { + 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.getMessagesClient().sendMessage( + MmsContentRequest.builder() + .from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .addAudio(MESSAGES_AUDIO_URL) + .addImage(MESSAGES_IMAGE_URL) + .addVideo(MESSAGES_VIDEO_URL) + .addFile(MESSAGES_FILE_URL) + .addVcard(MESSAGES_VCARD_URL) + .build() + ); + System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); + } +} diff --git a/src/main/java/com/vonage/quickstart/messages/mms/SendMmsFile.java b/src/main/java/com/vonage/quickstart/messages/mms/SendMmsFile.java new file mode 100644 index 0000000..89f0aca --- /dev/null +++ b/src/main/java/com/vonage/quickstart/messages/mms/SendMmsFile.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.messages.mms; + +import com.vonage.client.VonageClient; +import com.vonage.client.messages.mms.MmsFileRequest; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class SendMmsFile { + 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.getMessagesClient().sendMessage( + MmsFileRequest.builder() + .from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .url(MESSAGES_FILE_URL) + .build() + ); + System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); + } +} diff --git a/src/main/java/com/vonage/quickstart/messages/mms/SendMmsText.java b/src/main/java/com/vonage/quickstart/messages/mms/SendMmsText.java new file mode 100644 index 0000000..f08af35 --- /dev/null +++ b/src/main/java/com/vonage/quickstart/messages/mms/SendMmsText.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.messages.mms; + +import com.vonage.client.VonageClient; +import com.vonage.client.messages.mms.MmsTextRequest; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class SendMmsText { + 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.getMessagesClient().sendMessage( + MmsTextRequest.builder() + .from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .text("This is an MMS message with text") + .build() + ); + System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); + } +} From cd9ecdab0bb109fd1ca82fa6e71e949d1ef3ccf0 Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Tue, 4 Mar 2025 17:49:09 +0000 Subject: [PATCH 2/5] ci: Bump versions --- .github/workflows/build.yml | 2 +- .github/workflows/codeql.yml | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2270143..331805d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,6 +28,6 @@ jobs: distribution: 'temurin' java-version: ${{ matrix.java }} - name: Setup Gradle - uses: gradle/actions/setup-gradle@94baf225fe0a508e581a564467443d0e2379123b + uses: gradle/actions/setup-gradle@245c8a24de79c0dbeabaf19ebcbbd3b2c36f278d - name: Build with Gradle run: ./gradlew build diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ff1fbba..4302acb 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -29,11 +29,11 @@ jobs: - name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: Initialize CodeQL - uses: github/codeql-action/init@dd746615b3b9d728a6a37ca2045b68ca76d4841a + uses: github/codeql-action/init@1bb15d06a6fbb5d9d9ffd228746bf8ee208caec8 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@dd746615b3b9d728a6a37ca2045b68ca76d4841a + uses: github/codeql-action/analyze@1bb15d06a6fbb5d9d9ffd228746bf8ee208caec8 with: category: "/language:${{matrix.language}}" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6a02fc6..b8640a0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists From c83e9712069b7d23fa7ce2768d57817515430aaf Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Tue, 4 Mar 2025 17:50:47 +0000 Subject: [PATCH 3/5] docs: vCard casing --- SNIPPETS.md | 2 +- src/main/java/AggregateSnippets.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/SNIPPETS.md b/SNIPPETS.md index 64c0e54..797d48b 100644 --- a/SNIPPETS.md +++ b/SNIPPETS.md @@ -828,7 +828,7 @@ var response = client.getMessagesClient().sendMessage( ); System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); ``` -#### Send MMS Vcard +#### Send MMS vCard ```java var response = client.getMessagesClient().sendMessage( diff --git a/src/main/java/AggregateSnippets.java b/src/main/java/AggregateSnippets.java index 38bff95..560aa1d 100644 --- a/src/main/java/AggregateSnippets.java +++ b/src/main/java/AggregateSnippets.java @@ -147,6 +147,7 @@ private static String toHeadingTitle(String title) { var result = (title.substring(0, 1).toUpperCase() + title.substring(1)) .replace("NCCO", "ncco") // To avoid adding spaces in the next regex .replaceAll("(? Date: Wed, 5 Mar 2025 10:00:41 +0000 Subject: [PATCH 4/5] fix: MMS content up to spec --- .../com/vonage/quickstart/messages/mms/SendMmsContent.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/vonage/quickstart/messages/mms/SendMmsContent.java b/src/main/java/com/vonage/quickstart/messages/mms/SendMmsContent.java index 7d7ded4..71d0148 100644 --- a/src/main/java/com/vonage/quickstart/messages/mms/SendMmsContent.java +++ b/src/main/java/com/vonage/quickstart/messages/mms/SendMmsContent.java @@ -35,11 +35,8 @@ public static void main(String[] args) throws Exception { var response = client.getMessagesClient().sendMessage( MmsContentRequest.builder() .from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER) - .addAudio(MESSAGES_AUDIO_URL) .addImage(MESSAGES_IMAGE_URL) - .addVideo(MESSAGES_VIDEO_URL) .addFile(MESSAGES_FILE_URL) - .addVcard(MESSAGES_VCARD_URL) .build() ); System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); From 23e8665b962863661661d9b898db3a59d43bcdb1 Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Wed, 5 Mar 2025 10:31:50 +0000 Subject: [PATCH 5/5] chore: Run AggregateSnippets --- .env-example | 10 +++++----- SNIPPETS.md | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.env-example b/.env-example index 63717f5..0f6f04c 100644 --- a/.env-example +++ b/.env-example @@ -26,11 +26,11 @@ MESSAGES_GEOSPECIFIC_API_URL="https://api-eu.nexmo.com/v1/messages" MESSAGES_GEOSPECIFIC_API_HOST="api-eu" MESSAGES_SANDBOX_URL="https://messages-sandbox.nexmo.com/v1/messages" MESSAGES_MESSAGE_ID="00000000-0000-4000-8000-000000000000" -MESSAGES_IMAGE_URL="https://example.org/image.jpg" -MESSAGES_AUDIO_URL="https://example.org/audio.mp3" -MESSAGES_VIDEO_URL="https://example.org/video.mp4" -MESSAGES_FILE_URL="https://example.org/file.pdf" -MESSAGES_VCARD_URL="https://example.org/vcard.vcf" +MESSAGES_IMAGE_URL="https://file-examples.com/storage/fe435d6a5467c753ca23df4/2017/10/file_example_JPG_100kB.jpg" +MESSAGES_AUDIO_URL="https://file-examples.com/wp-content/storage/2017/11/file_example_MP3_700KB.mp3" +MESSAGES_VIDEO_URL="https://file-examples.com/wp-content/storage/2017/04/file_example_MP4_480_1_5MG.mp4" +MESSAGES_FILE_URL="https://file-examples.com/wp-content/storage/2017/02/file-sample_100kB.doc" +MESSAGES_VCARD_URL="https://raw.githubusercontent.com/nuovo/vCard-parser/refs/heads/master/Example.vcf" MESSAGES_EMOJI="🐱" MESSAGES_CAPTION="Additional text to accompany the message" diff --git a/SNIPPETS.md b/SNIPPETS.md index 797d48b..5905fd6 100644 --- a/SNIPPETS.md +++ b/SNIPPETS.md @@ -845,11 +845,8 @@ System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); var response = client.getMessagesClient().sendMessage( MmsContentRequest.builder() .from(MMS_SENDER_ID).to(MESSAGES_TO_NUMBER) - .addAudio(MESSAGES_AUDIO_URL) .addImage(MESSAGES_IMAGE_URL) - .addVideo(MESSAGES_VIDEO_URL) .addFile(MESSAGES_FILE_URL) - .addVcard(MESSAGES_VCARD_URL) .build() ); System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); @@ -3014,3 +3011,7 @@ 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())); ``` +age").build()); + +client.getVoiceClient().createCall(new Call(VOICE_TO_NUMBER, VONAGE_VIRTUAL_NUMBER, ncco.getActions())); +```