为了完整起见,这里有一个使用 Express 获取Twilio请求参数的完整示例。在运行之前,请确保使用npm install twilio express
. 阅读这篇介绍 Twilio node.js 模块的博文,您也可能会受益。
此代码是响应呼入电话的示例:
// Module dependencies
var twilio = require('twilio'),
express = require('express');
// Create an Express webapp, and use a middleware
// that parses incoming POST parameters
var app = express();
app.use(express.urlencoded());
// Create a route that responds to a phone call by saying
// the caller's number
app.post('/call', function(request, response) {
var twiml = new twilio.TwimlResponse();
twiml.say('Hello, you called from ' + request.param('From'));
response.type('text/xml');
response.send(twiml.toString());
});
// Start the app on port 3000
app.listen(3000);