Botframework github上tompaana开发的代理切换中介程序bot示例(c#);t将Microsoft.Bot.Builder和相关软件包升级到4.10.3版 问题陈述

Botframework github上tompaana开发的代理切换中介程序bot示例(c#);t将Microsoft.Bot.Builder和相关软件包升级到4.10.3版 问题陈述,botframework,asp.net-core-middleware,Botframework,Asp.net Core Middleware,这是关于tompaana在guithub上创建的实时代理切换中介程序bot示例(c#) intermediator bot示例与Microsoft.bot.Builder(4.2.2)和Microsoft.bot.Builder.Integration.AspNet.Core(4.2.2)以及相关版本4.2.2包完美配合使用,但是,它不使用对话框。 当我添加包Microsoft.Bot.Builder.Dialogs(4.10.3)时,切换中间件代码停止被调用(,因为我现有的代码需要对话框)

这是关于tompaana在guithub上创建的实时代理切换中介程序bot示例(c#)

  • intermediator bot示例与Microsoft.bot.Builder(4.2.2)和Microsoft.bot.Builder.Integration.AspNet.Core(4.2.2)以及相关版本4.2.2包完美配合使用,但是,它不使用对话框。

  • 当我添加包Microsoft.Bot.Builder.Dialogs(4.10.3)时,切换中间件代码停止被调用(,因为我现有的代码需要对话框)。这也导致将Microsoft.Bot.Builder升级到4.10.3版及其相关软件包,如Microsoft.Bot.Builder.Integration.AspNet.Core等

社区支持 原始作者Handoff intermediator bot示例已转移到其他项目,无法再将时间用于此项目,并已请求联系MS Botframework社区成员以获得支持()

  • 请求BotFramework社区提供帮助,向我现有的聊天机器人添加代理移交功能
观察:
  • 即使在包升级之后,切换中间件类也会在启动期间成功实例化

  • 我改装的代码包含BotController类,通过它可以调用所有API。此BotController类不在原始切换中介程序bot示例代码中

  • 在聊天机器人(升级/新代码)上键入任何话语时,控件进入BotController,而不是调用/触发切换中间件。OnTurnAsync(…)

  • 由于原始中间人bot示例代码没有任何BotController/API控制器,这可能是语音没有通过切换中间件进行路由的原因吗?如果是这样,我如何解决问题?

参考包 原始中间人bot示例引用包

升级的intermediator bot示例引用包

原始中间程序bot示例解决方案文件

升级的intermediator bot示例解决方案文件

查询 你能建议我如何解决这个问题吗

  • 当我执行核心代码时,HandoffMiddleware.OnTurnAsync(..)运行良好,但是,使用升级的Microsoft.Bot.Builder相关软件包将IntermediateBot代码改装为版本4.10.3后,不会从我的代码中触发

  • 指向现有的工作代理切换示例(c#)也会有所帮助

以下解决方案使升级后的Tompanna代理切换解决方案能够顺利工作:
  • 解决方案在于BotFrameworkHttpAdapter调用切换中间件的方式
Github中的示例提供了调用任何中间件的方法,即在我们升级了Microsoft.Bot.Builder和引入BotController类/API控制器概念的相关软件包的场景中

来自的AdapterWithInspection.cs的代码参考 将以下代码中的检查中间件替换为切换中间件


命名空间Microsoft.BotBuilderSamples
{
检查中的公共类适配器:BotFrameworkHttpAdapter
{
检查中的公用适配器(I配置配置、检查状态检查状态、用户状态用户状态、会话状态会话状态、ILogger记录器)
:基本(配置、记录器)
{
//检查需要认证,因为它将向仿真器发送活动、用户和会话状态
var凭据=新的MicrosoftAppCredentials(配置[“MicrosoftAppId”]、配置[“MicrosoftAppPassword”]);
//***********************************************************************************//
//*检查中间件需要替换执行管道中的HandOffMddieWare*//
//***********************************************************************************//          
使用(新的InspectionMiddleware(inspectionState、userState、conversationState、credentials));
OnTurnError=async(turnContext,异常)=>
{
//记录应用程序中泄漏的任何异常。
logger.LogError(异常,$”[OnTurnError]未处理的错误:{exception.Message}”);
//向用户发送消息
等待turnContext.SendActivityAsync(“机器人遇到错误或bug”);
等待turnContext.SendActivityAsync(“若要继续运行此bot,请修复bot源代码”);
//发送跟踪活动,该活动将显示在Bot Framework Emulator中
等待turnContext.TraceActivityAsync(“OnTurnError Trace”,exception.Message,”https://www.botframework.com/schemas/error“,”旋转误差“);
};
}
}
}
新代码应该如下所示
//版权所有(c)微软公司。版权所有。
//根据麻省理工学院许可证授权。
命名空间Microsoft.BotBuilderSamples
{
检查中的公共类适配器:BotFrameworkHttpAdapter
{
检查中的公用适配器(I配置配置、检查状态检查状态、用户状态用户状态、会话状态会话状态、ILogger记录器)
:基本(配置、记录器)
{
//检查需要凭证,因为
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;

namespace Neo.Controllers
{
    // This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot
    // implementation at runtime. Multiple different IBot implementations running at different endpoints can be
    // achieved by specifying a more specific type for the bot constructor argument.
    [Route("api/messages")]
    [ApiController]
    public class BotController : ControllerBase
    {
        private readonly IBotFrameworkHttpAdapter Adapter;
        private readonly IBot Bot;

        public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
        {
            Adapter = adapter;
            Bot = bot;
        }

        [HttpPost, HttpGet]
        public async Task PostAsync()
        {
            // Delegate the processing of the HTTP POST to the adapter.
            // The adapter will invoke the bot.
            await Adapter.ProcessAsync(Request, Response, Bot);
        }
    }
}


namespace Microsoft.BotBuilderSamples
{
    public class AdapterWithInspection : BotFrameworkHttpAdapter
    {
        public AdapterWithInspection(IConfiguration configuration, InspectionState inspectionState, UserState userState, ConversationState conversationState, ILogger<BotFrameworkHttpAdapter> logger)
            : base(configuration, logger)
        {
            // Inspection needs credentiaols because it will be sending the Activities and User and Conversation State to the emulator
            var credentials = new MicrosoftAppCredentials(configuration["MicrosoftAppId"], configuration["MicrosoftAppPassword"]);

//***********************************************************************************//
//* InspectionMiddleware needs to be replace HandOffMddieWare in the execution pipeline *// 
//***********************************************************************************//          
              Use(new InspectionMiddleware(inspectionState, userState, conversationState, credentials));

            OnTurnError = async (turnContext, exception) =>
            {
                // Log any leaked exception from the application.
                logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}");

                // Send a message to the user
                await turnContext.SendActivityAsync("The bot encountered an error or bug.");
                await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code.");

                // Send a trace activity, which will be displayed in the Bot Framework Emulator
                await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError");
            };
        }
    }
}

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.


namespace Microsoft.BotBuilderSamples
{
    public class AdapterWithInspection : BotFrameworkHttpAdapter
    {
        public AdapterWithInspection(IConfiguration configuration, InspectionState inspectionState, UserState userState, ConversationState conversationState, ILogger<BotFrameworkHttpAdapter> logger)
            : base(configuration, logger)
        {
            // Inspection needs credentials because it will be sending the Activities and User and Conversation State to the emulator
            var credentials = new MicrosoftAppCredentials(configuration["MicrosoftAppId"], configuration["MicrosoftAppPassword"]);

//***********************************************************************************//
//*************** Adding HandOffMddieWare in the execution pipeline *****************//           
//***********************************************************************************//
            Use(new HandoffMiddleware(configuration));

            OnTurnError = async (turnContext, exception) =>
            {
                // Log any leaked exception from the application.
                logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}");

                // Send a message to the user
                await turnContext.SendActivityAsync("The bot encountered an error or bug.");
                await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code.");

                // Send a trace activity, which will be displayed in the Bot Framework Emulator
                await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError");
            };
        }
    }
}

            services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithInspection>();