Skip to content

Commit 0744d12

Browse files
feat: added new mms examples (#180)
Co-authored-by: Karl Lingiah <[email protected]>
1 parent 413caa5 commit 0744d12

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

messages/mms/send-mms-content.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require('dotenv').config({ path: __dirname + '/../.env' });
2+
3+
const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID;
4+
const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY;
5+
const MESSAGES_TO_NUMBER = process.env.MESSAGES_TO_NUMBER;
6+
const MMS_SENDER_ID = process.env.MMS_SENDER_ID;
7+
const MESSAGES_IMAGE_URL = process.env.MESSAGES_IMAGE_URL;
8+
const MESSAGES_FILE_URL = process.env.MESSAGES_FILE_URL;
9+
const MESSAGES_API_URL = process.env.MESSAGES_API_URL;
10+
11+
const { Channels, } = require('@vonage/messages');
12+
const { Vonage } = require('@vonage/server-sdk');
13+
14+
/**
15+
* It is best to send messages using JWT instead of basic auth. If you leave out
16+
* apiKey and apiSecret, the messages SDK will send requests using JWT tokens
17+
*
18+
* @link https://developer.vonage.com/en/messages/technical-details#authentication
19+
*/
20+
const vonage = new Vonage(
21+
{
22+
applicationId: VONAGE_APPLICATION_ID,
23+
privateKey: VONAGE_PRIVATE_KEY,
24+
},
25+
{
26+
...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}),
27+
},
28+
);
29+
30+
vonage.messages.send({
31+
messageType: 'content',
32+
channel: Channels.MMS,
33+
content: [
34+
{
35+
type: 'image',
36+
url: MESSAGES_IMAGE_URL,
37+
},
38+
{
39+
type: 'file',
40+
url: MESSAGES_FILE_URL,
41+
42+
}
43+
],
44+
to: MESSAGES_TO_NUMBER,
45+
from: MMS_SENDER_ID,
46+
})
47+
.then(({ messageUUID }) => console.log(messageUUID))
48+
.catch((error) => console.error(error));

messages/mms/send-mms-file.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require('dotenv').config({ path: __dirname + '/../.env' });
2+
3+
const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID;
4+
const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY;
5+
const MESSAGES_TO_NUMBER = process.env.MESSAGES_TO_NUMBER;
6+
const MMS_SENDER_ID = process.env.MMS_SENDER_ID;
7+
const MESSAGES_FILE_URL = process.env.MESSAGES_FILE_URL;
8+
const MESSAGES_API_URL = process.env.MESSAGES_API_URL;
9+
10+
const { Vonage } = require('@vonage/server-sdk');
11+
const { Channels } = require('@vonage/messages');
12+
13+
/**
14+
* It is best to send messages using JWT instead of basic auth. If you leave out
15+
* apiKey and apiSecret, the messages SDK will send requests using JWT tokens
16+
*
17+
* @link https://developer.vonage.com/en/messages/technical-details#authentication
18+
*/
19+
const vonage = new Vonage(
20+
{
21+
applicationId: VONAGE_APPLICATION_ID,
22+
privateKey: VONAGE_PRIVATE_KEY,
23+
},
24+
{
25+
...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}),
26+
},
27+
);
28+
29+
vonage.messages.send({
30+
messageType: 'file',
31+
channel: Channels.MMS,
32+
file: {
33+
url: MESSAGES_FILE_URL,
34+
},
35+
to: MESSAGES_TO_NUMBER,
36+
from: MMS_SENDER_ID,
37+
})
38+
.then(({ messageUUID }) => console.log(messageUUID))
39+
.catch((error) => console.error(error));

messages/mms/send-mms-text.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require('dotenv').config({ path: __dirname + '/../.env' });
2+
3+
const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID;
4+
const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY;
5+
const MESSAGES_TO_NUMBER = process.env.MESSAGES_TO_NUMBER;
6+
const MMS_SENDER_ID = process.env.MMS_SENDER_ID;
7+
const MESSAGES_API_URL = process.env.MESSAGES_API_URL;
8+
9+
const { Vonage } = require('@vonage/server-sdk');
10+
const { Channels } = require('@vonage/messages');
11+
12+
/**
13+
* It is best to send messages using JWT instead of basic auth. If you leave out
14+
* apiKey and apiSecret, the messages SDK will send requests using JWT tokens
15+
*
16+
* @link https://developer.vonage.com/en/messages/technical-details#authentication
17+
*/
18+
const vonage = new Vonage(
19+
{
20+
applicationId: VONAGE_APPLICATION_ID,
21+
privateKey: VONAGE_PRIVATE_KEY,
22+
},
23+
{
24+
...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}),
25+
},
26+
);
27+
28+
vonage.messages.send({
29+
messageType: 'text',
30+
channel: Channels.MMS,
31+
text: 'This is an RCS text message sent via the Vonage Messages API.',
32+
to: MESSAGES_TO_NUMBER,
33+
from: MMS_SENDER_ID,
34+
})
35+
.then(({ messageUUID }) => console.log(messageUUID))
36+
.catch((error) => console.error(error));
37+

0 commit comments

Comments
 (0)