Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twilly

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twilly

Node.js Twilio API abstraction layer for Express applications

  • 0.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Twilly 📱💬

Writing the back end of an SMS web application with Twilio should be easy, and Twilly was created to greatly simplify the process of writing such applications.

Twilly is a Node.js library that can be used with TypeScript or JavaScript and integrates with Express.js. It works in conjunction with the Twilio API to allow you to defined complex SMS interactions for your users with ease.

The design of the library's exposed interface was built with one goal in mind, make interactions as easy to design as they are with tools like FlowXO or Twilio Studio but allow the interactions to be defined with code (in this case, JavaScript) instead of a GUI.


Contents

  1. Installation and Setup
  2. Quick Start
  3. Documentation
  4. License
  5. Contributing
  6. Bugs or Feature Suggestions
  7. Feature Pipeline

Installation and Setup

Twilly is published on npm. To add Twilly to your Node.js Express application, run

npm i -s twilly

You will download a precompiled version of Twilly so there is no need to add TypeScript or Twilly's settings to your build config.

You will need to have an account with Twilio in order to use Twilly, if there is demand to allow other APIs to be compatible then I am open to adding more. For now, you will need to create a messaging service with Twilio using their dashboard. You will also need to set your inbound message url to the path of your application you use the twilly function.

I recommend you download the package ngrok (or another library like it) while developing with Twilly.


Quick Start

The most simple interaction a user can have with an SMS application is where whenever the user sends a message, the application replies with "Hello world!". Twilly allows us to code this application in just a few lines.

First you need to install the required dependencies,

const bp = require('body-parser');
const express = require('express');

and let's set up our Express application,

const app = express();

app.use(bp.urlencoded({ extended: false, limit: '2mb' }));
app.use(bp.json({ limit: '5mb' }));

// Twilio requires your site have a GET to your index return an HTML response
app.get('/', (req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/html' });
  res.end('<html><body>Hello world!</body></html>');
});

Now let's start defining your SMS app. Twilly separates the different type of interactions into linear sequences of actions called Flows. A Flow is a linear collection of actions your app can take after receiving a message.

The application we want to build just has one Flow, the user sends a message and the application replies with "Hello world!". So let's import the Flow and Reply objects from Twilly.

const { Flow, Reply } = require('twilly');

The Flow any user who hasn't already started any application enters is called the "root" Flow. Every other Flow is a "child" of this Flow, and later on, we will see how to initiate Flows within each other using the Trigger object.

Now let's set up the root Flow for this interaction,

const root = new Flow();

root.addAction('reply', () => new Reply('Hello world!'));

The add action method on the Flow object appends a new action to the end of the Flow. The first argument is the name of the action, and can be used later to retrieve metadata about the action in later actions.

The last thing we need to do is add the twilly function to the Express app. This is done below:

const { twilly } = require('twilly');

app.use('/twilly', twilly({
  accountSid: TWILIO_ACCOUNT_SID,
  authToken: TWILIO_AUTH_TOKEN,
  messagingServiceSid: TWILIO_MESSAGE_SERVICE_ID,
  root,
}));

You can see the entire twilly app in working form in examples/quickstart.js.


Documentation

You can view the documentation of Twilly's exposed objects and API here.


License

Twilly is available free of charge under the MIT license. See LICENSE.md for details.


Contributing

See CONTRIBUTING.md for information on contribution guidlines and community standards.


Bugs or Feature Suggestions

To report any bugs or suggest any features or improvements, please open an issue here.


Feature Pipeline

Below is a list of the features I plan on adding to twilly in the future. I am always open to suggested features and contributions from other developers who want to make twilly better!

Trigger Flows outside of the twilly() function

As pointed out in Issue #3 it would be nice to be able to trigger flows from other places in your Node application outside of the twilly function. This seems like a common use case and seems feasible though I have not actually tried implementing. PRs are welcome if anyone is interested as well.

Filtering Actions

Right now there is no way to "filter" (or skip) Actions in a Flow. Either an Action is performed or the entire interaction ends. The next release I plan on doing is adding an ability to filter actions so that interactions can continue even if a particular action is not performed.

I am open to suggestions about implementation, but right now I am planning on adding a 3rd optional argument to Flow.addAction which is a function of the Flow and user contexts and returns a Boolean which indicates if the Action should execute. For Flow.addActions this would be an optional filter key in each of the plain objects. Each Action's contexts would have a filtered key which would be false if an Action is performed or true if no Action was performed and the Flow skipped to the next Action.

Keywords

FAQs

Package last updated on 14 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc