npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reshuffle-twilio-connector

v0.0.13

Published

A Reshuffle Twilio connector

Downloads

19

Readme

reshuffle-twilio-connector

Code | npm | Code sample

npm install reshuffle-twilio-connector

Reshuffle Twilio Connector

This package is a Reshuffle connector that provides access to the Twilio service. This connector can be used to send SMS and MMS out. It can also trigger your code (through handlers) on incoming messages.

The following example listens to an incoming SMS and responds back to the service:

const { Reshuffle } = require('reshuffle')
const { TwilioConnector } = require('reshuffle-twilio-connector')
const app = new Reshuffle()

// Create w Twilio account in few minutes for free: https://www.twilio.com/
const twilioConnector = new TwilioConnector(app, {
  accountSid: '<accountSid>',
  authToken: '<authToken>',
  twilioNumber: '<twilioNumber>',
})

// Reply to an incoming message on <twilioNumber>
twilioConnector.on({ method: 'POST', path: '/sms' }, (event, app) => {
  const messageReceived = event.req.body.Body
  const fromPhoneNumber = event.req.body.From
  console.log(`New SMS received from ${fromPhoneNumber}: ${messageReceived}`)

  if (messageReceived.includes('test')) {
    event.res.end('test successful')
  } else {
    event.res.end('Thanks for your message')
  }
})

app.start()

Configuration Options:

interface TwilioConnectorConfigOptions {
    accountSid: string
    authToken: string
    opts?: Twilio.TwilioClientOptions
    twilioNumber?: string
}

Connector events

new messages

This event is fired when new messages are delivered to a <twilioNumber>.

For setting up webhooks in Twilio:

  • go to https://www.twilio.com/console/phone-numbers/incoming
  • select the phone number you'd like to use
  • scroll all the way down to messaging
  • create a new webhook with method and path
  • save

You can now trigger a handler on incoming messages.

Usage:
twilioConnector.on({method:'POST', path:'/sms'}, (event, app) => {
  console.log(event.req.body)
  // Example of console output for event.req.body:
  // {
  //   ToCountry = "US"
  //   ToState = "ID"
  //   SmsMessageSid = "SM9aca55a393c120f964cc49d91bfec52e"
  //   NumMedia = "0"
  //   ToCity = "DESMET"
  //   FromZip = "85004"
  //   SmsSid = "SM9aca55a393c120f964cc49d91bfec52e"
  //   FromState = "AZ"
  //   SmsStatus = "received"
  //   FromCity = "PHOENIX"
  //   Body = "msg line 1 line 2 line 3"
  //   FromCountry = "US"
  //   To = "+12082685987"
  //   ToZip = "99128"
  //   NumSegments = "1"
  //   MessageSid = "SM9aca55a393c120f964cc49d91bfec52e"
  //   AccountSid = "AC43820350f399443f2ab9a80ce59dc797"
  //   From = "+19282275501"
  //   ApiVersion = "2010-04-01"
  // }

  const messageReceived = event.req.body.Body
  const fromPhoneNumber = event.req.body.From
  console.log(`New SMS received from ${fromPhoneNumber}: ${messageReceived}`)

  if(messageReceived.includes('test')) {
    event.res.end("test successful")
  } else {
    event.res.end("Thanks for your message")
  }
})

Connector actions

This connector provides 2 types of actions for sending SMS or MMS via Twilio

sendSMS

send a message via Twilio:

myTwilioConnector.sendSMS('<your-message>', '<to-phone-number>' )
sendMMS

send a media message via Twilio:

myTwilioConnector.sendMMS('<your-message>', '<media-url>','<to-phone-number>' )
sdk

returns a Twilio client (using the connector config options)

See documentation in Twilio github: https://github.com/twilio/twilio-node

Example on how to use this connector can be found here.