Bot在模拟器上工作,但不在Azure上工作(InternalServerError)

时间:2018-12-05 10:02:33

标签: c# azure botframework

使用:

  • SDK语言:C#
  • SDK版本:4.1.5
  • 环境:本地主机,Azure
  • 频道:网络聊天

问题描述

在Bot Framework Emulator V4中测试该机器人时,它的确按预期工作,如下图所示:

Figure 1: Bot working on emulator

按照this的说明将其部署到Azure后,机器人停止工作(发送或接收消息),并在网络聊天频道部分收到此警报:

Figure 2: Alerts at the channel section

我发现了这些类似的问题:

https://github.com/Microsoft/BotFramework-Emulator/issues/296

https://github.com/Microsoft/BotBuilder/issues/3329

但是在我的案例中,同时定义了AppId和Password,而另一个解决方案根本不起作用。 我什至设法在azure平台上找到错误代码,但我无法找到详细信息或错误的来源...

Figure 3: AppInsights Error panel

代码概述

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        bool reintentar = false;
        //tried this but didn't work
        //MicrosoftAppCredentials.TrustServiceUrl("http://botrps.azurewebsites.net");         

        //obtener el contexto de los dialogos
        var dc = await _dialogs.CreateContextAsync(turnContext, cancellationToken);

        if (turnContext.Activity.Type == ActivityTypes.Message && turnContext.Activity.From.Id != turnContext.Activity.Recipient.Id)
        {
            //bot operations on users messages
        }    

        //if active dialog
        await dc.ContinueDialogAsync(cancellationToken);

        //else, start greeting dialog
        if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate &&
            turnContext.Activity.MembersAdded[0].Id != turnContext.Activity.Recipient.Id)
        {
            await dc.BeginDialogAsync("dialogo", null, cancellationToken);
        }

        await _accessors.ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);

        // Guarda los cambios realizados en el Contexto, si hay alguno
        await _accessors.UserState.SaveChangesAsync(turnContext, false, cancellationToken);
    }

1 个答案:

答案 0 :(得分:0)

正如tdurnford在评论部分所述,有必要将生产委托服务添加到.bot配置中。生成的bot文件:

{
  "name": "BotMod2",
  "services": [
    {
      "type": "endpoint",
      "name": "development",
      "endpoint": "http://localhost:3978/api/messages",
      "appId": "",
      "appPassword": "",
      "id": "1"
    },
    {
      "appId": "**********************",
      "appPassword": "**********************",
      "endpoint": "https://**********************.azurewebsites.net/api/messages",
      "type": "endpoint",
      "name": "production",
      "id": "2"
    },
    {
      "appId": "**********************",
      "authoringKey": "**********************",
      "version": "0.1",
      "region": "westus",
      "type": "luis",
      "name": "**********************",
      "id": "3"
    },
    {
      "type": "qna",
      "name": "**********************",
      "kbId": "**********************",
      "hostname": "https://**********************.azurewebsites.net/qnamaker",
      "endpointKey": "**********************",
      "subscriptionKey": "**********************",
      "id": "4"
    }
  ],
  "padlock": "",
  "version": "2.0"
}