Bot无法处理Http请求

时间:2020-05-20 12:56:42

标签: c# api http asp.net-core botframework

我已经使用Microsoft Bot Framework创建了Bot,并希望它处理http请求。

根据此docs,我创建了控制器,清除了Get方法主体(只保留了调用方ContentResult的返回-我至少要处理该请求),部署了bot,但仍然收到500 Internal Server Error

Bot在典型的Bot频道(我正在使用团队)中正常工作。

这是控制器:

[Route("api/notify")]
[ApiController]
public class NotifyController : ControllerBase
{
    private readonly IBotFrameworkHttpAdapter _adapter;
    private readonly string _appId;
    private readonly ConcurrentDictionary<string, ConversationReference> _conversationReferences;

    public NotifyController(IBotFrameworkHttpAdapter adapter, IConfiguration configuration, ConcurrentDictionary<string, ConversationReference> conversationReferences)
    {
        _adapter = adapter;
        _appId = configuration["MicrosoftAppID"];

    }

    public async Task<IActionResult> Get()
    {
        return new ContentResult()
        {
            Content = "<html><body><h1>Request has been processed.</h1></body></html>",
            ContentType = "text/html",
            StatusCode = (int)HttpStatusCode.OK,
        };
    }
}

也许我必须配置其他内容,以便控制器可以正常工作?

1 个答案:

答案 0 :(得分:1)

基于该错误,看来您缺少某些依赖项注入。请将此行添加到您的Startup.cs> ConfigureServices()中,使其与Proactive Sample相匹配:

services.AddSingleton<ConcurrentDictionary<string, ConversationReference>>();

注意:如果这是一个新的漫游器,则最简单的方法是从此示例开始,然后从那里开始构建。