我使用Parse.com作为后端服务。当有人拨打twilio号码时,我想检测云代码中的来电号码,然后查询相应的用户电话号码。我能够通过request.param(' From')获取呼叫者号码但是我无法查询该用户。我尝试在多种形式的/ hello函数中查询,但它不起作用。我使用了同样的查询集,适用于其他云功能。该查询记录为未定义。为什么会这样? xcode的:
NSString *callString = [NSString stringWithFormat:@"telprompt://twilioNumber"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:callString]];
解析云代码
//Someone calling twilio number
app.get('/hello', function(request, response) {
var twiml = new twilio.TwimlResponse('');
var query = new Parse.Query(Parse.User);
query.equalTo("PhoneNumber", request.param('From'));
query.first({
success: function(result) {
var foundusr = result;
var receiver = foundusr.get("Receiver");
twiml.dial({callerId:'twilioNumber'}, receiver);
},
error: function(error) {response.error("Error updating user passcode");
});
response.type('text/xml');
response.send(twiml.toString(''));
});
app.listen();
答案 0 :(得分:0)
它不起作用,因为以下代码不在query.first函数
中twiml.dial({callerId:'twilioNumber'}, receiver);
response.type('text/xml');
所以正确的方法是
//Someone calling twilio number
app.get('/hello', function(request, response) {
var twiml = new twilio.TwimlResponse('');
var query = new Parse.Query(Parse.User);
query.equalTo("PhoneNumber", request.param('From'));
query.first({
success: function(result) {
var foundusr = result;
var receiver = foundusr.get("Receiver");
twiml.dial({callerId:'twilioNumber'}, receiver);
response.type('text/xml');
response.send(twiml.toString(''));
},
error: function(error) {response.error("Error updating user passcode");
});
});
app.listen();