Skip to content

Latest commit

 

History

History

moleculer-twilio

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Moleculer logo

moleculer-twilio NPM version

Send SMS using Twilio API.

Install

$ npm install moleculer-twilio --save

Usage

Before use please set the TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN and TWILIO_PHONE_NUMBER environment variables.

let { ServiceBroker }     = require("moleculer");
let SmsService             = require("../../index");

// Create broker
let broker = new ServiceBroker({ logger: console });

// Load my service
broker.createService({
    name: "twilio",
    mixins: [SmsService],
    settings: {
        phoneNumber: "+15005550006"
    }
});

// Start server
broker.start().then(() => {

    broker
        .call("twilio.send", { to: "+14108675309", message: "Hello Twilio!" })
        .then(sms => console.log("SMS sent. Sid:", sms.sid))
        .catch(console.error);

});

Settings

Property Type Default Description
accountSid String required Twilio account Sid. Visit your Twilio dashboard's main page. Click "Show API Credentials", then copy and paste your "ACCOUNT SID" here or set TWILIO_ACCOUNT_SID env var.
authToken String required Twilio auth token. Visit your Twilio dashboard's main page. Click "Show API Credentials", then copy and paste your "AUTH TOKEN" here or set TWILIO_AUTH_TOKEN env var.
phoneNumber String required This is the 'From' phone number you'd like to use to send the SMS. This phone number is assigned to you by Twilio.

Actions

send

Send an SMS

Parameters

Property Type Default Description
to String required Target phone number
message String required Message text
mediaUrl String - Media URL

Results

Type: String

Methods

sendSMS

Send an SMS

Parameters

Property Type Default Description
to String required Target phone number
body String "\"\"" Body of SMS
mediaUrl String - Media URL

Results

Type: String

Test

$ npm test

In development with watching

$ npm run ci

License

The project is available under the MIT license.

Contact

Copyright (c) 2016-2019 MoleculerJS

@moleculerjs @MoleculerJS