Azure Bot Service机器人状态保存技术疑问:对话数据生命周期等
I've reviewed the official Microsoft documentation on Azure Bot Service .NET State Management, and I have the following questions regarding bot state storage, specifically for bots deployed via the Web Chat channel:
- What is the lifecycle of stored data? For example, when I save data using the
context.ConversationData.SetValue(..)method, will this data be cleared after the conversation ends (such as when the user refreshes the page)? - The
Fromproperty in the Activity object includesIdandNamefields. I have follow-up questions to add later.
Answer
Let me break this down for you based on how Azure Bot Service handles state for the Web Chat channel:
1. Lifecycle of ConversationData
First, ConversationData is tied directly to a specific conversation ID. For the Web Chat channel, this conversation ID is linked to the user's browser session context.
- If a user just refreshes the page without closing the browser or clearing session-related storage (like cookies), the existing conversation ID usually stays intact. In this case, the data saved via
context.ConversationData.SetValue(..)won't be cleared—you’ll still be able to access it in the refreshed session. - If the user closes the browser, clears their browser’s cache/cookies, or starts a new browser instance, a new conversation ID will be generated. At that point, the old
ConversationDatabecomes inaccessible because it’s bound to the original conversation ID.
Additionally, Azure Bot Service has a default expiration policy for state storage. By default, conversation data expires after roughly 30 days, but you can adjust this timeline by configuring the state service to fit your needs. You can also manually delete data using methods like context.ConversationData.Clear() if you want to remove it before the automatic expiration.
2. Follow-up Questions on Activity.From's Id and Name
Since you mentioned you have follow-up questions about the Id and Name fields in the From property, feel free to share specific details whenever you’re ready. For example, questions about how the Id is generated in Web Chat, whether Name can be customized, or how these values behave across different user interactions would help provide a targeted, accurate answer.
内容的提问来源于stack exchange,提问作者user3740951

