从Express Get Method调用Parse Cloud Code函数

时间:2016-02-13 05:43:42

标签: express parse-platform cloud-code

我对Parse,Cloud Code,Twilio和Express等知识渊博的人有一个超级快速的问题......

基本上我已经设置了一个node.js Express函数来处理特定URL的GET,只要有人拨打电话号码就会被Twilio调用,我想从GET调用Parse Cloud Code函数处理程序函数,通知其帐户与该特定号码相关联的用户。

因此我的问题是在Parse Cloud函数下面的代码示例中是否" notifyConferenceNumberOwner"将被召唤。

app.get('/conf', function(request, response) {

    var phoneNumber = request.query['To'];

    var twiml = new twilio.TwimlResponse();
    twiml.say('Your conference call will begin momentarily.',
    {
        voice:'woman',
        language:'en-gb'
    })
    .dial({
        action:'http://url-to-call-status',
        method:'GET'
    },
    function(node) {
        node.conference('MyConference', {
        waitUrl:'http://twimlets.com/holdmusic?Bucket=com.twilio.music.guitars',
        startConferenceOnEnter:'true',
        beep:'true'
            });
    });

    response.type('text/xml');
    response.send(twiml.toString());

    Parse.Cloud.run('notifyConferenceNumberOwner', { conferenceCallNumber: phoneNumber }, {
        success: function(ratings) {
            console.log('*** NOTIFICATION SUCCEEDED');
        },
        error: function(error) {
            console.error('*** NOTIFICATION FAILED: ' + error);
        }
    });

});

我希望这会起作用,但在我的情况下似乎失败了...如果我错过了某些东西,请告诉我。

谢谢!

1 个答案:

答案 0 :(得分:1)

在进一步测试中,事实上,似乎正在调用Parse Cloud Code函数 并且正在发送推送通知。

出于某种原因(可能会限制苹果公司的部分?)看起来他们没有被发送,看起来这个功能似乎没有在我查看日志时被调用,但我肯定会收到一些推送通知。 / p>

更新

实际上最终工作得更好的只是将推送通知发送代码放在一个普通的旧JavaScript函数中,如此处所述(甚至没有回调):

https://www.parse.com/questions/can-i-use-a-cloud-code-function-within-another-cloud-code-function

现在它看起来更像是这样:

app.get('/conf', function(request, response) {

    var phoneNumber = request.query['To'];

    var twiml = new twilio.TwimlResponse();
    twiml.say('Your conference call will begin momentarily.',
    {
        voice:'woman',
        language:'en-gb'
    })
    .dial({
        action:'http://url-to-call-status',
        method:'GET'
    },
    function(node) {
        node.conference('MyConference', {
        waitUrl:'http://twimlets.com/holdmusic?Bucket=com.twilio.music.guitars',
        startConferenceOnEnter:'true',
        beep:'true'
            });
    });

    sendCallNotification(phoneNumber);

    response.type('text/xml');
    response.send(twiml.toString());
});

......现在它每次都在工作,到目前为止一直非常可靠。

sendCallNotification只是为推送通知准备一条消息,然后调用Parse.Push.send() - 它可以工作,也可以不工作。无论哪种方式,在这种情况下都没有真正的消费者信息,所以我只记录它成功或失败的事实。

我很满意,而且效果很好!

希望Parse能够坚持下去......但这是另一个问题。