我使用Microsoft Bot Framework创建了Bot,希望它能处理http请求。
根据这个 文件 我已经创建了控制器,清除了Get方法主体(只给调用者留下了ContentResult的返回--我想至少处理这个请求),部署了机器人,但一直得到500内部服务器错误。
Bot在典型的Bot频道中正常工作(我使用Teams)。
这里是控制器。
[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,
};
}
}
也许我必须配置一些其他的东西,这样控制器才能正常工作?
根据这个错误,看起来你缺少了一些依赖注入。请将这行添加到你的 Startup.cs
> ConfigureServices()
以使其与 积极主动的样品:
services.AddSingleton<ConcurrentDictionary<string, ConversationReference>>();
注:如果这是一个新的机器人,可能最容易从这个样本开始,然后再从那里建立。