我有一个相当复杂的机器人,但是它在本地工作。但是,一旦我发布它,它就会失败并显示以下错误:


  抱歉,我的机器人代码有问题。


我尝试使用Application Insights,但未显示错误详细信息。
该错误总是在同一点发生:

/// <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并提出问题。问题是一个选择。我认为这就是问题所在,因为它总是在问题出现后立即抛出该信息。

有人能在代码中发现任何明显的东西吗?

最佳答案

当您的漫游器抛出500时,将给出您引用的错误消息。查看您的代码,我猜是您有一个null ref异常。在“ //获取我们的问题和答案”下的部分中,尝试检查group.Questions不为null,并且_currentQuestion是该数组的有效索引。

关于c# - Microsoft Bot Framework在本地工作,但远程失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40977140/

10-10 03:00