Send SMS using Twilio API.
$ npm install moleculer-twilio --save
Before use please set the
TWILIO_ACCOUNT_SID
,TWILIO_AUTH_TOKEN
andTWILIO_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);
});
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. |
Send an SMS
Property | Type | Default | Description |
---|---|---|---|
to |
String |
required | Target phone number |
message |
String |
required | Message text |
mediaUrl |
String |
- | Media URL |
Type: String
Send an SMS
Property | Type | Default | Description |
---|---|---|---|
to |
String |
required | Target phone number |
body |
String |
"\"\"" |
Body of SMS |
mediaUrl |
String |
- | Media URL |
Type: String
$ npm test
In development with watching
$ npm run ci
The project is available under the MIT license.
Copyright (c) 2016-2019 MoleculerJS