Skip to content

API Reference parrot.integrations.msteams.graph

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.msteams.graph

View source

Minimal async Microsoft Graph client for the Teams HITL channel.

Provides email-to-AAD resolution used by TeamsHumanChannel.send_interaction to map a recipient email address to an Azure AD object ID before opening a proactive 1:1 conversation.

This module has NO dependency on botbuilder and does NOT import aiogram. It uses only aiohttp (project-standard async HTTP) and pydantic (data models).

Usage::

client = GraphClient(
    client_id="...",
    client_secret="...",
    tenant_id="...",
)
user = await client.get_user_by_email("manager@contoso.com")
if user is None:
    # resolution failed — caller should return False
    ...
manager = await client.get_user_manager(user.upn)

Class GraphClient

Async Microsoft Graph client for the Teams HITL channel.

Handles:

  • Client-credentials token acquisition with in-process expiry caching.
  • get_user_by_email: resolves an email to a :class:ResolvedTeamsUser via /users/{upn} first, falling back to /users?$filter=mail eq '{email}' on 404.
  • get_user_manager: returns the Graph user object for /users/{upn}/manager.

All methods return None (never raise) on any Graph error so the caller (TeamsHumanChannel) can fail-fast cleanly.

Parameter Type Default Description
client_id str Graph app registration client ID.
client_secret str Graph app registration client secret.
tenant_id str AAD tenant ID (for the token URL).
logger Optional[logging.Logger] None Optional logger. Defaults to module-level logger.

Method GraphClient.close

Close the underlying aiohttp session and release resources.

Should be called when the :class:GraphClient is no longer needed (e.g. from :meth:~parrot.human.channels.teams.TeamsHumanChannel.stop).

close() -> None

Method GraphClient.get_user_by_email

Resolve an email address to a :class:ResolvedTeamsUser.

Resolution strategy:

  1. Try GET /users/{email} (works when email == UPN).
  2. On 404, fall back to GET /users?$filter=mail eq '{email}'.
  3. Return None on any error or empty result.

get_user_by_email(email: str) -> Optional[ResolvedTeamsUser]

Parameter Type Default Description
email str The recipient's email address.

Returns: Optional[ResolvedTeamsUser] — A resolved user object, or None on failure.

Method GraphClient.get_user_manager

Return the Graph user object for a user's manager.

Used by the future TargetResolver (escalation feature) as a backend lookup. Returns None on error or missing manager.

get_user_manager(upn: str) -> Optional[Dict[str, Any]]

Parameter Type Default Description
upn str The user's UPN whose manager to retrieve.

Returns: Optional[Dict[str, Any]] — Raw Graph user dict for the manager, or None.

Method GraphClient.upload_file

Upload a local file to a user's OneDrive and return an org-view share link.

FEAT-273 (Module 7): app-only (client-credentials) file delivery for Teams. The file is uploaded to {user}'s OneDrive under {folder} via a Graph simple upload, then an organization-scoped view sharing link is created and returned for embedding in a Teams message.

Requires the Files.ReadWrite.All application permission (see module docs). Follows the class error contract: returns None (never raises) on any error.

upload_file(file_path: Union[str, Path], *, user: str, folder: str = 'A2UI-Artifacts') -> Optional[str]

Parameter Type Default Description
file_path Union[str, Path] Local path of the file to upload.
user str UPN / object id of the drive owner (e.g. the notify service account).
folder str 'A2UI-Artifacts' Destination folder within the drive root.

Returns: Optional[str] — A shareable webUrl string, or None on any failure.

Class ResolvedTeamsUser

Result of a successful Graph email-to-AAD resolution.

Fields:

Field Type Default Description
aad_object_id str Azure AD object ID (GUID) for the user.
upn str User Principal Name (often the same as email for cloud accounts).
email str The email address that was resolved.
service_url Optional[str] None Optional Bot Framework service URL associated with the user (populated from the ConversationReference cache, not from Graph directly).

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally