Skip to content

Commit cb64854

Browse files
chore: added failover example (#181)
Co-authored-by: Karl Lingiah <karl@superchilled.co.uk>
1 parent 0744d12 commit cb64854

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 RCS_SENDER_ID = process.env.RCS_SENDER_ID;
7+
const SMS_SENDER_ID = process.env.SMS_SENDER_ID;
8+
const MESSAGES_API_URL = process.env.MESSAGES_API_URL;
9+
10+
const { Vonage } = require('@vonage/server-sdk');
11+
const { Channels, MessageType } = 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+
to: MESSAGES_TO_NUMBER,
31+
from: RCS_SENDER_ID,
32+
channel: Channels.RCS,
33+
messageType: MessageType.TEXT,
34+
text: 'This is an RCS text message sent via the Vonage Messages API.',
35+
failover: [
36+
{
37+
to: MESSAGES_TO_NUMBER,
38+
from: SMS_SENDER_ID,
39+
channel: Channels.SMS,
40+
messageType: MessageType.TEXT,
41+
text: 'This is an SMS sent using the Vonage Messages API.',
42+
43+
}
44+
]
45+
})
46+
.then(({ messageUUID }) => console.log(messageUUID))
47+
.catch((error) => console.error(error));

0 commit comments

Comments
 (0)