Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

moleculer-twilio

v1.0.10arrow_drop_down
v1.0.10
STATUS
Passing
DOWNLOADS
0
VISIBILITY
Public
PUBLISHED
8 months ago
SIZE
N/A
Send a message using the Twilio API. https://www.twilio.com
1 contributor
Use moleculer-twilio in your project ?
Copied
npm i @bit/moleculerjs.moleculer-addons.moleculer-twilio
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
revert changes
reload
toggle layout
maximize
chevron_left
chevron_right

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

PropertyTypeDefaultDescription
accountSidStringrequiredTwilio 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.
authTokenStringrequiredTwilio 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.
phoneNumberStringrequiredThis is the ‘From’ phone number you’d like to use to send the SMS. This phone number is assigned to you by Twilio.

<!-- AUTO-CONTENT-TEMPLATE:SETTINGS

PropertyTypeDefaultDescription

{{#each this}} | {{name}} | {{type}} | {{defaultValue}} | {{description}} | {{/each}} {{^this}} No settings. {{/this}}

–>

Actions

send

Send an SMS

Parameters

PropertyTypeDefaultDescription
toStringrequiredTarget phone number
messageStringrequiredMessage text
mediaUrlString-Media URL

Results

Type: String

<!-- AUTO-CONTENT-TEMPLATE:ACTIONS {{#each this}}

{{name}} {{#each badges}}{{this}} {{/each}}

{{#since}} <sup>Since: {{this}}</sup> {{/since}}

{{description}}

Parameters

PropertyTypeDefaultDescription

{{#each params}} | {{name}} | {{type}} | {{defaultValue}} | {{description}} | {{/each}} {{^params}} No input parameters. {{/params}}

{{#returns}}

Results

Type: {{type}}

{{description}} {{/returns}}

{{#hasExamples}}

Examples

{{#each examples}} {{this}} {{/each}} {{/hasExamples}}

{{/each}} –>

Methods

sendSMS

Send an SMS

Parameters

PropertyTypeDefaultDescription
toStringrequiredTarget phone number
bodyString"\"\""Body of SMS
mediaUrlString-Media URL

Results

Type: String

<!-- AUTO-CONTENT-TEMPLATE:METHODS {{#each this}}

{{name}} {{#each badges}}{{this}} {{/each}}

{{#since}} <sup>Since: {{this}}</sup> {{/since}}

{{description}}

Parameters

PropertyTypeDefaultDescription

{{#each params}} | {{name}} | {{type}} | {{defaultValue}} | {{description}} | {{/each}} {{^params}} No input parameters. {{/params}}

{{#returns}}

Results

Type: {{type}}

{{description}} {{/returns}}

{{#hasExamples}}

Examples

{{#each examples}} {{this}} {{/each}} {{/hasExamples}}

{{/each}} –>

Test

$ npm test

In development with watching

$ npm run ci

License

The project is available under the MIT license.

Contact

Copyright © 2016-2018 MoleculerJS

@moleculerjs @MoleculerJS

Test Summary

should be created

Pass

should create Twilio client instance

Pass

should call client.messages.create

Pass

should call client.messages.create and return with error

Pass

should call the sendSMS method successfully

Pass