UNPKG

@vonage/messages

Version:

Multi-channel messaging that integrates WhatsApp, Facebook, Viber, SMS, and MMS

95 lines 3.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SMS = void 0; const AbstractTextMessage_1 = require("../AbstractTextMessage"); const debug_1 = __importDefault(require("debug")); const enums_1 = require("../../enums"); const log = (0, debug_1.default)('vonage:messages:sms'); /** * Send a text message using the SMS channel. * * @group SMS */ class SMS extends AbstractTextMessage_1.AbstractTextMessage { /** * The channel for this message (always 'sms'). */ channel = enums_1.Channels.SMS; sms; /** * The duration in seconds the delivery of an SMS will be attempted. By * default Vonage attempts delivery for 72 hours, however the maximum * effective value depends on the operator and is typically 24 - 48 hours. We * recommend this value should be kept at its default or at least 30 minutes. */ ttl; /** * Send an SMS message * * @param {MessageParamsText | string} params - The message parameters or text message. * @param {string} to - The recipient's phone number. * @param {string} from - The sender's phone number. * @param {string} clientRef - The client reference for the message. * * @example * ```ts * import { SMS } from '@vonage/messages'; * * const { messageUUID } = await messagesClient.send(new SMS({ * to: TO_NUMBER, * from: FROM_NUMBER, * text: 'Hello world', * clientRef: 'my-personal-reference', * })); * * console.log(`Message sent successfully with UUID ${messageUUID}`); * ``` * * @example * Send SMS with entity ID and content ID * ```ts * import { SMS } from '@vonage/messages'; * * const { messageUUID } = await messagesClient.send(new SMS({ * to: TO_NUMBER, * from: FROM_NUMBER, * text: 'Hello world', * clientRef: 'my-personal-reference', * sms: { * entityId: 'MyEntityID', * contentId: 'MyContentID' * } * })); * * console.log(`Message sent successfully with UUID ${messageUUID}`); * ``` */ constructor(params, to, from, clientRef) { if (to) { log('Please update the call to pass in an object instead of parameters'); params = { text: params, to: to, from: from, clientRef: clientRef, }; } super(params); if (typeof params === 'string') { return; } this.ttl = params.ttl; this.sms = params.sms ? { encodingType: params.sms?.encodingType, contentId: params.sms?.contentId, entityId: params.sms?.entityId, } : undefined; } } exports.SMS = SMS; //# sourceMappingURL=SMS.js.map