问题陈述
这是关于Live中介-bot (c#)由tompaana在https://github.com/tompaana/intermediator-bot-sample上创建的。
社区支持
最初的作者Handoff中介人-bot Tomi Paananen A.K.已经转移到其他项目上,不再能够将时间花在这个项目上,并请求与members社区成员联系以获得支持(参考:作者对Github问题的答复)。
观察:
// 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);
}
}
}参考包
原始中介-bot-示例参考包

升级的中介-bot-示例参考包

原始中介-bot-示例解决方案文件

升级的中介-bot-示例解决方案文件

查询
你能建议我怎么解决这个问题吗?
E 184相关包E 285到E 186版本4.10.3<代码>E 287后,不会从 My Code触发。发布于 2020-10-04 10:51:54
以下解决方案使升级后的Tompanna代理Handoff解决方案工作平稳:
Github中的检验中间件示例提供了调用任何中间件的方法,即在有升级的Microsoft.Bot.Builder和相关包的情况下,引入了BotController类/BotController的概念。
AdapterWithInspection.cs在BotBuilder-样本/样本中的代码引用
将以下代码中的InspectionMiddleware替换为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");
};
}
}
}新代码应该如下所示
// 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");
};
}
}
}备注
在Startup.cs中注入依赖项
添加以下代码以方便AdapterWithInspection的依赖注入
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithInspection>();https://stackoverflow.com/questions/64151304
复制相似问题