如何使用twilio模块发送解析用户objectId

时间:2014-01-28 18:41:52

标签: javascript parse-platform twilio

我一直在尝试获取解析用户的Object ID,以便我可以将其发送到用户的电话号码。云代码是用javascript完成的,我不熟悉。我相信问题出在我的代码上。以下是我到目前为止所做的事情:

var twilio = require("twilio");
twilio.initialize("myAccountSid","myAuthToken");

// Create the Cloud Function
Parse.Cloud.define("inviteWithTwilio", function(request, response) {

// getting objectId from Parse
var query = new Parse.Query("objectId");

query.equalTo("username", request.params.number);

query.find({

success: function(httpResponse){

response.success("Code found");
},
error: function(httpResponse){

response.error("Code not found");

}

});

// Use the Twilio Cloud Module to send an SMS 
twilio.sendSMS({
From: "myTwilioPhoneNumber",
To:    request.params.number,
Body: "Start using Parse and Twilio!" + query
}, {
success: function(httpResponse) { response.success("SMS sent!"); },
error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
});
});

我需要帮助使这段代码有效。我可以阅读的书籍建议可以提高我对JavaScript的理解。

1 个答案:

答案 0 :(得分:1)

终于能够解决我的问题了。我真正需要的只是Parse.User.current().id。这是工作代码:

var twilio = require("twilio");
twilio.initialize("myAccountSid","myAuthToken");

// Create the Cloud Function
Parse.Cloud.define("inviteWithTwilio", function(request, response) {
// Use the Twilio Cloud Module to send an SMS


var objectId = Parse.User.current().id ;  

twilio.sendSMS({
From: "myTwilioPhoneNumber",
To: request.params.number,
Body: "Your Apps verification code is "  + objectId
}, {
success: function(httpResponse) { response.success("SMS sent!"); },
error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
});  
});