Skip to content

msteams: Fetch thread/chat history from Graph API on session restart #54626

@atharva-getboon

Description

@atharva-getboon

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.historyLimit only 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions