-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
msteams: Fetch thread/chat history from Graph API on session restart #54626
Description
Problem
When a Teams thread session expires (via session.threadBindings.idleHours) or after a gateway restart, the new session starts with zero context from the previous conversation in that thread. The user experiences this as the bot "forgetting" everything they discussed.
Current behavior
channels.msteams.historyLimitonly controls an in-memory buffer (Map<string, HistoryEntry[]>) of messages seen in real-time while the gateway is running.- When a session expires or the gateway restarts, this buffer is empty.
- No Graph API call is made to fetch historical messages from the thread/chat.
Expected behavior
When a new session starts on a Teams thread that has prior messages, the extension should use the Microsoft Graph API to fetch the last N messages from the thread and inject them as context — similar to how other channels can provide history on session start.
Graph permissions needed
ChannelMessage.Read.All(for team channel threads)Chat.Read.All/ChatMessage.Read.All(for group chats)
These permissions are already documented as supported in the msteams docs and many users already have them configured.
Workaround
Setting session.threadBindings.idleHours: 0 prevents sessions from expiring, but this means sessions grow indefinitely and context is still lost on gateway restart.
Relevant code
extensions/msteams/src/monitor-handler/message-handler.ts — the conversationHistories Map is purely in-memory with no Graph API fallback.