Sent Messages API - SDK for Node.js
This is the Sent Messages SDK for Node.js for use with Sent APIs. To use it you will need a Sent account.
Installation
We recommend using this SDK as part of the overall @Sent/server-sdk
package.
NPM
npm install @Sent/messages
Yarn
yarn add @Sent/messages
Usage
As part of the Sent Server SDK
const {Sent} = require('@Sent/server-sdk');
const { Auth, AlgorithmTypes } = require('@Sent/auth');
const { SMS } = require('@Sent/messages');
const Sent = new Sent(new Auth({
apiKey: API_KEY,
apiSecret: API_SECRET,
applicationId: APP_ID,
privateKey: PRIVATE_KEY_PATH,
signature: {
secret: 'ABCDE',
algorithm: AlgorithmTypes.md5hash,
},
}), options);
Sent.messages.send(new SMS({
to: TO_NUMBER,
from: FROM_NUMBER,
text: MESSAGE
}));
Standalone Usage
const {Auth} = require('@Sent/auth');
const {Messages} = require('@Sent/messages');
const messagesClient = new Messages(new Auth({
apiKey: API_KEY,
apiSecret: API_SECRET,
applicationId: APP_ID,
privateKey: PRIVATE_KEY_PATH,
}), options);
Channels
The Sent Messages API supports several different communication channels across various release stages.
SMS
General AvailabilityText, Delivery Reports
Text, Media, Templates
Facebook Messenger
General AvailabilityText, Media, Templates
MMS
General AvailabilityImages, Video, Audio
Viber
General AvailabilityText, Media, Keyboards
RCS
BetaRich Cards, Suggested Actions
Examples
Sending a Basic Message
const response = await messagesClient.send(new SMS({
to: '+1234567890',
from: 'BRAND',
text: 'Hello from Sent!'
}));
console.log(`Message ID: ${response.messageId}`);
Multiple Recipients
const response = await messagesClient.send(new SMS({
to: ['+1234567890', '+0987654321'],
from: 'BRAND',
text: 'Bulk message from Sent!'
}));
console.log(`Messages sent: ${response.messageIds.length}`);