如何访问 Microsoft Bot Framework 上的用户数据?
How can I access user data on Microsoft Bot Framework?
如果我是正确的 userData
、privateConversationData
等等都存储在某个远程数据库中。我怎样才能访问这个数据库(例如在测试过程中清除它)?
由于未指定,我假设您正在使用 C#。
如果您能够使用 IDialogContext 对象,您就可以使用它来访问这些商店。
//Access private conversation data
context.PrivateConversationData
//Access user data
context.UserData
//Access conversation data
context.ConversationData
在此之后,您可以使用一些方法。最重要的是 TryGetValue(..)
、SetValue(..)
和 RemoveValue(..)
。
对于基本实现,'all user state database' 不可访问,您只能由用户执行操作(如 /deleteprofile
)。
documentation 添加了一个名为 How do I version the bot data stored through the State API?
的章节:
The State Service allows you to persist progress through the dialogs
in a conversation, so that a user can return to a conversation with a
bot days later without losing their position. But if you change your
bot's code, the bot data property bags stored through the State API
are not automatically cleared. You will have to decide whether the bot
data should be cleared based on whether your newer code is compatible
with older versions of your data. You can accomplish this in a few
ways:
- During development of your bot, if you want to manually reset the conversation's dialog stack and state, you can use the /deleteprofile
command (with the leading space so it's not interpreted by the
channel) to clear out the state.
- During production usage of your bot, you can version your bot data so that if you bump the version, the associated data is cleared. This
can be accomplished in Node using the exiting middleware or in C#
using an IPostToBot implementation.
If the dialog stack cannot be deserialized correctly (due to
serialization format changes or because the code has changed too
much), the conversation state will be reset.
另请参阅 BotBuilder Github 上关于存储的 topic。
这 question 也是为了国家安全
解决方法
由于 BotBuilder-Azure
Microsoft 提供的扩展,您可以为您的机器人使用自己的 Azure 存储。
它在 github here 上可用并且它:
enable bot developers to integrate bots with specific Azure
components.
Azure Table Storage: Allows bot developers to store bot state in their own Azure Storage accounts.
DocumentDB: Allows bot developers to store bot state in DocumentDB
所以一旦你设置好了,你就可以使用 javascript 获取你的数据,因为它是你自己的 Azure 存储。
如果我是正确的 userData
、privateConversationData
等等都存储在某个远程数据库中。我怎样才能访问这个数据库(例如在测试过程中清除它)?
由于未指定,我假设您正在使用 C#。
如果您能够使用 IDialogContext 对象,您就可以使用它来访问这些商店。
//Access private conversation data
context.PrivateConversationData
//Access user data
context.UserData
//Access conversation data
context.ConversationData
在此之后,您可以使用一些方法。最重要的是 TryGetValue(..)
、SetValue(..)
和 RemoveValue(..)
。
对于基本实现,'all user state database' 不可访问,您只能由用户执行操作(如 /deleteprofile
)。
documentation 添加了一个名为 How do I version the bot data stored through the State API?
的章节:
The State Service allows you to persist progress through the dialogs in a conversation, so that a user can return to a conversation with a bot days later without losing their position. But if you change your bot's code, the bot data property bags stored through the State API are not automatically cleared. You will have to decide whether the bot data should be cleared based on whether your newer code is compatible with older versions of your data. You can accomplish this in a few ways:
- During development of your bot, if you want to manually reset the conversation's dialog stack and state, you can use the /deleteprofile command (with the leading space so it's not interpreted by the channel) to clear out the state.
- During production usage of your bot, you can version your bot data so that if you bump the version, the associated data is cleared. This can be accomplished in Node using the exiting middleware or in C# using an IPostToBot implementation.
If the dialog stack cannot be deserialized correctly (due to serialization format changes or because the code has changed too much), the conversation state will be reset.
另请参阅 BotBuilder Github 上关于存储的 topic。 这 question 也是为了国家安全
解决方法
由于 BotBuilder-Azure
Microsoft 提供的扩展,您可以为您的机器人使用自己的 Azure 存储。
它在 github here 上可用并且它:
enable bot developers to integrate bots with specific Azure components.
Azure Table Storage: Allows bot developers to store bot state in their own Azure Storage accounts.
DocumentDB: Allows bot developers to store bot state in DocumentDB
所以一旦你设置好了,你就可以使用 javascript 获取你的数据,因为它是你自己的 Azure 存储。