twilio-response-builder
Build your Twilio SMS Response before connecting to the Twilio Webhook
Last updated 3 years ago by hjchen .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install twilio-response-builder 
SYNC missed versions from official npm registry.

Twilio-Response-Builder is a package for building SMS response before connecting with the Twilio webhook. It provides the SMS response in XML format for sending to the Twilio server, and a callback for mounting on Express/Loopback custom routers.

For Loopback Router:

var builder = require('twilio-response-builder');
var client = new builder(
    '/test',
    'GET',
    'hello world'
);

module.exports = function(app){
    if (client.method==='GET'){
        app.get(client.route, client.requestCallback);
    }
    else if (client.method==='POST'){
        app.post(client.route,client.requestCallback);
    }
}

For Express.js Router:

var twilio = require('twilio-response-builder');
var client = new twilio(
    '/test',
    'GET',
    'hello world'
);
app.route(client.route)
.get(client.requestCallback);

If you only need to extract the XML response

(Notice: since we only need the client.smsXMLResponse property, the first 2 parameters of the constructor don't really matter. However, the first parameter (route : String) must be started with a '/' and the second parameter (method : String) must be either 'GET' or 'POST', as of version 1.1.2.):

app.get('/test', function(res,req){

    var smsResponse = 'hello world';

    var twilio = require('twilio-response-builder');

    var client = new twilio('///', 'GET',smsResponse); 
    // send message HERE
    res.setHeader('content-type','application/xml');
    res.send(client.smsXMLResponse);
});

Connect the webhook with your application like this in Messaging -> A Message Comes In:

Change /[your custom route] to client.route and the HTTP request drop down to client.method. In the Express example above, we should change the method to HTTP GET:

Click Save. And now you can test the server:

Current Tags

  • 1.2.0                                ...           latest (3 years ago)

12 Versions

  • 1.2.0                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.8                                ...           3 years ago
  • 1.0.7                                ...           3 years ago
  • 1.0.6                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 1
This Week 3
This Month 4
Last Day 0
Last Week 1
Last Month 4
Dependencies (1)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |