【问题标题】:Calling Parse Cloud Code function from Express Get Method从 Express Get 方法调用 Parse Cloud Code 函数
【发布时间】:2016-02-18 09:16:28
【问题描述】:

我只是想问那些精通 Parse、Cloud Code、Twilio 和 Express 的人...

基本上,我已经设置了一个 node.js Express 函数来处理特定 URL 的 GET通知其帐户与该特定号码相关联的用户。

因此我的问题是在下面的代码示例中是否会调用 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);
        }
    });

});

我希望这会起作用,但在我的情况下它似乎失败了......如果我遗漏了什么,请告诉我。

谢谢!

【问题讨论】:

  • 这在什么方面失败了?就像您收到 NOTIFICATION FAILED 事件一样?如果是这样,错误是什么?您忽略的一件事是您没有从 app.get 返回。你需要在成功和错误中添加一个明确的return语句。

标签: express parse-platform parse-cloud-code


【解决方案1】:

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

由于某种原因(可能是 Apple 的限制?),它们似乎没有被发送,而且当我查看日志时,似乎也没有调用该函数,但我肯定会收到一些推送通知。

更新

实际上最终效果更好的只是将推送通知发送代码放在一个普通的旧 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 能够继续存在......但这是另一个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-12
    • 1970-01-01
    相关资源
    最近更新 更多