Skip to content

Simple SMS sender to multiple recipients using Twilio

License

Notifications You must be signed in to change notification settings

yorch/simple-sms-sender

Repository files navigation

Simple SMS Sender

Library to send SMS messages to multiple recipients using Twilio API.

install size Typescript Known Vulnerabilities

Installation

yarn add simple-sms-sender

or

npm install --save simple-sms-sender

Usage

import { SmsSender } from 'simple-sms-sender';

const sender = new SmsSender({
    accountId: '', // string
    fromNumber: '', // string
    logger, // Logger instance, optional, defaults to console.log and console.error
    secret: '', // string
    sid: '' // string
});

// Returns a promise
sender.sendSms({
    body: '', // string
    recipients: [] // array of strings
});

sender.sendMultipleSms([
    { body: '', recipients: [] },
    { body: '', recipients: [] }
]);

Example

import { SmsSender } from 'simple-sms-sender';
import pino from 'pino';

const logger = pino();

const config = {
    accountSid: '{Your Twilio Account SID}',
    fromNumber: '{Phone number to send }',
    secret: '{Your Twilio Secret}',
    sid: '{Your Twilio SID}'
};

const createSender = () => {
    const { accountSid, fromNumber, secret, sid } = config;

    return new SmsSender({
        accountSid,
        fromNumber,
        logger,
        secret,
        sid
    });
};

const smsSender = createSender();

smsSender.sendMultipleSms([
    {
        body: 'Some message',
        recipients: ['+19999999999', '+18888888888']
    },
    {
        body: 'Some other message message',
        recipients: ['+19999999999']
    }
]);