Plivode
Plivode is a lightweight scalable application framework for creating Plivo apps with NodeJS.
Installing
npm install plivode
Getting Started
Let's run through a few examples to see how Plivode works.
Example: Hello, World!
var plivode = ; appID: '[your Plivo app ID]' authID: '[your Plivo auth ID]' authToken: '[your Plivo auth token]' rootUrl: '[the root URL this app is accessible by Plivo]';
It doesn't get much simpler than this! Here we create a new Plivode app, which will answer any received phone calls with "Hello, world!"
Plivode makes use of Express to run a web server for receiving messages from Plivo.
Simply specify the URL of your server, and make sure the port you specify is accesible to the outside world. For example,
if your Plivode app is running on port 1919 of plivode-app.example.com, you'd pass: rootUrl: 'http://plivode-app.example.com:1919'
Application Events
Your Plivode app will raise events when you need to respond to a phone call or sms message. The standard Plivo events are:
answer
- raised when a call is received by any of the phone numbers associated with your app.message
- raised when a sms message is received by any of the phone numbers associated with your app.hangup
- raised when a call is ended.
Example: Parrot
See it in action! Send a sms to (949) 484-8425
. Within a few seconds you'll get a call speaking your message.
var plivode = ; appID: '[your Plivo app ID]' authID: '[your Plivo auth ID]' authToken: '[your Plivo auth token]' rootUrl: '[the root URL this app is accessible by Plivo]';
Here we listen for sms messages, and when one is received we call the number back and speak the message 3 times.
Plivode provides support for the entire Plivo REST API. Here we use Call.outbound
to make the call.
Notice that we specify the custom event parrot/:message
. This event is raised when the outbound call is answered.
Since event names map directly to Express routes, we're able to use Express' powerful
routing engine to specify parameters within the event name.
When we make the outbound call, we pass in the action route ['parrot', params.Text]
. The first field of your route must
be the event name, and the remaining fields can be parameters to pass to the next step of the call. If you don't need to
pass along parameters you can simply pass the event name as a string.
Example: Guess the Number
See it in action! Call (949) 484-8425
.
Pick a number between 1 and 100, and the app will try to guess it. If you're thinking of a lower number press *
; higher press #
;
and if the guess is correct press 0
.
var plivode = ; appID: '[your Plivo app ID]' authID: '[your Plivo auth ID]' authToken: '[your Plivo auth token]' rootUrl: '[the root URL this app is accessible by Plivo]';
Documentation
More documentation is on the way! For now, partial documentation is available here.