Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including moleculer-twilio with all npm packages installed. Try it out:

require("moleculer/package.json"); // moleculer is a peer dependency. var moleculerTwilio = require("moleculer-twilio")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

moleculer-twilio v1.0.11

Send SMS Message with Twilio.

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](https://www.twilio.com/console/voice/dashboard) 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](https://www.twilio.com/console/voice/dashboard) 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](https://www.twilio.com/console/phone-numbers/incoming). | ## `send`

Send an SMS

Parameters

PropertyTypeDefaultDescription
toStringrequiredTarget phone number
messageStringrequiredMessage text
mediaUrlString-Media URL

Results

Type: String

## `sendSMS`

Send an SMS

Parameters

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

Results

Type: String

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free