From 1a1e739c2eb415682170e3d9b6c197e0775a156a Mon Sep 17 00:00:00 2001 From: Chuck MANCHUCK Reeves Date: Mon, 7 Jul 2025 16:16:32 -0400 Subject: [PATCH] feat: added new mms examples --- messages/mms/send-mms-content.ts | 48 ++++++++++++++++++++++++++++++++ messages/mms/send-mms-file.js | 39 ++++++++++++++++++++++++++ messages/mms/send-mms-text.js | 37 ++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 messages/mms/send-mms-content.ts create mode 100644 messages/mms/send-mms-file.js create mode 100644 messages/mms/send-mms-text.js diff --git a/messages/mms/send-mms-content.ts b/messages/mms/send-mms-content.ts new file mode 100644 index 0000000..489363f --- /dev/null +++ b/messages/mms/send-mms-content.ts @@ -0,0 +1,48 @@ +require('dotenv').config({ path: __dirname + '/../.env' }); + +const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID; +const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY; +const MESSAGES_TO_NUMBER = process.env.MESSAGES_TO_NUMBER; +const MMS_SEENDER_ID = process.env.MMS_SEENDER_ID; +const MESSAGES_IMAGE_URL = process.env.MESSAGES_IMAGE_URL; +const MESSAGES_FILE_URL = process.env.MESSAGES_FILE_URL; +const MESSAGES_API_URL = process.env.MESSAGES_API_URL; + +const { Channels, } = require('@vonage/messages'); +const { Vonage } = require('@vonage/server-sdk'); + +/** + * It is best to send messages using JWT instead of basic auth. If you leave out + * apiKey and apiSecret, the messages SDK will send requests using JWT tokens + * + * @link https://developer.vonage.com/en/messages/technical-details#authentication + */ +const vonage = new Vonage( + { + applicationId: VONAGE_APPLICATION_ID, + privateKey: VONAGE_PRIVATE_KEY, + }, + { + ...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}), + }, +); + +vonage.messages.send({ + messageType: 'image', + channel: Channels.MMS, + content: [ + { + type: 'image', + url: MESSAGES_IMAGE_URL, + }, + { + type: 'file', + url: MESSAGES_FILE_URL, + + } + ], + to: MESSAGES_TO_NUMBER, + from: MMS_SEENDER_ID, +}) + .then(({ messageUUID }) => console.log(messageUUID)) + .catch((error) => console.error(error)); diff --git a/messages/mms/send-mms-file.js b/messages/mms/send-mms-file.js new file mode 100644 index 0000000..f21d1d6 --- /dev/null +++ b/messages/mms/send-mms-file.js @@ -0,0 +1,39 @@ +require('dotenv').config({ path: __dirname + '/../.env' }); + +const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID; +const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY; +const MESSAGES_TO_NUMBER = process.env.MESSAGES_TO_NUMBER; +const MMS_SEENDER_ID = process.env.MMS_SEENDER_ID; +const MESSAGES_FILE_URL = process.env.MESSAGES_FILE_URL; +const MESSAGES_API_URL = process.env.MESSAGES_API_URL; + +const { Vonage } = require('@vonage/server-sdk'); +const { Channels } = require('@vonage/messages'); + +/** + * It is best to send messages using JWT instead of basic auth. If you leave out + * apiKey and apiSecret, the messages SDK will send requests using JWT tokens + * + * @link https://developer.vonage.com/en/messages/technical-details#authentication + */ +const vonage = new Vonage( + { + applicationId: VONAGE_APPLICATION_ID, + privateKey: VONAGE_PRIVATE_KEY, + }, + { + ...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}), + }, +); + +vonage.messages.send({ + messageType: 'image', + channel: Channels.MMS, + file: { + url: MESSAGES_FILE_URL, + }, + to: MESSAGES_TO_NUMBER, + from: MMS_SEENDER_ID, +}) + .then(({ messageUUID }) => console.log(messageUUID)) + .catch((error) => console.error(error)); diff --git a/messages/mms/send-mms-text.js b/messages/mms/send-mms-text.js new file mode 100644 index 0000000..b77f454 --- /dev/null +++ b/messages/mms/send-mms-text.js @@ -0,0 +1,37 @@ +require('dotenv').config({ path: __dirname + '/../.env' }); + +const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID; +const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY; +const MESSAGES_TO_NUMBER = process.env.MESSAGES_TO_NUMBER; +const MMS_SEENDER_ID = process.env.MMS_SEENDER_ID; +const MESSAGES_API_URL = process.env.MESSAGES_API_URL; + +const { Vonage } = require('@vonage/server-sdk'); +const { Channels } = require('@vonage/messages'); + +/** + * It is best to send messages using JWT instead of basic auth. If you leave out + * apiKey and apiSecret, the messages SDK will send requests using JWT tokens + * + * @link https://developer.vonage.com/en/messages/technical-details#authentication + */ +const vonage = new Vonage( + { + applicationId: VONAGE_APPLICATION_ID, + privateKey: VONAGE_PRIVATE_KEY, + }, + { + ...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}), + }, +); + +vonage.messages.send({ + messageType: 'image', + channel: Channels.MMS, + text: 'This is an RCS text message sent via the Vonage Messages API.', + to: MESSAGES_TO_NUMBER, + from: MMS_SEENDER_ID, +}) + .then(({ messageUUID }) => console.log(messageUUID)) + .catch((error) => console.error(error)); +