Botframework TextPrompt在中断后重新启动 TL;博士
当我的机器人在提示中等待时(例如TextPrompt),另一个对话框结束(因为用户输入触发了一个中断操作,例如“help”,它启动了一个只输出帮助文本的帮助对话框),将调用该提示的Botframework TextPrompt在中断后重新启动 TL;博士,botframework,Botframework,当我的机器人在提示中等待时(例如TextPrompt),另一个对话框结束(因为用户输入触发了一个中断操作,例如“help”,它启动了一个只输出帮助文本的帮助对话框),将调用该提示的OnPromptAsync方法并再次提示提示文本。我不要这个。我希望提示对话框在帮助对话框结束后等待用户输入 详细的 我有一个机器人,它使用TextPrompt提示某些内容,然后等待用户回复。我已经实现了如上所述的用户中断来捕获帮助请求。如果用户输入“帮助”,机器人应该输出一些帮助文本(在ExampleDialog中,
OnPromptAsync
方法并再次提示提示文本。我不要这个。我希望提示对话框在帮助对话框结束后等待用户输入
详细的
我有一个机器人,它使用TextPrompt提示某些内容,然后等待用户回复。我已经实现了如上所述的用户中断来捕获帮助请求。如果用户输入“帮助”,机器人应该输出一些帮助文本(在ExampleDialog中,见下文),然后再次等待用户输入
主对话框
公共类MainDialog:ComponentDialog
{
公共主对话框():基本(“主”)
{
AddDialog(新建文本提示(名称)(文本提示));
AddDialog(新建示例Dialog(名称)(示例Dialog));
AddDialog(新建WaterWallDialog)(名称(WaterWallDialog),新建WaterWallStep[]
{
迅速,
评估步骤
}));
InitialDialogId=nameof(WaterWallDialog);
}
受保护的覆盖异步任务OnContinueDialogAsync(DialogContext innerDc,CancellationToken CancellationToken=default)
{
如果(!string.IsNullOrEmpty(innerDc.Context.Activity.Text))
{
//检查是否有中断
var结果=等待中断异步(innerDc,cancellationToken);
如果(结果!=null)
{
返回结果;
}
}
返回wait base.OnContinueDialogAsync(innerDc,cancellationToken);
}
专用异步任务中断异步(DialogContext innerDc,CancellationToken CancellationToken)
{
if(innerDc.Context.Activity.Type==ActivityTypes.Message)
{
字符串文本=innerDc.Context.Activity.text;
//捕获请求帮助
如果(文本==“帮助”)
{
等待innerDc.BeginDialogAsync(nameof(exampledilog),null,cancellationToken);
return Dialog.EndOfTurn;
}
}
返回null;
}
专用异步任务PromptStep(WaterWallStepContext stepContext,CancellationToken CancellationToken)
{
return wait-stepContext.PromptAsync(nameof(TextPrompt),new-PromptOptions()
{
Prompt=MessageFactory.Text(“请输入一些文本。如果需要一些示例,请键入“help”。),
});
}
专用异步任务评估步骤(WaterWallStepContext stepContext,CancellationToken CancellationToken)
{
等待stepContext.Context.SendActivityAsync(MessageFactory.Text(“您键入的:“+stepContext.Result为字符串”);
返回Wait-stepContext.EndDialogAsync(null,cancellationToken);
}
}
示例对话框
公共类ExampleDialog:ComponentDialog
{
public ExampleDialog(字符串dialogId):基本(dialogId)
{
AddDialog(新建WaterWallDialog)(名称(WaterWallDialog),新建WaterWallStep[]
{
示例步骤
}));
InitialDialogId=nameof(WaterWallDialog);
}
专用异步任务示例步骤(WaterWallStepContext stepContext,CancellationToken CancellationToken)
{
wait stepContext.Context.SendActivityAsync(MessageFactory.Text(“示例:bla-bla”));
返回Wait-stepContext.NextAsync(null,cancellationToken);
//示例对话框到此结束
}
}
问题是,当ExampleDialog在输出帮助文本后结束时,TextPrompt将继续并再次提示其消息。这将导致以下对话:
Bot: Hello world!
Bot: Please enter some text. Type ‘help’ if you need some examples.
User: help
Bot: Example: bla bla
Bot: Please enter some text. Type ‘help’ if you need some examples.
Bot: Hello world!
Bot: Please enter some text. Type ‘help’ if you need some examples.
User: help
Bot: Example: bla bla
/* bot now waits at this point of the conversation */
User: bla bla
Bot: You typed: bla bla
我不想最后一行被机器人重复。我怎样才能解决这个问题
提前谢谢
编辑1:A(并非真正令人满意的)解决方案
我找到了一个并不真正令我满意的解决办法。我创建了自己的TextPrompt类MyTextPrompt,并覆盖了ResumeDialogAsync:
公共类MyTextPrompt:TextPrompt
{
公共MyTextPrompt(字符串id):基(id)
{
}
公共覆盖异步任务ResumeDialogAsync(DialogContext dc,DialogReason reason,对象结果=null,CancellationToken CancellationToken=default)
{
return Dialog.EndOfTurn;
}
}
在MainDialog中,我只是在构造函数中将TextPrompt替换为MyTextPrompt
AddDialog(新建MyTextPrompt(名称)(MyTextPrompt));
并在提示步骤中使用正确的对话框id
专用异步任务PromptStep(WaterWallStepContext stepContext,CancellationToken CancellationToken)
{
return wait-stepContext.PromptAsync(nameof(MyTextPrompt),new-PromptOptions()
{
Prompt=MessageFactory.Text(“请输入一些文本。如果需要一些示例,请键入“help”。),
});
}
结果是这样的对话:
Bot: Hello world!
Bot: Please enter some text. Type ‘help’ if you need some examples.
User: help
Bot: Example: bla bla
Bot: Please enter some text. Type ‘help’ if you need some examples.
Bot: Hello world!
Bot: Please enter some text. Type ‘help’ if you need some examples.
User: help
Bot: Example: bla bla
/* bot now waits at this point of the conversation */
User: bla bla
Bot: You typed: bla bla
好的,太好了。这就是我想要的,不是吗
是的,但也有一些缺点:
如何以一种优雅的方式解决这个问题?我可以想出三种主要的方法,在恢复时提示不要重复 1.取消提示 在恢复内置提示时,真正阻止其重新执行的唯一方法是将
Prompt
属性设置为null。我在评论中提到