c# - 如何在不使用 TurnContext 对象的情况下管理和存储 TurnState
问题描述
在以下代码中,需要 TurnContext 对象从 Cosmos 获取底层 Bot State 并将其保存回来 -
//Get the TurnContext from the Dictionary
TurnContextReferences.TryGetValue(sessionStateChangedEventData.SessionId, out ITurnContext turnContext);
if (turnContext != null)
{
var conversationData = await BotStateAccessors
.ConversationStateAccessor
.GetAsync(turnContext, () => new ConversationStateDataModel());
if (!conversationData.LiveAgentChatClosed)
{
conversationData.LiveAgentChatClosed = true;
await BotStateAccessors.ConversationStateAccessor.SetAsync(turnContext, conversationData);
await BotConversationState.SaveChangesAsync(turnContext);
}
}
有没有可能在不直接使用 TurnContext 的情况下实现相同的方法?
解决方案
访问机器人状态和向用户发送消息所需的所有信息都在对话参考中。ContinueConversationAsync
您可以使用该方法从保存的对话参考中构建一个回合上下文。您可以在主动消息示例中查看如何执行此操作:
await ((BotAdapter)_adapter).ContinueConversationAsync(_appId, conversationReference, BotCallback, default(CancellationToken));
转弯上下文并不意味着存在于其关联转弯之外。您应该保存对话参考而不是转向上下文。
推荐阅读
- ios - Xcode 10 Splash Screen Resizable Logo Image
- angular - Angular 中的组件树与视图层次结构
- amazon-web-services - 如何从 terraform 重新开始?
- python - Python 3.7.1 将所有文件从单一来源复制到从 .xlsx 创建的文件夹列表中
- python - 在scipy中对两个稀疏矩阵进行张量积后如何消除零点?
- python - 如何根据两列的差异向数据框添加行
- javascript - 有没有办法用一个重复的元素替换单个数组元素?
- r - 创建循环以从多个 URL 中抓取 Web 数据时,R 中出现“externalptr”错误
- c - c存储变量中的高级内存管理
- python - 是或否结束循环不显示