簡體   English   中英

Javascript等待函數響應完成

[英]Javascript wait for a function response to complete

我試圖在Facebook機器人實現中提出一個后續問題“快速回復”。 您可以看到完整的app.js(此處為示例文件): https : //github.com/fbsamples/messenger-platform-samples/blob/master/node/app.js

當1)用戶輸入命令(例如“你好”)時,我向用戶發送了相關的響應之后; 2)我想問一個后續問題。例如:“你想知道今天的天氣嗎?”

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

即我想等待1完成再執行2。但是,由於某種原因,天氣問題總是首先顯示給用戶。 任何幫助,將不勝感激

在setTimeout中包裝功能

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM