2017-01-02 40 views
0

我試圖在Facebook bot實現中詢問後續問題「快速回復」。你可以看到完整的app.js(示例文件在這裏):https://github.com/fbsamples/messenger-platform-samples/blob/master/node/app.jsJavascript正在等待函數響應完成

當1)用戶輸入命令 - 例如「你好」,在我向用戶發送相關回復後 - 2)我想問一個跟進問題。 「你想知道今天的天氣嗎?」

case 'hello': 
     sendHelloGenericReponse(senderID); 
     sendWeatherQuickReplyQuestion(senderID); //only execute this after above is complete 
     break; 

I.e.我想在做2之前等待1完成。但是,由於某些原因,天氣問題總是首先顯示給用戶。任何幫助,將不勝感激

+0

功能的使用您在'sendHelloGenericReponse'和'sendWeatherQuickReplyQuestion'方法的承諾? –

回答

0

包裹你的setTimeout

case 'hello': 
 
    sendHelloGenericReponse(senderID); 
 
    setTimeout(function(){ 
 
     sendWeatherQuickReplyQuestion(senderID); 
 
    },0) //only execute this after above is complete 
 
    break;

+0

這有什麼用? – vlaz

+0

和vlaz一樣的問題? :) – ChicagoDude

+0

它將確保完全執行當前堆棧,然後此方法'sendWeatherQuickReplyQuestion(senderID)'。雖然它不依賴於第一種方法的響應。 – ricky