我使用 Microsoft 的 Bot Framework 创建了一个名为 picturesaver 的机器人,添加了一个 GroupMe channel ,并将其托管在 Azure 中。该机器人运行完美,将图片保存到 Google 云端硬盘。
但是,机器人给出错误“服务错误:POST to picturesaver timed out after 15s” 是否可以延长超时时间?或者甚至阻止机器人发布任何内容。这可能是 Azure 问题还是 GroupMe 问题?
最佳答案
如果您的机器人执行的操作需要超过 15 秒来处理消息,您可以在另一个线程上处理该消息,并立即确认调用。像这样的东西:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
if ([determine if this will take > 15s])
{
// process the message asyncronously
Task.Factory.StartNew(async () => await Conversation.SendAsync(activity, () => new Dialogs.RootDialog()));
}
else
{
//process the message normally
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
}
return Request.CreateResponse(HttpStatusCode.OK); //ack the call
}
这将避免连接器和机器人之间出现 15 秒超时。
<小时/>编辑:上面的内容不会扩展,并且只是使用 Task.Factory。请引用https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-long-operations-guidance有关处理机器人长时间操作的建议指南。
关于c# - Bot 框架发送不必要的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47910640/