在对话框中使用Bot状态访问器 [英] Using Bot State Accessors Inside Dialogs

查看:92
本文介绍了在对话框中使用Bot状态访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Bot Framework上工作了几天,真是太新了.我一直在试图了解对国家的管理,老实说,我只是不明白这一点.似乎关于此的框架和建议最近已经发生了很大变化,并且似乎没有任何明确的建议或示例.

I'm a few days in on the Bot Framework so very new. I've been trying to arrive at an understanding of managing the state and to be honest I'm just not getting it. It seems the framework and advice on this has changed a lot recently and there doesn't appear to be any clear advice or samples.

页面说:

将信息保存为机器人状态.这将需要您设计 您的对话框可以访问机器人的状态属性访问器.

Save the information to bot state. This would require you to design your dialog to have access to the bot's state property accessors.

但是没有实现此目的的示例.

But there are no examples of how to achieve this.

我的一个瀑布对话框的最后一步是这样的:

The last step in one of my Waterfall dialogs looks like this:

AddStep(async (stepContext, cancellationToken) =>
{
    var response = stepContext.Result as FoundChoice;
    stepContext.Values["maxPrice"] = response;

    return await stepContext.BeginDialogAsync(SearchDialog.Id, null, cancellationToken);
});

这基本上是一个新对话框的开始,我想通过将对象从该对话框中收集的数据传递到SearchDialog中,或者最好将其保存到我的BotAccessors中,然后检索SearchDialog并使用它.

It's basically kicking off a new dialog and I want to either pass the collected data from this dialog into the SearchDialog either by passing the object or, preferably, saving this into my BotAccessors and then the SearchDialog retrieving this and using it.

所有MS示例的瀑布步骤都定义为IBot类上的async方法.他们也不建议将bot对话框放在一起,从而使该示例变得毫无用处.

All MS examples have waterfall steps defined as async methods on the IBot class. Which also isn't how they recommend putting bot dialogs together making the example pretty useless all in all.

此外,似乎甚至Microsoft v4文档也已过时,例如

Also, it seems that even the Microsoft v4 docs are out of date, such as this doc, that is still telling us to use deprecated code, such as:

options.State.Add(new ConversationState(storage));

不幸的是,目前看来,文档比起对这个主题的帮助要混乱得多.管理此状态的最佳方法是什么?

Unfortunately it seems the docs are more confusing than helpful on this topic at the moment. What's the best way to manage this state?

推荐答案

注意:基本Bot示例已由Core Bot示例替换,因此此答案已过时

看看从Azure中的模板创建基本的bot .

状态属性访问器在

The state property accessor is declared in the BasicBot class:

private readonly IStatePropertyAccessor<GreetingState> _greetingStateAccessor;

然后将其分配给BasicBot 然后传递GreetingDialog构造函数:

Dialogs.Add(new GreetingDialog(_greetingStateAccessor, loggerFactory));

然后将其分配给

It is then assigned to a property of the GreetingDialog class:

UserProfileAccessor = userProfileStateAccessor ?? throw new ArgumentNullException(nameof(userProfileStateAccessor));

然后在GreetingDialog类中的许多地方使用

It is then used in many places throughout the GreetingDialog class with the GetAsync and SetAsync methods. For example:

var greetingState = await UserProfileAccessor.GetAsync(stepContext.Context, () => null);

这篇关于在对话框中使用Bot状态访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆