How do I get the caller ID from twilio? I've tried many different ways to get the POST data but it isn't working.
如何从twilio获取来电显示?我已经尝试了许多不同的方法来获取POST数据,但它无法正常工作。
var twilio = require('./node_modules/twilio/index'),
http = require('http'),
express = require('express');
http.createServer(function (req, res) {
/*
var app = express();
app.use(express.urlencoded());
app.post('/call',function (req, res) {
*/
var name, from;
// if (req.method=='POST')
// req.on('From', function (data) {from = data;});
try {
from = req.param('From');
// from = req.body.from;
}
catch (err)
{
console.log("No Caller ID");
}
console.log("Number: " + from);
//Some code goes here..
res.end(resp.toString());
}).listen(8080);
It's throwing me the error every single time at the try catch statement (always null).
它每次都在try catch语句中抛出错误(总是为null)。
I'm trying to get the caller ID of an incoming text message.
我正在尝试获取传入文本消息的来电显示。
Things in comments are the different approaches I tried.
评论中的内容是我尝试过的不同方法。
The thrown error is:
抛出的错误是:
Error TypeError: Object #IncomingMessage> has no method 'param'
错误TypeError:对象#IncomingMessage>没有方法'param'
1 个解决方案
#1
3
I guess that this will do the trick:
我想这可以解决问题:
var qs = require('querystring');
var processRequest = function(req, callback) {
var body = '';
req.on('data', function (data) {
body += data;
});
req.on('end', function () {
callback(qs.parse(body));
});
}
var http = require('http');
http.createServer(function (req, res) {
processRequest(req, function(data) {
// data
});
}).listen(9000, "127.0.0.1");
#1
3
I guess that this will do the trick:
我想这可以解决问题:
var qs = require('querystring');
var processRequest = function(req, callback) {
var body = '';
req.on('data', function (data) {
body += data;
});
req.on('end', function () {
callback(qs.parse(body));
});
}
var http = require('http');
http.createServer(function (req, res) {
processRequest(req, function(data) {
// data
});
}).listen(9000, "127.0.0.1");