Skip to content

feat: add App.get_app_graph() and App._get_graph_token()#355

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/reuse-get-graph-token
Draft

feat: add App.get_app_graph() and App._get_graph_token()#355
Copilot wants to merge 4 commits intomainfrom
copilot/reuse-get-graph-token

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

App had no way to access a Graph client for app-only operations — only ActivityContext did.

Changes

  • App._get_graph_token(tenant_id=None) — new private method wrapping _token_manager.get_graph_token(), mirroring the existing _get_bot_token pattern.

  • App.get_app_graph(tenant_id=None) — new public method returning a GraphServiceClient for app-only Graph operations. Not cached (clients own caching if needed). Accepts optional tenant_id for multi-tenant support.

  • utils/graph.py — new utility module with a public create_graph_client helper (replaces the private _get_graph_client inline function in activity_context.py). Both ActivityContext and App now import it from utils.

  • ActivityContext.app_graph — unchanged.

  • ActivityProcessor — unchanged.

# App-level Graph access, no ActivityContext needed
graph = app.get_app_graph()                         # default tenant
graph = app.get_app_graph(tenant_id="some-tenant")  # explicit tenant
me = await graph.me.get()

Copilot AI and others added 2 commits April 3, 2026 23:07
… 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>
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
Copilot AI requested a review from heyitsaamir April 3, 2026 23:09
Copy link
Copy Markdown
Collaborator

@heyitsaamir heyitsaamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm is there any benefit to this change @copilot ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be importing private functions. Could pull into a different file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copilot AI requested a review from heyitsaamir April 4, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants