Skip to content

feat: added new mms examples #180

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
48 changes: 48 additions & 0 deletions messages/mms/send-mms-content.ts
Original file line number Diff line number Diff line change
@@ -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));
39 changes: 39 additions & 0 deletions messages/mms/send-mms-file.js
Original file line number Diff line number Diff line change
@@ -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));
37 changes: 37 additions & 0 deletions messages/mms/send-mms-text.js
Original file line number Diff line number Diff line change
@@ -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));