我们正试图挽救一个简单的序列化对象PrivateConversationData的Dialog,并从国家访问中MessagesController出于某种原因,在我们Context.Done在对话框中执行之后,我们没有取回存储在状态中的数据 public static async Task SetUserAsync<T>(IActivity activity, T botUser) where T : IBotUser { if (botUser != null) { using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity.AsMessageActivity())) { var botDataStore = scope.Resolve<IBotDataStore<BotData>>(); var key = new AddressKey() { BotId = activity.Recipient.Id, ChannelId = activity.ChannelId, UserId = activity.From.Id, ConversationId = activity.Conversation.Id, ServiceUrl = activity.ServiceUrl }; var privateData = await botDataStore.LoadAsync(key, BotStoreType.BotPrivateConversationData, CancellationToken.None); privateData.SetProperty<T>(Keys.CacheBotUserKey, botUser); await botDataStore.SaveAsync(key, BotStoreType.BotPrivateConversationData, privateData, CancellationToken.None); await botDataStore.FlushAsync(key, CancellationToken.None); } } }对话框代码很简单 public override async Task ProcessMessageAsync(IDialogContext context, IAwaitable<IMessageActivity> result) { BotUser user = new BotUser { UserId = "user1" }; await StateHelper.SetUserAsync(context.Activity, user); var userFromState = await StateHelper.GetUserAsync<BotUser>(context.Activity); Debug.WriteLine("Within dialog (after set) >" + userFromState?.UserId); context.Done<object>(null); }在这种情况下,我们得到以下输出Within dialog (after set) > user1 Within MC (end) >有什么问题吗?
1 回答
手掌心
TA贡献1942条经验 获得超3个赞
当对话框加载时,状态会随之加载,并且可以使用 Context 对象上的方法访问/保存。当对话完成时,状态由 SDK 持久化。如果您创建一个嵌套在对话框中的新范围,并尝试加载/保持状态:那么对话框状态将覆盖它。要解决此问题,您可以在 StateHelper 中添加一个接受IDialogContext 的方法,并在 Dialog 中使用该方法。
- 1 回答
- 0 关注
- 173 浏览
添加回答
举报
0/150
提交
取消