Skip to content

feat: Add MMS text/file/content messages #117

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 5 commits into from
Mar 5, 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: 5 additions & 5 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
40 changes: 39 additions & 1 deletion SNIPPETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -817,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(
Expand All @@ -828,6 +839,29 @@ 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)
.addImage(MESSAGES_IMAGE_URL)
.addFile(MESSAGES_FILE_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
Expand Down Expand Up @@ -2977,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()));
```
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/java/AggregateSnippets.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("(?<!^)([A-Z])(?![A-Z])", " $1")
.replace("Vcard", "vCard")
.replace("Numberinsight2", "Fraud Detection")
.replace("Numberinsight", "Number Insight")
.replace("Verify\n", "Verify (Legacy)\n")
Expand Down
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.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)
.addImage(MESSAGES_IMAGE_URL)
.addFile(MESSAGES_FILE_URL)
.build()
);
System.out.println("Message sent successfully. ID: "+response.getMessageUuid());
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/vonage/quickstart/messages/mms/SendMmsFile.java
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.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());
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/vonage/quickstart/messages/mms/SendMmsText.java
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.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());
}
}