Add Teams message history API#491
Draft
heyitsaamir wants to merge 13 commits into
Draft
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Microsoft Graph-backed Teams message history API for context-level and app-level callers, plus a focused example app for manual testing. History now returns both the messages and a serializable source that can be reused for future reads.
API
Reactive context API
ctx.get_history(n)infers the current scope from the inbound activity and returnsMessageHistory(messages, source):GET /chats/{chat-id}/messagesGET /teams/{team-aad-group-id}/channels/{channel-id}/messagesreply_to_idor;messageid=<root>and calls.../messages/{root-message-id}/repliesFor channel history, the SDK requires the Teams activity to include
team.aad_group_id; this is the Graph team resource ID used by RSC.App-level API
app.get_historyintentionally takes aHistorySourceinstead of individual IDs. Callers can passhistory.sourcefrom a previousctx.get_history(...)result or construct one of the exported source models directly:Available source models:
OneOnOneHistorySource(chat_id=...)GroupChatHistorySource(chat_id=...)ChannelHistorySource(team_aad_group_id=..., channel_id=..., thread_id=None)HistorySourceis a Pydantic discriminated union, so sources can be persisted withsource.model_dump(by_alias=True)and restored withTypeAdapter(HistorySource).validate_python(payload).The helper returns the latest
nmessages for the selected source:$orderby=createdDateTime descwith$top.$top; the SDK pages through replies and returns the lastnbycreated_date_timewhen timestamps are available.Graph errors propagate unchanged.
Caveats
Example
Adds
examples/historywith commands to test:history/history ctx <n>history chat <chat-id> [n]history channel <team-aad-group-id> <channel-id> [n]history thread <team-aad-group-id> <channel-id> <thread-id> [n]