2016-12-05 58 views
2

我有這個機器人是相當複雜的,但它工作在本地。但只要我發佈,它失敗,出現錯誤:微軟博特框架本地工作,但遠程失敗

Sorry, my bot code is having an issue.

我一直在使用應用洞察試過,但它沒有顯示錯誤的詳細信息。 錯誤總是發生在同一點:

/// <summary> 
/// Start our response 
/// </summary> 
/// <param name="context">The current context</param> 
/// <returns></returns> 
public async Task StartAsync(IDialogContext context) 
{ 

    // Get our current step 
    _groups = await _groupProvider.ListAsync(); 
    _group = _groups.First(); 

    // Post the question header 
    await context.PostAsync(_group.Text); 

    // Wait for the users response 
    context.Wait(AskQuestion); 
} 

/// <summary> 
/// When our message is recieved we execute this delegate 
/// </summary> 
/// <param name="context">The current context</param> 
/// <param name="result">The result object</param> 
/// <returns></returns> 
private async Task AskQuestion(IDialogContext context, IAwaitable<IMessageActivity> result) 
{ 

    // Get our question and answers 
    var question = this._group.Questions[_currentQuestion]; 
    var questionText = question.Text; 
    var answers = question.Answers.Select(m => m.Text).ToList(); 
    var answerCount = question.Answers.Count; 

    // Create our options 
    var options = new PromptOptions<string>(questionText, options: answers); 

    // Ask our question 
    Choice<string>(context, GetAnswer, options); 
} 

/// <summary> 
/// Get our answer and decide what to do next 
/// </summary> 
/// <param name="context">The current context</param> 
/// <param name="result">The answer text</param> 
/// <returns></returns> 
private async Task GetAnswer(IDialogContext context, IAwaitable<string> result) 
{ 

    // Get our quest 
    var questions = _group.Questions; 
    var length = questions.Count; 
    var question = _group.Questions[_currentQuestion]; 
    var selectedAnswer = await result; 

    // Assign our answer to our question 
    foreach (var answer in question.Answers) 
     if (answer.Text == selectedAnswer) 
      question.Answer = answer; 

    // If we have an answer, filter the products 
    if (question.Answer != null) 
     _productProvider.Score(await GetCurrentProducts(), _groups); 

    // Increase our index 
    _currentQuestion++; 

    // If our current index is greater or equal than the length of the questions 
    if (_currentQuestion == length) 
    { 

     // Create our dialog 
     var dialog = _dialogFactory.CreateSecondStepDialog(_dialogFactory, _groupProvider, _questionProvider, _productProvider, await GetCurrentProducts()); 

     // Otherwise, got to the next step 
     await context.Forward(dialog, ResumeAfter, new Activity { }, CancellationToken.None); 
     return; 
    } 

    // Ask our next question 
    await AskQuestion(context, null); 
} 

所以,當這對話框啓動時,它張貼問題介紹給客戶。 然後我調用context.Wait並提出問題。問題是一個選擇。我認爲這是問題出在哪裏,因爲只要問題出現,它就會一直拋出這個信息。

任何人都可以點任何與代碼昭然若揭?

+0

什麼版本的BotBuilder運行? –

回答

0

你引用的錯誤信息,當你的機器人拋出一個500看你的代碼中給出,我的猜測是,你有一個空REF例外。在根據「//獲取我們的問題和答案」的章節,嘗試檢查group.Questions不爲空,並且_currentQuestion是有效的索引到該數組。

相關問題