honktang/twilio-hub
Tag 0
No description field found in package.json
  Published by honktang on Friday, June 16th, 2017, 3:35:24 AM
  # Your StdLib Twilio Hub Welcome to your Twilio Hub on StdLib! The goal of the Twilio Hub is to provide your project, team or company with a fully-functional, robust telephony hub for things like bots and customer support. Through StdLib, you're guaranteed that your infrastructure scales infinitely and you never have to manage servers. While it is necessary to write *some* code, StdLib is easy and malleable enough to be completely hackable to even the most junior developers. # Your Project The first thing you'll probably notice is your `functions/` directory. This is your StdLib function directory which maps directly to HTTP endpoints. There are six "out of the box" functions in your Twilio Hub. - `__main__.js` - `voice/__main__.js` - `messaging/__main__.js` - `messaging/__notfound__.js` - `messaging/more.js` - `messaging/whoami.js` We'll go through these in the order listed here. ## Function: `functions/__main__.js` This is your main endpoint, corresponding to `https://<username>.lib.id/<service>/`. This is, of course, where `<username>` is your username and `<service>` is your service name. Any time a function has the filename `__main__.js`, the enclosing folder is used as the route name over HTTP. You can think of it like the default function for a specific directory. Note that when pushing to a development environment (or if you want to access a specific version), this should be reached via: `https://username.lib.id/service@dev/main` (if your dev environment is called `dev`, also the default local environment name) or `https://username.lib.id/service@0.0.0/main` (if your version is 0.0.0). ### Usage This endpoint initiates a conversation with a specific telephone number via SMS. Just provide a number (via the `tel` parameter) to begin. With the [StdLib command line tools](https://github.com/stdlib/lib), you can test this using `$ lib . --tel [Telephone Number]` ## Function: `functions/voice/__main__.js` This is the main HTTP Webhook handler for incoming phonecalls from Twilio. You'll set your Twilio Webhook handler to accept this using the URL: ``` dev environment: http://username.lib.id/service@dev/voice/ production: http://username.lib.id/service/voice/ ``` Where `username` is your StdLib username and `service` is the name of this service as its deployed. ### Usage Simply point your Twilio number voice webhook to this URL. By default, it redirects any incoming calls to `process.env.FORWARD_NUMBER` (`"FORWARD_NUMBER"` in `env.json`.) ## Function: `functions/messaging/__main__.js` This is the main HTTP Webhook handler for incoming SMS and MMS messages from Twilio. You'll set your Twilio Webhook handler to accept this using the URL: ``` dev environment: http://username.lib.id/service@dev/messaging/ production: http://username.lib.id/service/messaging/ ``` Where `username` is your StdLib username and `service` is the name of this service as its deployed. ### Usage This function will dispatch other StdLib functions that you've built, namely the `functions/messaging/__notfound__.js`, `functions/messaging/more.js` and `functions/messaging/whoami.js` to begin with (unless you add more). ## Function: `functions/messaging/__notfound__.js` This is the SMS / MMS "not found" handler. It also handles *any MMS messages* via the `media` parameter. If the message your Twilio Hub on StdLib receives can not be mapped to a named function (like `more` or `whoami`) this handler will be triggered. ### Usage This handler outputs a string for simple messaging and development testing. You can test from your command line using: ```shell $ lib .messaging.__notfound__ --body "My message" ``` Or for an MMS message, ```shell $ lib .messaging.__notfound__ --media file:./path/to/myfile.jpg ``` ## Function: `functions/messaging/more.js` This is the SMS handler for messages containing the word "more" (in any capitalization variation) as their sole contents. All named functions will be dispatched similarly from `functions/messaging/__main__.js`, but this can be modified to suit your needs, specifically. ### Usage This handler outputs a string for simple messaging and development testing. You can test from your command line using: ```shell $ lib .messaging.more ``` ## Function: `functions/messaging/whoami.js` This is the SMS handler for messages containing the word "whoami" (in any capitalization variation) as their sole contents. It is meant to show the use of the `to` and `from` objects to show you can track originating number information. ### Usage This handler outputs a string for simple messaging and development testing. You can test from your command line using: ```shell $ lib .messaging.whoami ``` # Helpers You'll notice a `/helpers/` directory which contains a single function. You should store Twilio helpers here, like sending picture messages, videos, or any time you want to write logic that you don't want to repeat. ## Helper: `helpers/send.js` Sends messages using [Twilio's NPM module](https://www.npmjs.com/package/twilio) and your account information from `env.json`. # That's it! We hope this has served as a welcoming introduction to your Twilio Hub project scaffold on [StdLib](https://stdlib.com) --- happy building!
# Your StdLib Twilio Hub Welcome to your Twilio Hub on StdLib! The goal of the Twilio Hub is to provide your project, team or company with a fully-functional, robust telephony hub for things like bots and customer support. Through StdLib, you're guaranteed that your infrastructure scales infinitely and you never have to manage servers. While it is necessary to write *some* code, StdLib is easy and malleable enough to be completely hackable to even the most junior developers. # Your Project The first thing you'll probably notice is your `functions/` directory. This is your StdLib function directory which maps directly to HTTP endpoints. There are six "out of the box" functions in your Twilio Hub. - `__main__.js` - `voice/__main__.js` - `messaging/__main__.js` - `messaging/__notfound__.js` - `messaging/more.js` - `messaging/whoami.js` We'll go through these in the order listed here. ## Function: `functions/__main__.js` This is your main endpoint, corresponding to `https://<username>.lib.id/<service>/`. This is, of course, where `<username>` is your username and `<service>` is your service name. Any time a function has the filename `__main__.js`, the enclosing folder is used as the route name over HTTP. You can think of it like the default function for a specific directory. Note that when pushing to a development environment (or if you want to access a specific version), this should be reached via: `https://username.lib.id/service@dev/main` (if your dev environment is called `dev`, also the default local environment name) or `https://username.lib.id/service@0.0.0/main` (if your version is 0.0.0). ### Usage This endpoint initiates a conversation with a specific telephone number via SMS. Just provide a number (via the `tel` parameter) to begin. With the [StdLib command line tools](https://github.com/stdlib/lib), you can test this using `$ lib . --tel [Telephone Number]` ## Function: `functions/voice/__main__.js` This is the main HTTP Webhook handler for incoming phonecalls from Twilio. You'll set your Twilio Webhook handler to accept this using the URL: ``` dev environment: http://username.lib.id/service@dev/voice/ production: http://username.lib.id/service/voice/ ``` Where `username` is your StdLib username and `service` is the name of this service as its deployed. ### Usage Simply point your Twilio number voice webhook to this URL. By default, it redirects any incoming calls to `process.env.FORWARD_NUMBER` (`"FORWARD_NUMBER"` in `env.json`.) ## Function: `functions/messaging/__main__.js` This is the main HTTP Webhook handler for incoming SMS and MMS messages from Twilio. You'll set your Twilio Webhook handler to accept this using the URL: ``` dev environment: http://username.lib.id/service@dev/messaging/ production: http://username.lib.id/service/messaging/ ``` Where `username` is your StdLib username and `service` is the name of this service as its deployed. ### Usage This function will dispatch other StdLib functions that you've built, namely the `functions/messaging/__notfound__.js`, `functions/messaging/more.js` and `functions/messaging/whoami.js` to begin with (unless you add more). ## Function: `functions/messaging/__notfound__.js` This is the SMS / MMS "not found" handler. It also handles *any MMS messages* via the `media` parameter. If the message your Twilio Hub on StdLib receives can not be mapped to a named function (like `more` or `whoami`) this handler will be triggered. ### Usage This handler outputs a string for simple messaging and development testing. You can test from your command line using: ```shell $ lib .messaging.__notfound__ --body "My message" ``` Or for an MMS message, ```shell $ lib .messaging.__notfound__ --media file:./path/to/myfile.jpg ``` ## Function: `functions/messaging/more.js` This is the SMS handler for messages containing the word "more" (in any capitalization variation) as their sole contents. All named functions will be dispatched similarly from `functions/messaging/__main__.js`, but this can be modified to suit your needs, specifically. ### Usage This handler outputs a string for simple messaging and development testing. You can test from your command line using: ```shell $ lib .messaging.more ``` ## Function: `functions/messaging/whoami.js` This is the SMS handler for messages containing the word "whoami" (in any capitalization variation) as their sole contents. It is meant to show the use of the `to` and `from` objects to show you can track originating number information. ### Usage This handler outputs a string for simple messaging and development testing. You can test from your command line using: ```shell $ lib .messaging.whoami ``` # Helpers You'll notice a `/helpers/` directory which contains a single function. You should store Twilio helpers here, like sending picture messages, videos, or any time you want to write logic that you don't want to repeat. ## Helper: `helpers/send.js` Sends messages using [Twilio's NPM module](https://www.npmjs.com/package/twilio) and your account information from `env.json`. # That's it! We hope this has served as a welcoming introduction to your Twilio Hub project scaffold on [StdLib](https://stdlib.com) --- happy building!
Begins a conversation with a specified telephone number
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
tel
(required)
The telephone number to initiate messaging with
  code
Main messaging (SMS/MMS) handler. Upon receiving a message, first check to see if there's media (MMS), if so, invoke __notfound__ handler with a media object, otherwise, check to see if message corresponds to a handler (more, whoami), invoke that if possible, or invoke __notfound__ with raw contents of message body.
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
Body
= ""
The message contents
{string}
From
= ""
The inbound number
{string}
FromZip
= ""
The zip associated with inbound number
{string}
FromCity
= ""
The city associated with inbound number
{string}
FromState
= ""
The state associated with inbound number
{string}
FromCountry
= ""
The country associated with inbound number
{string}
To
= ""
The outbound number, i.e. your Twilio Number
{string}
ToZip
= ""
The zip associated with outbound number
{string}
ToCity
= ""
The city associated with outbound number
{string}
ToState
= ""
The state associated with outbound number
{string}
ToCountry
= ""
The country associated with outbound number
{string}
AccountSid
= ""
The Twilio Account SID - sent from Twilio, used to verify webhook authenticity
  code
MORE handler, responds if user texts "more" (or any uppercase variation like "MORE")
  info
  parameters (click to modify)
{string}
tel
= ""
The incoming telephone number
{string}
body
= ""
The (text) body of the message
{object}
from
= {}
Information about the incoming message: number, zip, city, state, country
{object}
to
= {}
Information about the receiver (your Twilio number): number, zip, city, state, country
  code
WHOAMI handler, responds if user texts "whoami" (or any uppercase variation like "WHOAMI")
  info
  parameters (click to modify)
{string}
tel
= ""
The incoming telephone number
{string}
body
= ""
The (text) body of the message
{object}
from
= {}
Information about the incoming message: number, zip, city, state, country
{object}
to
= {}
Information about the receiver (your Twilio number): number, zip, city, state, country
  code
Not found handler - handles all SMS / MMS that don't match a command (i.e. "more" = functions/messaging/more.js)
  info
  parameters (click to modify)
{string}
tel
= ""
The incoming telephone number
{string}
body
= ""
The (text) body of the message
{buffer}
media
= null
The media content of the message, if any
{object}
from
= {}
Information about the incoming message: number, zip, city, state, country
{object}
to
= {}
Information about the receiver (your Twilio number): number, zip, city, state, country
  code
Main voice handler. Upon receiving a call, outputs a TwiML response to handle call routing. Default is to forward the call to a number of your choosing, to be used for call forwarding from a help line, for example. See https://www.twilio.com/docs/api/twiml/dial for more information.
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
From
= ""
The number that's calling (inbound)
{string}
AccountSid
= ""
The Twilio Account SID - sent from Twilio, used to verify webhook authenticity
  code