fix(teams): deliver documents via file consent cards - #89491
Closed
HermeticOrmus wants to merge 1 commit into
Closed
fix(teams): deliver documents via file consent cards#89491HermeticOrmus wants to merge 1 commit into
HermeticOrmus wants to merge 1 commit into
Conversation
Bot Framework rejects non-image data: URI attachments with HTTP 400, so send_document silently failed for .xlsx/.pdf/.csv. Personal chats now offer a file consent card; accept uploads to the user's OneDrive via the pre-authorized URL. Pending offers persist on disk as opaque tokens so a short-lived hermes send and the gateway process can share state without echoing a path through the client. Group chats and channels keep the old attachment path — Teams has no consent flow there. Tenants must set bots[].supportsFiles in the app manifest or Allow fails with "card action is not supported". Verified: pytest tests/gateway/test_teams.py — 30 passed
Contributor
Solid design overall (opaque token, disk-backed pending map, allowlist gate, behavioral tests against a temp
|
13 tasks
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?
send_documenton Teams silently failed for every non-image file. The adapter base64s local files into adata:URI attachment; Bot Framework accepts that for images and returns HTTP 400 for everything else (.xlsx,.pdf,.csv, …). The text that went with the file still claimed it was attached.The supported Bot Framework path for a bot to deliver a document in a personal chat is the file consent card: the user accepts, Teams returns a pre-authorized upload URL into that user's own OneDrive, and the bot PUTs the bytes there. No Graph permissions are required.
This PR routes local
send_documentcalls in personal chats through that flow, and keeps the existing attachment path for group chats / channels (Teams has no consent flow there) and for HTTP(S) URLs.Related Issue
No existing issue or PR covers Teams
send_document/ file consent (searched open + closed). Group-chat document delivery remains a platform constraint, not addressed here.Type of Change
Changes Made
plugins/platforms/teams/adapter.py$HERMES_HOME/pending_file_consents.json, mode 0600, 24h TTL) keyed by an opaque token — never a path — so a short-livedhermes sendand the long-lived gateway can share state, and a tampered invoke cannot upload an arbitrary local file._send_file_consentoffers the card;_on_file_consent(registered via@app.on_file_consent) completes or discards it.TEAMS_ALLOWED_USERS/TEAMS_ALLOW_ALL_USERSallowlist as card actions.send_documentuses the consent path for local files in personal chat; group/channel ids (19:…) and remote URLs keep the attachment path.tests/gateway/test_teams.py— personal-chat offer, empty/oversized rejection, accept upload + token drop, decline, unknown token, allowlist gate. Existing group-chatsend_documenttest still expects the attachment path.Scope note: consent is personal-chat only. The tenant Teams app manifest must set
bots[].supportsFiles: trueor the Allow button fails with "This card action is not supported by <bot>".How to Test
pytest tests/gateway/test_teams.py -q(30 passed on this branch)..xlsxfrom a personal chat. A consent card should render; after Allow, the file lands in the recipient's OneDrive and a file-info card appears. Gateway log:[teams] Uploaded … after consent.I did not run the full
pytest tests/ -qsuite locally. The install/update tests in this repo rebuild.venvand reset the git checkout; targeted tests + CI are the safer split.Checklist
Code
fix(teams):)pytest tests/ -qand all tests pass — targetedtest_teams.pyonly; see aboveDocumentation & Housekeeping
docs/, docstrings) — N/A (adapter docstring + comments)cli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AHERMES_HOME+os.replace