2017-01-25 10 views
0

API呼び出しから応答を受け取った後に関数を呼び出そうとしています。ここでは、この2つのAPIを扱うスラックAPI

function saveScore(bot,result,message){ 
    getFirstScore(bot,result).then(function(fscore){ //API -1 
     if(fscore){ 
      getSecondScore(bot,result,null).then(function(sscore){ //API -2 
       if(fscore && sscore){ 
        var finalScores = "First score is " + fscore + " :innocent:" + "\n Second score is "+ sscore +" :blush: "; 
        var remindAttachment = util.reminderAttachment("",finalScores); 
        listAllScores(bot,message,remindAttachment); 
       } 
      },function(error){ 
       console.log('sscore error: ' + error); 
      }); 
     } 
    },function(error){ 
     console.log('fscore error: ' + error); 
    }); 
} 

function listAllScores(bot,message,remindAttachment){ 
    sendInstructions = function(response, convo){ 
     convo.say(remindAttachment); 
     convo.say("Take it to the next level:"); 
     convo.next(); 
     setTimeout(function(){   
     listScores(bot,message); 
     },2000); 
    }       
    bot.startPrivateConversation(message, sendInstructions); 
} 

と同じように、私はlistScores(ボット、メッセージ)を呼び出したいです。以降の機能convo.say(remindAttachment);。しかし今はロード中listScores(bot、message);最初はです。だから、私はタイムアウト(良いアプローチではない)を設定していますlistScores(bot、message);いつか後でをロードしてください。

もっと良い方法がありますか?listScores(bot、message);以降の機能convo.say(remindAttachment);

編集

function listAllScores(bot,message,remindAttachment){ 
    sendInstructions = function(response, convo){ 
     convo.say(remindAttachment, function(error){ 
      console.log("error ::::::::::::::::::::",error); 
      if(error!=null) { 
       listScores(bot,message); 
      } 
     }); 
    }       
    bot.startPrivateConversation(message, sendInstructions); 
} 

答えて

0

関数パラメータと、そのコールバック呼び出し内部 "listScores(ボット、メッセージ)" 関数としてコールバックを持っているために、このconvo.say()関数を変更します。この convo.say様(remindAttachment、関数(誤差){ 場合(エラー!= NULL){ listScores(BOT、メッセージ) }})応答を

+0

おかげ。コールバックを使用しようとしましたが、そのコールバック関数が呼び出されていません。 – NNR

+0

convo.say関数のスニペットを教えていただけますか? –

関連する問題