Now when someone calls the twilio number, /hello function in Parse Cloud Code is executed. In /hello function I can find who is making the call by request.param('From'). With this information I want to query that user and then get the Receiver's phone number, which is in the 'Receiver' column of the User Table.
app.get('/hello', function(request, response) {
var twiml = new twilio.TwimlResponse('');
// querying the caller
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("username", request.param('From')); // querying the caller
query.find( {
success: function(result) {
twiml.dial({callerId:'+4XXXXXX7'}, result[0].get("Receiver")); // dialing the receiver
console.log("user is " +result[0]);
response.success("user is found");
},
error: function (error) {
response.error("failed finding the user");
}
});
response.type('text/xml');
response.send(twiml.toString(''));
});
app.listen();
The querying does not work and the logs that are in the query.find does not print. I tried query.first instead of query.find but that too did not work.