简体   繁体   English

在虚拟助手模板 Botframework 中拦截传出活动

[英]Intercepting outgoing activities in Virtual Assistant Template Botframework

I'm looking for a place inside a Microsoft Bot code (created with the Virtual Assistant Template 4.9.1.1) where I can be able to intercept any outgoing activity just before it is sent from the bot to the client.我正在寻找 Microsoft Bot 代码(使用虚拟助手模板 4.9.1.1 创建)中的一个位置,在那里我可以在任何传出活动从机器人发送到客户端之前拦截它。

As I understood one solution could be to override these two methods in DefaultAdapter:据我了解,一种解决方案可能是在 DefaultAdapter 中覆盖这两种方法:

bool CanProcessOutgoingActivity(Activity activity)

Task<ResourceResponse> ProcessOutgoingActivityAsync(ITurnContext turnContext, Activity activity, CancellationToken cancellationToken)

Since I just have to do some changes to the activity, I thought I could do it directly in the CanProcessOutgoingActivity.由于我只需要对活动进行一些更改,因此我认为可以直接在 CanProcessOutgoingActivity 中进行。 But I was wrong since I also need some info from the context.但我错了,因为我还需要上下文中的一些信息。

So I had CanProcessOutgoingActivity() just returning true and move the logic in ProcessOutgoingActivityAsync, where all the info are available.所以我让 CanProcessOutgoingActivity() 只返回 true 并在 ProcessOutgoingActivityAsync 中移动逻辑,所有信息都可用。

However I don't understand how it is supposed to work and what the method should return in the ResourceResponse parameter.但是我不明白它应该如何工作以及该方法应该在 ResourceResponse 参数中返回什么。

Is there any example or documentation from which I can understand how does it works?是否有任何示例或文档可以让我了解它是如何工作的?

Middleware would be the recommended and most straightforward (not to mention modular) approach. 中间件将是推荐和最直接(更不用说模块化)的方法。 It is designed for this type of scenario and should accomplish what you need.它是为这种类型的场景设计的,应该可以满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM