feat(gateway): add Microsoft Teams platform integration#17683
Closed
heyitsaamir wants to merge 6 commits into
Closed
feat(gateway): add Microsoft Teams platform integration#17683heyitsaamir wants to merge 6 commits into
heyitsaamir wants to merge 6 commits into
Conversation
Wire Teams as a new messaging platform using the microsoft-teams-apps SDK. Uses an aiohttp webhook server (consistent with other webhook adapters) and the SDK's App.initialize() + handle_request() for JWT validation and activity dispatching. Proactive messaging via App.send(). All 16 ADDING_A_PLATFORM checklist items implemented: - Platform enum, config loading (all 3 creds required: client_id, secret, tenant_id) - Core adapter with aiohttp server on configurable port - Factory, authorization maps (3), platform hints, toolset - Cron delivery, send_message tool routing + standalone _send_teams() - CLI status display, gateway setup wizard (Teams CLI instructions) - 36 tests covering requirements, config, auth, routing, send, message handling - Env vars documented
- Implement send_exec_approval() with 4-button Adaptive Card (Allow Once / Allow Session / Always Allow / Deny) replacing plain-text /approve prompt - Register on_card_action handler that resolves gateway approval and replaces the card in-place with the decision (no double-click) - Store ConversationReference per chat_id so cards send correctly in group chats and channels, not just DMs - Add TEAMS_ALLOWED_USERS to allowlist check in run.py - Add 'teams' entry to PLATFORMS registry in hermes_cli/platforms.py - Fix pyproject.toml Teams SDK version constraint (>=2.0.0a1,<3) - Expose Teams webhook port in docker-compose.yml - Add Teams setup guide and platform comparison docs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add behavior table, Features section (approval cards, images), security warning, troubleshooting table, and fix incorrect network_mode: host reference. Aligns with Slack/Discord guide quality. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add `from __future__ import annotations` to teams.py so type annotations are evaluated lazily, avoiding `TypeError` when SDK classes are mocked as MagicMock. Extend `_ensure_teams_mock()` in test_teams.py to cover all new imports added for adaptive card support (invoke activity, card/invoke response models, cards module, ConversationReference, on_card_action) so the try-block in teams.py never falls to the except-ImportError branch during testing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Collaborator
Collaborator
5 tasks
Author
|
Closing in favor of #17764 |
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.
What does this PR do?
Hello! I am the maintainer of the Teams SDK SDK (I maintain TS, Py, and .net) and I'm adding Microsoft Teams as a fully supported messaging platform in Hermes.
The gateway connects via a webhook server (aiohttp on port 3978) authenticated through the Azure Bot Framework, using the
microsoft-teams-appsPython SDK.Key highlights:
/approveprompt, dangerous command approvals are delivered as Adaptive Cards with 4 buttons (Allow Once / Allow Session / Always Allow / Deny). Clicking a button resolves the approval inline and replaces the card with the decision, preventing double-clicks.ConversationReferencefrom each incoming message so cards (and future sends) work correctly in group chats and channels, not just DMs.Related Issue
Fixes #
Type of Change
Changes Made
gateway/platforms/teams.py— new Teams adapter: webhook server, message handler,send_exec_approval()with Adaptive Cards,on_card_actionhandler,_send_card()with stored ConversationReferencegateway/config.py— addPlatform.TEAMSenum valuegateway/run.py— wire up Teams adapter instantiation andTEAMS_ALLOWED_USERSallowlist checkhermes_cli/platforms.py— add"teams"entry toPLATFORMSregistryhermes_cli/gateway.py— add Teams to setup wizardhermes_cli/status.py— add Teams home channel displaycron/scheduler.py— add"teams"delivery platformtools/send_message_tool.py— add Teams dispatchtoolsets.py— addhermes-teamstoolsetpyproject.toml— addmicrosoft-teams-apps>=2.0.0a1,<3andaiohttpto messaging extradocker-compose.yml— expose port 3978 for Teams webhook delivery.env.example/cli-config.yaml.example— add Teams env vars and platform_toolsets entrywebsite/docs/user-guide/messaging/teams.md— full setup guide (tunnel options, Teams CLI, Docker, troubleshooting, security)website/docs/user-guide/messaging/index.md— add Teams to platform comparison and toolset tablesHow to Test
npm install -g @microsoft/teams.cli@preview && teams loginngrok http 3978(or devtunnel / cloudflared)teams app create --name "Hermes" --endpoint "https://<tunnel>/api/messages"TEAMS_CLIENT_ID,TEAMS_CLIENT_SECRET,TEAMS_TENANT_IDin~/.hermes/.envHERMES_UID=$(id -u) HERMES_GID=$(id -g) docker compose up -d gatewayteams app install --id <teamsAppId>rm -rf /tmp/test) — an Adaptive Card with 4 approval buttons should appearChecklist
Code
pytest tests/ -qand all tests pass — or N/A (no existing Teams tests to break)Documentation & Housekeeping
website/docs/user-guide/messaging/teams.md)cli-config.yaml.examplewith new config keysScreenshots / Logs