如何在 Microsoft Bot Framework 中有多个选择对话框
How to have more than 1 multiple choice dialogs in Microsoft Bot Framework
我正在为 Facebook Messenger 在 Azure 机器人框架中构建一个简单的自动响应机器人。
到目前为止我有:
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("Welcome!");
context.Wait(MessageReceivedAsync);
}
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
var message = await argument;
if (message.Text.StartsWith("REPORT"))
PromptDialog.Choice(
context,
this.OnOptionSelected,
new List<string>() { "Good Driving", "Bad Driving"},
"Report Driver for?",
"Not a valid option", 3);
}
else
{
await context.PostAsync($"Thank you for messaging AutoConscience! We will get back to you shortly <br/> <br/>You can report drivers on the road by replying with REPORT followed by the license plate"
+"(REPORT ABC 123)");
context.Wait(MessageReceivedAsync);
}
}
public async Task OnOptionSelected(IDialogContext context, IAwaitable<string> argument)
{
var confirm = await argument;
if (confirm == "Good Driving")
{
//Having Trouble with the following
PromptDialog.Choice(context,
this.OnOptionSelected,
new List<string>() { "Used Signal", "Allowed Lane Merge", "Kept Intersection Open", "Followed Right of Way","Patient Driver","Defensive Driver","Nice Car"},
"Report Driver for?",
"Not a valid option", 3);
//await context.PostAsync("Good");
}
我想在第一个对话框之后显示另一个多选对话框,但在用户从第一个对话框中进行选择后,机器人失败了。提前致谢!
正如您在评论中提到的,要关闭对话框并将其从堆栈中删除(从而将用户发送回堆栈中的先前对话框),我们应该调用 context.Done()
。我们可以在 this article 中找到有关 Dialog 生命周期 的详细信息。
My problem now although not related to this is that on FB, the bot does not reply to other users than me.
在this article中,我们可以知道:一个应用在发布之前,都是处于开发模式。它仅适用于管理员、开发人员和测试人员。
我正在为 Facebook Messenger 在 Azure 机器人框架中构建一个简单的自动响应机器人。
到目前为止我有:
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("Welcome!");
context.Wait(MessageReceivedAsync);
}
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
var message = await argument;
if (message.Text.StartsWith("REPORT"))
PromptDialog.Choice(
context,
this.OnOptionSelected,
new List<string>() { "Good Driving", "Bad Driving"},
"Report Driver for?",
"Not a valid option", 3);
}
else
{
await context.PostAsync($"Thank you for messaging AutoConscience! We will get back to you shortly <br/> <br/>You can report drivers on the road by replying with REPORT followed by the license plate"
+"(REPORT ABC 123)");
context.Wait(MessageReceivedAsync);
}
}
public async Task OnOptionSelected(IDialogContext context, IAwaitable<string> argument)
{
var confirm = await argument;
if (confirm == "Good Driving")
{
//Having Trouble with the following
PromptDialog.Choice(context,
this.OnOptionSelected,
new List<string>() { "Used Signal", "Allowed Lane Merge", "Kept Intersection Open", "Followed Right of Way","Patient Driver","Defensive Driver","Nice Car"},
"Report Driver for?",
"Not a valid option", 3);
//await context.PostAsync("Good");
}
我想在第一个对话框之后显示另一个多选对话框,但在用户从第一个对话框中进行选择后,机器人失败了。提前致谢!
正如您在评论中提到的,要关闭对话框并将其从堆栈中删除(从而将用户发送回堆栈中的先前对话框),我们应该调用 context.Done()
。我们可以在 this article 中找到有关 Dialog 生命周期 的详细信息。
My problem now although not related to this is that on FB, the bot does not reply to other users than me.
在this article中,我们可以知道:一个应用在发布之前,都是处于开发模式。它仅适用于管理员、开发人员和测试人员。