github上tompaana的Agent Handoff intermediator-bot-sample(C#)无法将Microsoft.Bot.Builder和相关软件包升级到Ver 4.10.3 [英] Agent Handoff intermediator-bot-sample (c#) by tompaana on github doesn't work on upgrading Microsoft.Bot.Builder and related packages to Ver 4.10.3

查看:96
本文介绍了github上tompaana的Agent Handoff intermediator-bot-sample(C#)无法将Microsoft.Bot.Builder和相关软件包升级到Ver 4.10.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题陈述

这与tompaana在

升级的intermediator-bot-sample参考包

原始的intermediator-bot-sample解决方案文件

升级的intermediator-bot-sample解决方案文件

查询

能否请您提出我该如何解决此问题的建议?

    当我执行原始代码_ 时,
  • 作为 HandoffMiddleware.OnTurnAsync(..)正常工作,但是 <使用升级的Microsoft.Bot.Builder 相关程序包改装为版本4.10.3 .

  • 指向现有的有效Agent HandOff示例(c#)也将有所帮助

解决方案

以下解决方案使升级的Tompanna Agent Handoff解决方案能够顺利运行:

  • 该解决方案在于BotFrameworkHttpAdapter需要调用HandoffMiddleware的方式.

检查中间件示例Github提供了一种方法来调用任何中间件,例如,在那些具有升级的Microsoft.Bot.Builder和相关软件包的场景中,这些软件包引入了BotController类/API Controller的概念.

AdapterWithInspection.cs的代码参考,来自

新代码应如下所示

 //版权所有(c)Microsoft Corporation.版权所有.//根据MIT许可获得许可.命名空间Microsoft.BotBuilderSamples{公共类AdapterWithInspection:BotFrameworkHttpAdapter{public AdapterWithInspection(IConfiguration配置,InspectionState检查状态,UserState用户状态,ConversationState对话状态,ILogger< BotFrameworkHttpAdapter>记录器):基础(配置,记录器){//检查需要凭据,因为它将把活动,用户和对话状态发送给模拟器var凭证=新的MicrosoftAppCredentials(configuration ["MicrosoftAppId"],configuration ["MicrosoftAppPassword"]);//**********************************************************************************************////***************在执行管道中添加HandOffMddieWare ******************////**********************************************************************************************//使用(新的HandoffMiddleware(配置));OnTurnError =异步(turnContext,异常)=>{//从应用程序记录任何泄漏的异常.logger.LogError(exception,$"[[OnTurnError]未处理的错误:{exception.Message}'");//向用户发送消息等待turnContext.SendActivityAsync(机器人遇到错误或错误.");等待turnContext.SendActivityAsync(要继续运行该机器人,请修复该机器人源代码.");//发送跟踪活动,该活动将显示在Bot Framework仿真器中等待turnContext.TraceActivityAsync("OnTurnError Trace",exception.Message,"https://www.botframework.com/schemas/error","TurnError");};}}} 

注意

  • 您需要相应地在Startup.cs中注入依赖项

在Startup.cs中注入依赖项

添加以下代码以方便对AdapterWithInspection进行依赖注入

  services.AddSingleton< IBotFrameworkHttpAdapter,AdapterWithInspection>(); 

Problem Statement

This is regarding the Live Agent Handoff intermediator-bot-sample (c#) created by tompaana at https://github.com/tompaana/intermediator-bot-sample on guithub.

  • The intermediator-bot-sample works perfectly with Microsoft.Bot.Builder (4.2.2) and Microsoft.Bot.Builder.Integration.AspNet.Core(4.2.2) and dependent Version 4.2.2 packages but, It does not use Dialogs.

  • The HandoffMiddleware Code stopped getting invoked , when I added the package Microsoft.Bot.Builder.Dialogs (4.10.3) (as my existing code requires Dialogs) . This also caused upgrading to Microsoft.Bot.Builder to version 4.10.3 along with it's dependent packages i.e. Microsoft.Bot.Builder.Integration.AspNet.Core etc..

Community Support

The Original Author Handoff intermediator-bot-sample Tomi Paananen A.K.A tompaana has moved on to other projects and would no longer be able to devote time to this project and has requested to reach out MS Botframework community members for support (Refer: Author Response to Github issue raised).

  • Requesting BotFramework community to please help out to add Agent Hand Off functionality to my existing Chatbot

Observation :

  • Even After Package upgrade, the HandoffMiddleware class is getting successfully instantiated during Startup.

  • My retrofitted code contains BotController class via which all the API get invoked. This BotController class which isn't present in the original Handoff intermediator-bot-sample code.

  • On typing any utterance on the chat bot (Upgraded/new code), the control goes into the BotController class rather than invoking/triggering HandoffMiddleware.OnTurnAsync(...)

  • As the original intermediator-bot-sample code does not have any BotController/ API Controller, could this be the reason that utterances aren't getting routed via, HandoffMiddleware Middleware if so, how could I fix the issue?

// 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);
        }
    }
}

Referenced Packages

Original intermediator-bot-sample referenced Packages

Upgraded intermediator-bot-sample referenced Packages

Original intermediator-bot-sample Solution Files

Upgraded intermediator-bot-sample Solution Files

Query

Could you please suggest How I can fix this issue?

  • As the HandoffMiddleware.OnTurnAsync(..) works fine when I execute the coriginal code_ but, doesn't get triggered from My Code after retrofitting IntermediateBot code with upgraded Microsoft.Bot.Builder and related packages to Version 4.10.3 .

  • Pointing to an existing working Agent HandOff sample(c#) would also help

解决方案

The following solution makes the upgraded Tompanna Agent Handoff solution work smoothly:

  • The solution lies in the way BotFrameworkHttpAdapter needs to invoke HandoffMiddleware.

The inspection Middleware example in Github provides the methodology to invoke any middleware i.e. in those scenarios where we have the upgraded Microsoft.Bot.Builder and related packages which introduce the concept of BotController class / API Controller .

Code reference of AdapterWithInspection.cs from BotBuilder-Samples/samples

Replace InspectionMiddleware in the following code with HandoffMiddleware


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");
            };
        }
    }
}

New code should look like the following

// 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");
            };
        }
    }
}

NOTE

  • You would need to inject dependencies in the Startup.cs accordingly

Inject Dependencies in Startup.cs

Add following code to facilitate dependency injection of AdapterWithInspection

            services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithInspection>();

这篇关于github上tompaana的Agent Handoff intermediator-bot-sample(C#)无法将Microsoft.Bot.Builder和相关软件包升级到Ver 4.10.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆