点击卡片跳转URL后,如何在Cortana中恢复原有会话?
Alright, let's tackle this Cortana bot session persistence issue you're facing. I've worked through similar scenarios with Microsoft bots on Cortana, so here are practical, actionable fixes to get users back to the exact conversation node after they return from an external URL:
1. Use Cortana Deep Linking to Pass Context
Cortana supports deep linking that lets you carry session context back to your bot when users return. Here's how to implement it:
- When generating the adaptive card with the redirect URL, append critical session parameters (like a unique
sessionIdandcurrentConversationNode) to the external URL. For example:https://your-external-site.com?sessionId=xyz789¤tNode=product_inquiry - On your external page, add a "Return to Cortana" button that triggers a Cortana deep link. This link will send the saved context back to your bot:
cortana://converse?botId=your-bot-unique-id&context={"sessionId":"xyz789","currentNode":"product_inquiry"} - Update your bot's backend to listen for this
contextpayload. When received, fetch the corresponding session state (from your database or cache) and automatically resume the conversation at thecurrentNode.
2. Persist Session State Externally
Cortana's native session storage is limited, so offload your conversation state to a reliable external store (like Redis, Azure Cosmos DB, or your own backend database):
- Before the user is redirected, save all critical session data—including conversation history, current node, user ID, and session ID—to your external store. You can do this via a quick API call from your bot:
// Example: Save session state in Node.js await fetch('https://your-api.com/save-session', { method: 'POST', body: JSON.stringify({ userId: turnContext.activity.from.id, sessionId: turnContext.activity.conversation.id, currentNode: 'product_inquiry', conversationHistory: turnContext.activity.history }) }); - When the user re-initiates the Cortana conversation, your bot should first check the external store for an active session tied to the user's ID. If found, load the saved state and jump directly back to the pre-redirect conversation node.
3. Add a Contextual "Resume" Command
Simplify the user workflow by adding a dedicated voice/text command to resume the previous conversation:
- Train your bot to recognize phrases like "Resume my last conversation" or "Go back to where I was".
- When the user triggers this command, have the bot query your external session store using the user's ID, pull up the most recent session state, and restore the conversation to the redirect point.
- Proactively prompt users about this command on the redirect card: "After completing your task, say 'Resume conversation' to pick up right where you left off."
4. Embed a Lightweight Bot Component in the External Page
For a seamless experience, embed a mini-version of your bot directly in the external URL:
- This embedded bot can sync user actions (like form submissions or selections) back to your main bot's session state in real time.
- When the user returns to Cortana, the main bot already has the updated context and can resume the conversation without any extra steps from the user.
- Note: This requires frontend integration (using the Bot Framework Web Chat component) and backend sync logic, so it's a bit more complex but delivers the smoothest user experience.
Key Notes to Remember
- Always encrypt sensitive session data (like user IDs) when passing them via URLs or storing them externally to avoid security risks.
- Test your solution across different Cortana platforms (mobile, desktop, smart speakers) since deep linking behavior can vary slightly.
- Set a reasonable expiration time for saved session states (e.g., 24 hours) to clean up stale data and keep your store efficient.
内容的提问来源于stack exchange,提问作者Sash Sheen

