我有一个使用Microsoft的.NET Bot框架的示例机器人。
我想为Facebook Messenger创建一个菜单。
我需要添加哪些文本以及如何捕获用户选择的选项?
这就是我现在所拥有的:
strReplyMessage.Append($"Hello, I am **TestBot** Bot");
strReplyMessage.Append($"\n");
strReplyMessage.Append($"You can say anything");
strReplyMessage.Append($"\n");
strReplyMessage.Append($"to me and I will repeat it back");
strReplyMessage.Append($"\n\n");
strReplyMessage.Append($"What is your name?");
有任何线索吗?
答案 0 :(得分:0)
Here您将找到有关如何使用PromptChoice的示例。
为方便起见,我粘贴了以下内容。
如何调用
PromptDialog.Choice(context, this.OnOptionSelected, new List<string>() { FlightsOption, HotelsOption }, "Are you looking for a flight or a hotel?", "Not a valid option", 3);
如何获取所选选项
private async Task OnOptionSelected(IDialogContext context, IAwaitable<string> result)
{
try
{
string optionSelected = await result;
switch (optionSelected)
{
case FlightsOption:
context.Call(new FlightsDialog(), this.ResumeAfterOptionDialog);
break;
case HotelsOption:
context.Call(new HotelsDialog(), this.ResumeAfterOptionDialog);
break;
}
}
catch (TooManyAttemptsException ex)
{
await context.PostAsync($"Ooops! Too many attemps :(. But don't worry, I'm handling that exception and you can try again!");
context.Wait(this.MessageReceivedAsync);
}
}
答案 1 :(得分:0)