使用bot框架模拟器v.3.5.36,如果用户发送长文本(大约1K个字符),模拟器会自动将对话框堆栈重置为root对话框,而不会出现任何错误或警告。 (见下面的截图。)
bot框架是否有声明的消息限制?
有没有办法让机器人处理这种情况并警告用户而不是这种无声的东西?
根本没有关于代码的具体内容:
[LuisModel("{GUID}", "{CODE}", LuisApiVersion.V2, domain: "westeurope.api.cognitive.microsoft.com", threshold: 0.5)]
[Serializable]
public class LuisSearchDialog2 : LuisDialog<object>
{
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisResult result)
{
await context.PostAsync(JsonConvert.SerializeObject(result));
context.Wait(this.MessageReceived);
}
}
答案 0 :(得分:1)
一种简单的方法是在 MessageController 中检查邮件的长度,并决定是否要处理它。
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl);
var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
if (activity.Text != null && activity.Text.Length > 200)
{
var errorReply = activity.CreateReply();
errorReply.Text = "Well well, that is too much of data. How about keeping it simple? How can I help you?";
await connector.Conversations.ReplyToActivityAsync(errorReply);
}
else
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
}
}
答案 1 :(得分:1)
原因是base LuisDialog没有处理失败的API请求(如果查询太长,则返回414代码)。因此,处理此类错误的最简单方法是重写MessageReceived,如下所示:
[Serializable]
public class LuisSearchDialog2 : LuisDialog<object>
{
protected override async Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> activity)
{
try
{
await base.MessageReceived(context, activity);
}
catch(HttpRequestException e)
{
// Handle error here
//await context.PostAsync("Error: " + e.ToString());
context.Wait(this.MessageReceived);
}
}
}