c# - 机器人在模拟器上工作,但在 Azure 上不工作(InternalServerError)

标签 c# azure botframework

使用:

  • SDK 语言:C#
  • SDK 版本:4.1.5
  • 环境:本地主机、Azure
  • channel :网络聊天
<小时/>

问题描述

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

Figure 1: Bot working on emulator

在 Azure 中部署后,遵循 this说明,机器人停止工作(既不发送也不接收消息)并在网络聊天 channel 部分收到此警报:

Figure 2: Alerts at the channel section

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

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

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

但就我而言,AppId 和密码都已定义,而另一个解决方案根本不起作用。 我什至设法在 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);
    }

最佳答案

正如 tdurnford 所说在评论部分,有必要将生产 enpoint 服务添加到 .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"
}

关于c# - 机器人在模拟器上工作,但在 Azure 上不工作(InternalServerError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53629637/

相关文章:

c# - GetHashCode() 与 ^

c# - C# 中的命名约定 - 全局变量

c# - 未找到 ConnectionMultiplexer.cs

python - 通过机器人 channel 注册使用 Python 的 Skype for Business 机器人

botframework - Microsoft Bot Framework - Bot 进入休眠状态。有没有办法防止它?

c# - 您可以在 SSIS 中重复使用代码吗?你能以编程方式更改源/目标吗?

c# - DDD聚合根有一个创建对象的静态方法是否正确

Azure Blob 容器文件下载

python - Azure Web 服务和 Django 日志