Express 调用Twilio号时查询用户表

Express 调用Twilio号时查询用户表,express,parse-platform,twilio,Express,Parse Platform,Twilio,我使用Parse.com作为后端服务。当有人拨打twilio号码时,我想在云代码中检测呼叫者的电话号码,然后查询相应的用户电话号码。我能够通过request.param('From')获取呼叫者号码,但是我无法查询该用户。我尝试以多种形式在/hello函数中进行查询,但没有成功。我使用了与其他云函数相同的查询集。查询记录为未定义。为什么会这样? Xcode: 解析云代码 //Someone calling twilio number app.get('/hello', funct

我使用Parse.com作为后端服务。当有人拨打twilio号码时,我想在云代码中检测呼叫者的电话号码,然后查询相应的用户电话号码。我能够通过request.param('From')获取呼叫者号码,但是我无法查询该用户。我尝试以多种形式在/hello函数中进行查询,但没有成功。我使用了与其他云函数相同的查询集。查询记录为未定义。为什么会这样? Xcode:

解析云代码

    //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();

它不起作用,因为以下代码不在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();

请您发布一个完整的代码示例,其中您尝试提取呼叫者号码,并对该号码执行查询。您发布的代码似乎确实在这样做,因此很难在这一点上为您指出正确的方向。ardrian我编辑了我的代码。request.param('From')提取呼叫者号码。@ardrian当我进行twiml.dial({callerId:'twilioNumber'},request.param('From'))时;它会回叫来电者。因此,唯一的问题是查询用户表。在控制台中,它表示foundusr未定义。在查询成功但未找到匹配项的情况下,foundusr将未定义。在调用拨号方法之前,您应该检查foundusr是否已定义谢谢@ardrian我发现了我的错误很高兴您发现了错误。您仍然应该检查以确保定义了结果,以处理找不到数字的情况。
//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();