Skip to content

nemo/twilio-f

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Twilio-f

stdlib.com service

This service helps you forward calls or SMS that you receive on a Twilio Number to any phone number that you'd like.

It's a micro-service built using stdlib that you can use as a Twilio Number web-hook.

Usage

SMS & Call Forwarding

This service is already available to be used on stdlib here, or you can fork it and launch your version of it on stdlib.

The main function is called forward and it accepts two parameters (other than the ones that come from Twilio):

  • type - the type of forwarding to do: call or SMS.
  • ForwardTo - the phone number to forward the call or SMS to.

So to construct a webhook that forwards all calls to 415-xxx-xxxx, all you have to do is:

https://nemo.api.stdlib.com/twilio/forward?ForwardTo=+1415xxxxxxx&type=call

And to do the same for SMS:

https://nemo.api.stdlib.com/twilio/forward?ForwardTo=+1415xxxxxxx&type=SMS

You can use these URLs as the web-hooks in Twilio's Voice and SMS web-hooks.

Enjoy forwarding!

Sending Messages

Twilio provides a great API for sending messages. However, after building a few chat-bots and SMS products, you learn a thing or two. This service makes it easier to deliver messages and provide a better experience for the receiver. It's also a great and scalable way to wrap your messaging service.

The main features are that it handles multiple mediaUrls, automatically truncates long messages and attempts to control delivery order using timeouts.

You have to set the following environment variables to make the function work (which means you have to fork this repo and submit your own stdlib function!):

  • TWILIO_ACCOUNT_SID - Twilio Account SID
  • TWILIO_ACCOUNT_AUTH - Twilio Account Auth

After you've set those, you can call the function (built on top of twilio's node sdk):

var f = require('f');

f("<stdlib-username>/twilio/sendMessage")({
    to: "+1415xxxxxxx",
    from: "+1415xxxxxxx",
    body: "Body goes here",
    mediaUrls: ["path-to-url"],
    splitLength: 160, // optional, set to 0 if you want to disable splitting
    MessagingServiceSid: '<MessagingServiceSid>', // optional
    StatusCallback: '<StatusCallback>', // optional
    ApplicationSid: '<ApplicationSid>', // optional
    MaxPrice: "<MaxPrice>", // optional
    ProvideFeedback: "<ProvideFeedback>", // optional
    otherParameter: "Other params accepted by Twilio's node sdk"
});

The result will be an array with a status set to ok or failure, message set to the payload that was sent, and result or error being the response from Twilio.

Functions

/twilio/forward

function spec | source

This function responds with Twiml that forwards a phone call or SMS to another number.

/twilio/sendMessage

function spec | source

This function sends a message using Twilio's messages.create API. It handles cases were the message body is too long, only a media Url is provided or multiple mediaUrls are being sent.

LICENSE

MIT

About

Twilio microservice to forward Calls and SMS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published