出错了,请从BotFramework MessagingExtesion再试一次。

问题描述 投票:0回答:1

我一直在努力为MS Teams实现一个连接到我们应用程序的机器人,使用BotFramework v4和C#(Web API库)。 我已经在 azure 中注册了机器人,并成功地使机器人的聊天部分正常工作。

然而,当我从消息扩展中搜索项目时,我得到了上述错误,即 Something went wrong. Please try again. 我查看了代码,从服务器端代码来看,我似乎返回了正确的响应,但是当我从Teams Web客户端检查请求时,响应是空的。

enter image description here

enter image description here

从Bot端代码来看,我实现了以下功能

protected override async Task<MessagingExtensionResponse> OnTeamsMessagingExtensionQueryAsync(ITurnContext<IInvokeActivity> turnContext, MessagingExtensionQuery query, CancellationToken cancellationToken)
{
     var text = query?.Parameters?[0]?.Value as string ?? string.Empty;
     if (text == "true" && query?.Parameters?[0]?.Name == "initialRun")
          return new MessagingExtensionResponse { ComposeExtension = new MessagingExtensionResult { Type = "message", Text = "Please enter your search term above" } };
     else 
          return new MessagingExtensionResponse { ComposeExtension = new MessagingExtensionResult { Type = "message", Text = "Not the initial run" } };
}

和主计长

public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
{
     _adapter = adapter;
     _bot = bot;
}

public async Task Messages()
{
     await _adapter.ProcessAsync(ActionContext.Request, ActionContext.Request.CreateResponse(), _bot);
}

有谁能给我指出正确的方向,告诉我哪里做错了?

c# botframework microsoft-teams
1个回答
0
投票

对于任何其他遇到同样问题的人,如果您正在从ASP.NET WebApi处理BotFramework,您需要确保您从消息端点正确返回响应。

即控制器中的以下例程。

public async Task Messages()
{
     await _adapter.ProcessAsync(ActionContext.Request, ActionContext.Request.CreateResponse(), _bot);
}

要变成

public async Task<HttpResponseMessage> Messages()
{
     var response = new HttpResponseMessage();
     await _adapter.ProcessAsync(ActionContext.Request, response, _bot);
     return response;
}
© www.soinside.com 2019 - 2024. All rights reserved.