Twilio $_REQUEST['From'] 等效于 node.js [英] Twilio $_REQUEST['From'] equivalent for node.js
问题描述
我正在尝试使用twilio"从来电中获取来电显示.我设法在我的 call.php 文件中使用以下内容轻松做到了这一点:
I'm trying to use 'twilio' to grab the caller ID from an incoming phone call. I managed to do this easily in my call.php file using the following:
$callerId=($_REQUEST['From']);
我现在已经重定向了我的 twilio 电话号码以访问不同的 URL,以便我可以将它与 node.js 一起使用(即 call.php 现在是 call.js).但是,我似乎无法以与 .php 文件类似的方式请求 ['From'] 字段.这可能吗?使用 node.js 获取调用者 ID 并将其存储在变量中的最简单方法是什么?
I have now redirected my twilio phone number to access a different URL so that I can use it with node.js (ie call.php is now call.js). However, I cannot seem to request the ['From'] field in a similar manner as with the .php file. Is this possible? What is the easiest way to grab a caller Id and store it in a variable using node.js?
任何想法表示赞赏.
推荐答案
为了完整起见,这里有一个获取 Twilio 使用 Express 请求参数.在运行之前,请确保使用 npm install twilio express
安装依赖项.您也可能受益于阅读 这篇博文介绍了 Twilio node.js 模块.
For the sake of completeness, here's a full example of getting Twilio request parameters using Express. Before running, make sure to install dependencies with npm install twilio express
. You might also benefit from reading this blog post introducing the Twilio node.js module.
此代码是响应入站电话的示例:
This code is an example of responding to an inbound phone call:
// 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);
这篇关于Twilio $_REQUEST['From'] 等效于 node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!