Bot framework v4中OnturnAsync中如何响应task/fetch

How to respond to task/fetch in OnturnAsync in Bot framework v4

我正在使用 Bot framewokV4,我想 return 自适应卡到 Teams 中的任务模块。

我正在使用提交值为 "data":{"msteams":{"type":"task/fetch"}}" 的自适应卡片用于任务模块弹出窗口。

如何return基本适配卡转任务模块 public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 方法。

我可以 return 使用 protected override async Task<TaskModuleResponse> OnTeamsTaskModuleFetchAsync(ITurnContext<IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken) 方法

但是当我使用 OnturnAsync 方法时没有触发此方法。

请帮忙, 谢谢

你应该再看看 How bots work, especially "The activity processing stack" and "Bot logic" sections. Basically, there's a sequence of how the event handlers work - OnTurnAsync will get called FIRST in this chain. If you fully handle the event inside your own OnTurnAsync, then the chain will stop processing there. In this particular case, the base OnTurnAsync isn't getting called, and this is the one that -would- have called OnTeamsTaskModuleFetchAsync. Have a look at the source code for the TeamsActivityHandler's OnTurnAsync,在你的情况下显然没有被调用。

基本上,您应该:

1) 如果您不需要自己的 OR,请不要使用自己的 OnTurnAsync 2) 如果你确实需要实现你的 OnTurnAsync(比如你在里面做一些事情)那么一定要从你自己的 OnTurnAsync 内部调用 base.OnTurnAsync 来处理你自己无法处理的任何情况。

当然,所有这些都假设您正确继承了 TeamsActivityHandler,而不仅仅是 ActivityHandler,否则所有与 Teams 相关的内容都不会加载。