UNPKG

@vonage/messages

Version:

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

84 lines 2.54 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 log = (0, debug_1.default)('vonage:messages:sms'); /** * Send a text message using the SMS channel. * * @group SMS */ class SMS extends AbstractTextMessage_1.AbstractTextMessage { channel; sms; /** * 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 use MessageParamsText instead'); params = { text: params, to: to, from: from, clientRef: clientRef, }; } super(params); this.channel = 'sms'; if (typeof params === 'string') { return; } this.sms = params.sms ? { encodingType: params.sms?.encodingType, contentId: params.sms?.contentId, entityId: params.sms?.entityId, } : undefined; } } exports.SMS = SMS; //# sourceMappingURL=SMS.js.map