我有以下情况:通过网页中的网络聊天提供机器人。加载网页时,机器人会问候并立即显示用户可以选择的一些选项。这是在MessagesController中使用的代码:
[ResponseType(typeof(void))]
public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
if (activity.Type == ActivityTypes.Message || activity.Type == ActivityTypes.ConversationUpdate)
{
if (activity.Type == ActivityTypes.ConversationUpdate &&
!activity.MembersAdded.Any(r => r.Name == "Bot"))
return Request.CreateResponse(System.Net.HttpStatusCode.OK);
await Conversation.SendAsync(activity, () =>
new RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(System.Net.HttpStatusCode.OK);
return response;
}
并且是RootDialog类的一部分:
[Serializable]
public class RootDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
var message = context.MakeMessage();
var attachment = GetHeroCard();
message.Attachments.Add(attachment);
await context.PostAsync(message);
context.Wait(this.ShowFirstCategoryRefinement);
}
public virtual async Task ShowFirstCategoryRefinement(IDialogContext context, IAwaitable<IMessageActivity> activity)
{
var message = await activity;
IEnumerable<string> options = this.mainCategories;
PromptDialog.Choice(
context: context,
resume: ChoiceReceivedAsync,
options: options,
prompt: "Please select product category:",
retry: "Selected category not available. Please try again.",
promptStyle: PromptStyle.Auto
);
}
...
}
实际发生的是:用户打开页面,机器人问候并显示一些选项。当用户选择一个选项时,机器人再次问候并显示相同的选项。如果用户再次选择一个选项,则对话框会正常继续。
如何解决这个问题?感谢。