Bot Framework发送OPTIONS消息

时间:2018-09-27 17:10:44

标签: botframework bots azure-bot-service

最近,我从bot框架中收到了405条与正在发送的“ OPTIONS”消息有关的响应消息。

我的服务应如何应对这些问题?

谁在发出这些请求?

1 个答案:

答案 0 :(得分:2)

对不起,如果您看到我以前的回答;它完全不合时宜,所以我丢脸了。

您提到的请求是由Azure在导航到WebChat或“设置”选项卡时发出的。要允许通话,您可以创建一个自定义的bot auth类:

 public class CustomBotAuthenticationAttribute : BotAuthentication
    {
        public override Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
        {
            if (actionContext.Request.Method.Method == "OPTIONS") // allow OPTIONS through, and do not authenticate
                return Task.CompletedTask;

            return base.OnActionExecutingAsync(actionContext, cancellationToken);
        }
    }

然后,在MessagesController中:

[CustomBotAuthentication] // Change from [BotAuthentication]
public class MessagesController : ApiController
{

    public HttpResponseMessage Options() // handle options
    {
        return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
    }

    public async Task<HttpResponseMessage> Post([FromBody]Activity activity)