BotFramework 状态未保存
BotFramework State not saving
我的机器人状态有问题。我几乎遵循他们所说的保存用户状态的方式 here。我唯一的变化是我正在使用 Visual Studio 中的对话机器人。当我在我的主对话框中执行最后一步时,我将几个属性设置为我的用户配置文件对象中的值,然后我调用 SaveChangesAsync
然后返回处理下一个请求。
当我收到下一个请求时。我调用 userStateAccessors.GetAsync
获取最新版本只是为了保持新鲜。但我注意到我的更改没有保存。
有没有其他人遇到过这个问题。我的雇主希望聊天机器人保留每个用户的状态,这样他们就不必在每个请求中输入所有信息。
2011 年 5 月 11 日
这是我 DialogBot.cs
的代码部分
public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default)
{
await base.OnTurnAsync(turnContext, cancellationToken);
// Save any state changes that might have occured during the turn.
await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
}
也来自我的 MainDialog.cs 文件
private async Task<DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext,
CancellationToken cancellationToken)
{
var conversationStateAccessors =
_conversationState.CreateProperty<ConversationData>(nameof(ConversationData));
_conversationData =
await conversationStateAccessors.GetAsync(stepContext.Context, () => new ConversationData());
var userStateAccessors = _userState.CreateProperty<UserProfile.UserProfile>(nameof(UserProfile));
_userProfile = await userStateAccessors.GetAsync(stepContext.Context, () => new UserProfile.UserProfile());
//More code is here
}
此外,如果我们注释掉 make 以便我们仅在 _userProfile 为 null 时获取它,那么我们 运行 就会遇到其他用户查看数据的问题。不确定这是否相关。
我所做的是获取用户配置文件并使其在每个回合都本地化。此外,我们所做的是让它在数据库中使用永久存储,这样即使我们重置聊天机器人也可以存储数据
我的机器人状态有问题。我几乎遵循他们所说的保存用户状态的方式 here。我唯一的变化是我正在使用 Visual Studio 中的对话机器人。当我在我的主对话框中执行最后一步时,我将几个属性设置为我的用户配置文件对象中的值,然后我调用 SaveChangesAsync
然后返回处理下一个请求。
当我收到下一个请求时。我调用 userStateAccessors.GetAsync
获取最新版本只是为了保持新鲜。但我注意到我的更改没有保存。
有没有其他人遇到过这个问题。我的雇主希望聊天机器人保留每个用户的状态,这样他们就不必在每个请求中输入所有信息。
2011 年 5 月 11 日 这是我 DialogBot.cs
的代码部分public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default)
{
await base.OnTurnAsync(turnContext, cancellationToken);
// Save any state changes that might have occured during the turn.
await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
}
也来自我的 MainDialog.cs 文件
private async Task<DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext,
CancellationToken cancellationToken)
{
var conversationStateAccessors =
_conversationState.CreateProperty<ConversationData>(nameof(ConversationData));
_conversationData =
await conversationStateAccessors.GetAsync(stepContext.Context, () => new ConversationData());
var userStateAccessors = _userState.CreateProperty<UserProfile.UserProfile>(nameof(UserProfile));
_userProfile = await userStateAccessors.GetAsync(stepContext.Context, () => new UserProfile.UserProfile());
//More code is here
}
此外,如果我们注释掉 make 以便我们仅在 _userProfile 为 null 时获取它,那么我们 运行 就会遇到其他用户查看数据的问题。不确定这是否相关。
我所做的是获取用户配置文件并使其在每个回合都本地化。此外,我们所做的是让它在数据库中使用永久存储,这样即使我们重置聊天机器人也可以存储数据