UNPKG

1.49 kBMarkdownView Raw
1# Simple SMS Sender [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=yorch/simple-sms-sender)](https://dependabot.com)
2
3Library to send SMS messages to multiple recipients using Twilio API.
4
5## Installation
6
7```sh
8yarn add simple-sms-sender
9```
10
11or
12
13```sh
14npm install --save simple-sms-sender
15```
16
17## Usage
18
19```js
20import { SmsSender } from 'simple-sms-sender';
21
22const sender = new SmsSender({
23 accountId: '', // string
24 fromNumber: '', // string
25 logger, // Logger instance, optional, defaults to console.log and console.error
26 secret: '', // string
27 sid: '', // string
28});
29
30// Returns a promise
31sender.sendSms({
32 body: '', // string
33 recipients: [] // array of strings
34})
35```
36
37## Example
38
39```js
40import { SmsSender } from 'simple-sms-sender';
41import pino from 'pino';
42
43const logger = pino();
44
45const config = {
46 accountSid: '{Your Twilio Account SID}',
47 fromNumber: '{Phone number to send }',
48 secret: '{Your Twilio Secret}',
49 sid: '{Your Twilio SID}'
50};
51
52const sendSms = ({ body, recipients }) => {
53 const {
54 accountSid, fromNumber, secret, sid,
55 } = config;
56
57 const smsSender = new SmsSender({
58 accountSid,
59 fromNumber,
60 logger,
61 secret,
62 sid,
63 });
64
65 return smsSender.sendSms({
66 body,
67 recipients,
68 });
69};
70
71Promise.all([
72 sendSms({
73 body: 'Some message',
74 recipients: ['+19999999999', '+18888888888']
75 }),
76 sendSms({
77 body: 'Some other message message',
78 recipients: ['+19999999999']
79 })
80]);
81```