feat: add App.get_app_graph() and App._get_graph_token()#355
Draft
feat: add App.get_app_graph() and App._get_graph_token()#355
Conversation
… avoid duplication Agent-Logs-Url: https://github.com/microsoft/teams.py/sessions/03d51509-9734-4b08-9351-f90453bf9ff5 Co-authored-by: heyitsaamir <48929123+heyitsaamir@users.noreply.github.com>
…back Agent-Logs-Url: https://github.com/microsoft/teams.py/sessions/03d51509-9734-4b08-9351-f90453bf9ff5 Co-authored-by: heyitsaamir <48929123+heyitsaamir@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor to improve graph token usage
feat: add App.get_app_graph() and centralize _get_graph_token
Apr 3, 2026
heyitsaamir
reviewed
Apr 4, 2026
Collaborator
heyitsaamir
left a comment
There was a problem hiding this comment.
@copilot address these
| self.default_connection_name, | ||
| activity_sender=self.activity_sender, | ||
| app_token=lambda: self.token_manager.get_graph_token(tenant_id), | ||
| app_token=lambda: self._get_graph_token(tenant_id), |
Collaborator
There was a problem hiding this comment.
Hmm is there any benefit to this change @copilot ?
Contributor
Author
There was a problem hiding this comment.
You're right — there's no benefit. Reverted in 9f79045. ActivityProcessor is back to calling self.token_manager.get_graph_token(tenant_id) directly.
| from .plugins import PluginBase, PluginStartEvent | ||
| from .routing import ActivityHandlerMixin, ActivityRouter | ||
| from .routing.activity_context import ActivityContext | ||
| from .routing.activity_context import ActivityContext, _get_graph_client |
Collaborator
There was a problem hiding this comment.
We shouldn't be importing private functions. Could pull into a different file?
Contributor
Author
There was a problem hiding this comment.
Moved to utils/graph.py as a public create_graph_client function (9f79045). Both activity_context.py and app.py now import it from .utils, no private function exposed.
…sor change Agent-Logs-Url: https://github.com/microsoft/teams.py/sessions/8ed98a37-3b1d-4b7f-a509-d8bd137c07f9 Co-authored-by: heyitsaamir <48929123+heyitsaamir@users.noreply.github.com>
Copilot
AI
changed the title
feat: add App.get_app_graph() and centralize _get_graph_token
feat: add App.get_app_graph() and App._get_graph_token()
Apr 4, 2026
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.
Apphad no way to access a Graph client for app-only operations — onlyActivityContextdid.Changes
App._get_graph_token(tenant_id=None)— new private method wrapping_token_manager.get_graph_token(), mirroring the existing_get_bot_tokenpattern.App.get_app_graph(tenant_id=None)— new public method returning aGraphServiceClientfor app-only Graph operations. Not cached (clients own caching if needed). Accepts optionaltenant_idfor multi-tenant support.utils/graph.py— new utility module with a publiccreate_graph_clienthelper (replaces the private_get_graph_clientinline function inactivity_context.py). BothActivityContextandAppnow import it fromutils.ActivityContext.app_graph— unchanged.ActivityProcessor— unchanged.