c# - 具有复杂对话流的顺序瀑布模型 Bot Framework C# v4
问题描述
我有 3 个独立的瀑布模型,它们由使用 Luis 的意图触发。我想按顺序链接这 3 个模型,我一直遵循PictureBot编码风格,每个对话框/瀑布都有它的状态属性。
3种瀑布方法如下,
- WaterFall_1 - 根据用户提供的过滤器查询 Azure 搜索,响应是名称列表
- WaterFall_2 - 将执行一些 REST 动作,取名 waterFall_1
- WaterFall_3 - 将再次执行一些 REST 操作,取名 WaterFall_1
到目前为止,我一直在通过聊天窗口传递值,因为 3 个瀑布步骤松散耦合,用户可以将它们作为机器人的独立组件/功能调用,所以我的问题是
如何链接 3 个模型,即如果用户触发了瀑布_1,并转到 2 或 3,则询问“用户”的对话框将被跳过?我在想每个瀑布都需要一个全局和本地获取器和设置器。
在 WaterFall_1 中,最后一个响应发送来自 Azure 搜索的查询结果,即“名称”,我应该立即 endDialog 还是 WaterFall_1 调用 WaterFall_2 和/如果 WaterFall_3 然后我为 3、2、1 结束对话框?
该图可能会提供更多上下文简单图
解决方案
You have the general idea down, in your question 1. What you would need is a 'shared' or global state not unlike the state demonstrated in the Bot Framework's CafeBot (Look under samples => dotnet => #50).
If you have a 'global' state set, you could save the list of user names retrieved in your Waterfall 1 to that. Then, when your second or third waterfall are called via your LUIS intents, you pass in the state accessor to the Waterfall 1 results to the parent class of Waterfall 2, thus making them accessible to the other waterfalls.
You would not need to make them sequential, if you're relying on LUIS. You could use LUIS to have 'Search Users' trigger WF1, 'Do XYZ to Users' trigger 2, and 'Do ABC to Users' trigger 3. This would make your bot less rigid for your bot users, as they could do a search, then do either 2 OR 3, (or both) as needed.
I was able to simulate this by simply adding an extra, waterfall based class to the Bot Framework MessageRoutingBot (samples => dotnet => #09)
Here is the waterfall setup for the 'Favorite Animal' prompt, including accessing the greetingState from the original sample bot:
public TestDialog(IStatePropertyAccessor<TestState> testStateAccessor, IStatePropertyAccessor<GreetingState> greetingStateAccessor, ILoggerFactory loggerFactory)
: base(nameof(TestDialog))
{
TestStateAccessor = testStateAccessor ?? throw new ArgumentNullException(nameof(testStateAccessor));
GreetingStateAccessor = greetingStateAccessor ?? throw new ArgumentNullException(nameof(greetingStateAccessor));
// Add control flow dialogs
var waterfallSteps = new WaterfallStep[]
{
InitializeStateStepAsync,
PromptForAnimalStepAsync,
// PromptForCityStepAsync,
DisplayTestStateStepAsync,
};
AddDialog(new WaterfallDialog(ProfileDialog, waterfallSteps));
// AddDialog(new TextPrompt(NamePrompt, ValidateName));
AddDialog(new TextPrompt(AnimalPrompt));
}
With the greetingState accessor pulled in, it allowed me to continue to call my user by name, from a second waterfall, without needing to reprompt for it:
private async Task<DialogTurnResult> GreetUser(WaterfallStepContext stepContext)
{
var context = stepContext.Context;
var testState = await TestStateAccessor.GetAsync(context);
var greetingState = await GreetingStateAccessor.GetAsync(context);
// Display their profile information and end dialog.
await context.SendActivityAsync($"Hi {greetingState.Name}, who likes {testState.Animal}s, nice to meet you!");
return await stepContext.EndDialogAsync();
}
Hope this helps!
推荐阅读
- reporting-services - SSRS 表展示了没有表达式集的条件可见性
- java - 如何解决gradle上传jar到nexus的maven仓库时POM文件无效的问题?
- javascript - 无法在谷歌地图上叠加图像
- python - A2C 稳定基线中熵系数的线性时间表
- android - 工作管理器中的 Dispatchers.Main 会阻塞用户主线程吗?
- python-3.x - 是他们的 SDK 库在 python 中创建 Github Bot
- python - 是否可以将matlab fitnet神经网络转换为keras
- mysql - 优化 mySQL 查询以更好地扩展
- aws-glue - Athena 没有看到新的每日分区文件夹
- image - 在没有 ui 的情况下在 Flutter 中裁剪和保存图像