2016-02-13 60 views
2

我只是對那些知識淵博的解析,雲代碼,Twilio和快速超快速的問題...調用從快速解析雲代碼功能GET方法

基本上我已經設置了Node.js的快速功能它處理GET的特定URL,Twilio每當有人撥打電話號碼時都會調用該URL,並且我想從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); 
     } 
    }); 

}); 

我希望這會工作,但它似乎失敗了我的情況...讓我知道如果我失去了一些東西。

謝謝!

+0

這種失敗的方式是什麼?正如你收到NOTIFICATION FAILED事件?如果是這樣,錯誤是什麼? 你忽略的一件事是你沒有從app.get返回。您需要在成功和錯誤中添加快速返回語句。 –

回答

1

在進一步測試中,看起來實際上,解析雲代碼功能被調用並正在發送推送通知。由於某種原因(也許在蘋果的部分上限制?)它似乎沒有被髮送,它似乎也沒有被調用,當我看着日誌,但我絕對正在接受一些推送通知。

UPDATE

其實什麼結束了更好的工作只是把推送通知,如這裏所描述(甚至不回調)一個普通的老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() - 並且它可以工作,或者它不工作。無論哪種方式,在這種情況下,這些信息都不是真正的消費者,所以我只記錄它成功或失敗的事實。

我很滿意,它的工作很棒!

只是希望解析會一直在... ...但這是另一個問題。