Chat bridge API
The chat bridge lets a user in Mattermost, Microsoft Teams or Slack talk to a saved Myra AI Workspace agent from inside their chat client: they message the bot, the bridge runs the configured agent, and the answer comes back in the same thread.
This page documents the channel-agnostic core and its inbound trust boundary. Each chat platform is a thin adapter (Mattermost first) that plugs into this core; the core is identical across platforms.
Architecture — one core, thin adapters
Everything between "a message arrived" and "a reply must be sent" is identical across platforms. Only the two edges differ per platform, and they live behind a five-function adapter interface:
| Adapter function | Responsibility |
|---|---|
extract_workspace_key |
pull the workspace/team id from the raw event — body or Request-URL query (pre-auth) |
verify |
validate the platform signature/secret (fail-closed) |
parse |
turn the raw event into a normalized message, an ignore, or a synchronous respond (handshake) |
resolve_identity |
map the platform user to a verified email (may call the platform API) |
render_and_send |
post the reply back into the thread |
The core owns identity mapping, thread↔conversation binding, agent selection,
invocation, and reply mapping. A message is a { platform, workspace_key,
platform_user_id, thread_key, text, event_id } record; a reply is { text, status }.
The inbound endpoint
POST https://ai-api.myra.eu/chat-bridge/{platform}/events
Content-Type: (platform-specific: JSON or form-encoded)
(platform-native event payload)
Accepted request shape:
| Part | Accepted | Rejected → status |
|---|---|---|
| Readiness | the gateway has finished starting up | during the start-up window → 503 with Retry-After and X-AIG-Error: service_starting (the platform retries); the body is {"error":{"code":"service_starting",…},"code":"service_starting"}, the same top-level code as every other error from this endpoint |
| Method | POST only |
any other → 405 (with Allow: POST) |
| Path | /chat-bridge/{platform}/events, {platform} a registered adapter |
unknown/malformed → 404 |
| Body | raw bytes, valid UTF-8, ≤ 32 KB (the adapter decodes) | > cap → 413 (refused at the edge as {"error":"payload_too_large"}, no code; see Rejection behaviour); non-UTF-8 → 400 |
| Workspace | must resolve to an enabled chat_bridge_connection row |
unknown → 403 |
| Signature | must pass the adapter's verify |
invalid → 403 |
| Rate | no per-source-IP limit; only a signed event meets the per-(platform, workspace) sliding window |
exceeded → 429 |
| Known workspace | a per-node list of every configured workspace (enabled or disabled) gates the database; an unknown workspace is refused without a lookup | unknown → 403; while the node has not yet loaded the list → 503 {"error":"busy; retry","code":"temporarily_unavailable"} |
| Event id | a message must carry a platform-stable event_id |
empty/absent → 400 {"error":"bad event","code":"event_id_required"}; present but not a string (JSON null included) → 400 {"error":"bad event","code":"invalid_event_id"}; an id the durable claim cannot key safely (platform over 32 bytes, workspace or event id over 191 bytes, a workspace key that is not valid UTF-8, or an event id that is not printable ASCII — a space, control byte or non-ASCII character) → 400 {"error":"bad event","code":"invalid_event"}, nothing claimed or processed |
Inbound event body
After the signature and the per-workspace rate limit pass, the body is read once, strictly, before any adapter parses it. The order of checks is: method, body cap and UTF-8, workspace, configuration, signature, rate limit, body. A body that fails the last step is not processed: no event row is written and nothing is posted.
| Body (validly signed or authenticated) | Answer |
|---|---|
| a JSON object repeats a key at any depth | 400 {"error":"duplicate key in event body","code":"duplicate_key"} |
more than 16,384 structural elements (each {, [, , and each string, counted outside string contents) |
413 {"error":"event body too complex","code":"body_too_complex"} |
not valid JSON (including a raw NUL byte or a UTF-8 BOM), or holds a non-finite number such as NaN |
400 {"error":"malformed event body","code":"malformed_body"} |
Slack only: a blank body, a non-object JSON value, or a form-encoded body (for example a Slack Interactivity payload= URL pointed at /events by mistake) |
400, malformed_body (a form-encoded body was previously acknowledged 200 and ignored) |
On the Mattermost relay and on Teams the workspace key is read from the body itself, so a blank or invalid body
cannot name a workspace and stays the opaque 403 at the workspace step. Slack takes the workspace from the ?ws=
query, so it reaches the body check. The refusal is typed, so the sender can tell a repeated key from a
malformed body; it is only ever sent to a caller that already passed authentication.
Operator alert. A refused body of an authenticated caller is a platform alert with the signal
bridge_body_refused, at most once per hour per workspace; the count is always available as the metric
aig_bridge_body_refused_total. The alert names the platform, tenant, gateway, code and route, never the body or a
key name. What to do: for Slack, the request carried a valid signature, so check whether the signing secret has
leaked; for a Mattermost slash command, check whether the slash token has leaked; for the Mattermost relay, check
whether the relay shared secret has leaked or the relay is broken; for Teams there is no secret to rotate (the Bot
Framework token does not sign the body), so check for token replay or a changed Teams payload.
A failed verify is always 403, never 429, so a flood from one source cannot lock out a real
workspace. What a platform does with a non-2xx answer differs, so do not assume a 503 is retried:
| Platform | On a non-2xx answer or no answer within 3 s |
|---|---|
| Slack | retries up to 3 times (immediately, after about 1 minute, after about 5 minutes), marking each with X-Slack-Retry-Num and X-Slack-Retry-Reason; Slack disables an events subscription whose deliveries fail more than 95 % of the time |
| Microsoft Teams | treated as not retried — assume a refused Activity is lost |
| Mattermost relay | does not retry; it counts consecutive forward failures and raises the [MM_RELAY_SILENT] alert after a streak |
| Mattermost slash command | shows Mattermost's generic error; the user types the command again |
A real message is claimed first, then acknowledged 200, and processed
out-of-band — chat replies take seconds (far past a platform's few-second ACK
deadline) and are posted back through the platform API, not on the inbound
connection. The claim is one indexed database write taken before the acknowledgement, so
the answer is only sent once the event is durably recorded. A redelivery of an event that
is already claimed is answered 200 {"status":"duplicate"} and does no work. If the claim
cannot be taken (the database is unreachable) the answer is 503 temporarily_unavailable
and nothing is processed — a platform that retries then redelivers into a healthy claim store. A handshake (e.g. Slack URL verification) is answered synchronously
with the body the adapter dictates. A bot echo or non-message event is ignored
with a 200.
Rejection behaviour (fail-closed, no enumeration)
Every rejection does no work. To avoid revealing which workspaces exist, an
unconfigured workspace and a failed signature return an identical 403
{"error":"forbidden","code":"forbidden"}. Every JSON error the handler produces on the events and slash
endpoints carries a top-level code (not_found, method_not_allowed,
payload_too_large, bad_utf8, event_id_required, invalid_event_id, invalid_event,
duplicate_key, body_too_complex, malformed_body, rate_limited, temporarily_unavailable, internal_error); the status and the error
sentence are unchanged, and a body the server cannot read answers 503
temporarily_unavailable. The exception is an oversize body: the front end caps /chat-bridge/ at 32 KB, the same as the handler, so every body over the cap is refused before the handler with 413 {"error":"payload_too_large"} and no code. Key off status 413 (or the error token). See
Typed codes on the webhook receiver and the chat-bridge endpoints. If the detached worker cannot be spawned (server busy), the gateway releases the
claim it just took and returns a retryable 500 without acknowledging, so a platform that
retries redelivers into a free claim. If that release itself fails, the claim stays and the
redelivery is answered as a duplicate: that one message is dropped (logged at ERROR) rather
than ever being answered twice.
Identity — fail-closed, tenant-pinned
The chat user is mapped to a gateway user by email, scoped to the tenant that owns the resolved connection:
- The email is resolved by the adapter (
resolve_identity) and looked up only within the connection's tenant — an email that matches a user in a different tenant is not accepted. - The user must be active (not soft-deleted), not under a GDPR Art. 18
processing restriction, and not a
viewer(viewers are barred from inference). Any failure returns a short, generic message to the chat and runs nothing. - An unmapped user is told their chat account isn't linked; the gateway never invokes on their behalf. The client is never the authorization boundary — tenant, gateway, agent and owner are all resolved server-side from the deployment's configuration.
Execution — run-as-owner, held egress
The agent for a workspace defaults to the server-configured default_agent_slug;
in a direct message a user may switch it per conversation to another agent they are
entitled to (see the Agent picker section below), but never to a private or
cross-tenant agent. It runs as the agent's owner — the same
run-as-owner model as the scheduler and webhook triggers — via the normal
inference pipeline (guardrails, PII and routing all apply unchanged).
Because the connection's gateway guardrails apply to every bridge turn, a gateway
configured with a fail-closed PII detector (pii_protector with fail_open: false)
masks personal data in the message before it reaches an external model and masks
model-generated personal data in the reply — recommended for any bot reachable from
a chat workspace. (A bridge turn served wholly by a first-party local Myra/EU model is
not masked — the data never leaves Myra; see PII Protector — Local model legs are not
masked.) The connection's bound gateway (gateway_slug, matched against the stored spelling exactly — a case or padding variant is gateway_not_found) is the sole
enforcement point: bind the bot to a gateway that carries the fail-closed detector
(typically a dedicated PII gateway), not to a shared unguarded one. If the PII
analyzer is unavailable while fail_open is false, the turn is blocked, not
degraded: the bot posts a localized error reply instead of answering (see
Replies the bot sends instead of an answer) —
never a silent drop, and never an unmasked answer.
Over-long messages. A message longer than 16 KiB (16,384 bytes) is shortened to
its first 16,384 characters before the agent runs. Personal data or a keyword that crosses that cut is
masked at the cut, together with up to 256 bytes of the text that was cut off, with the detectors
the agent run applies (the connection's gateway, the agent owner's personal keywords and role
detectors, the mandate of the agent's knowledge areas) — the run's own scan sees only the kept text
and would not recognise a fragment. If the cut cannot be masked (the analyzer is unavailable, or a
block detector matches across the cut) the bot answers "Your message is too long for the assistant
and could not be shortened safely. Please send a shorter message." (localized) and runs nothing; if
the agent owner, the gateway configuration or the agent's knowledge areas cannot be read it answers
its temporary-fault reply ("Something went wrong on our side. Please try again in a moment."). The stored turn (replayed in later turns) is the masked text. A message
within the limit is unchanged.
Every bridge turn is attached to an agent run, and the gateway decides from that run whether the turn is
trusted. The bridge sends no tool-restriction header: the agent keeps its full tool set (including the code
interpreter), and the restriction is the gateway's own held-egress rule. A turn that runs with the connection's
full egress rights (Full-tool opt-in) behaves as in the /easy app. Every other
turn (a foreign caller) is treated as carrying untrusted content: tools that send data out (fetch_url,
agentic_fetch, external MCP writes, web search) are held for approval instead of running, so an external,
model-unauthenticated channel cannot steer the agent into sending data out by itself. A turn is never
treated as trusted merely because it arrives from the bridge: a bridge turn without a run is refused
(400 INVALID_REQUEST), and a run whose trust marker is missing or malformed is treated as a foreign caller.
Caller-scoped connector credentials. A bridge turn names the asking colleague to the gateway
(X-AIG-Bridge-Driver, accepted only on the connection's own service token), and user-scoped MCP connectors run
with that colleague's credential - never the agent owner's. When a connector needs a credential the colleague has
not connected, the gateway answers with X-AIG-Connect-Required and the bot tells them to connect it. Both header
contracts are specified in Agents API - Chat-bridge driver and
Connect-required response header.
Bridge-driven runs are non-interactive: if the per-call decision record cannot be written, the tool call is denied
(record_write_failed).
Model that always searches. A bridge turn whose agent uses a model that searches the web on every call (for example OpenRouter perplexity/sonar) is held the same way when it has processed outside content: the hold has hold_reason: "inherent_search" and is decided by the same approver as any other hold of the turn. A rejection or expiry ends the turn with inherent_search_rejected. The same applies to a Gemini or Vertex agent whose request would inject Google Search grounding: the hold has hold_reason: "native_grounding" and a rejection or expiry ends the turn with native_grounding_rejected. Operators: a hold that is never decided shows up in the vanishing SLI like any other expired hold.
Held for approval. A bridge turn is attached to an agent run, so a gated write call is held instead of
denied. The thread receives an "Approval needed" notice with a link; the asking colleague approves or rejects it in
the approvals inbox (/admin/v1/me/tool-approvals/{id}/approve|deny). After the decision the scheduler resumes the
run and the bot posts the outcome into the same thread: the answer when approved, "Rejected" when rejected, and
"Expired" when the approval window passes (the thread shows the "Expired" notice to the asker; the agent's owner receives the expiry email). On rejection and expiry the tool never
runs. On a turn that runs with the connection's full egress rights, only the colleague who asked can decide; the run is bound to the bridge connection and that driver (turns with a foreign caller follow the rule below). If the
asking colleague is erased (GDPR Art. 17), their held bridge runs are failed.
If a bridge turn finds that the review of its held run no longer exists (for example after the tenant or gateway was purged), the thread gets the neutral "temporary" answer instead of a hold notice.
Who approves a foreign-caller turn. When a turn runs with a foreign caller (the connection does not grant the asking colleague's full egress rights), a held call is approved by the owner of the chat connection, not by the asking colleague. The thread notice then says that the connection owner has been asked and carries no details link, and the owner (not the asker) sees the approval in their inbox; the asker cannot decide it. The single exception is a batch made up only of calls on the asking colleague's own, non-shared MCP connector: it stays with the asker. A shared connector, a colleague's connector, a built-in tool and any mixed batch always go to the owner. A nested sub-agent call on the asking colleague's own connector goes to the connection owner as well. An owner who is disabled, processing-restricted or a viewer cannot approve; if the connection owner cannot be determined or is not an eligible account in the tenant, the held calls are denied instead of being routed to anyone else. This rule applies to foreign-caller turns once they are attached to a run.
A foreign-caller turn (and the sub-agents it delegates to) never feeds the agent's automatic protection pauses; see Foreign-caller chat-bridge turns never trigger an automatic pause.
Content nobody on the team wrote
Full egress (Full-tool opt-in) is meant for what the asking colleague typed. A turn
that carries text no mapped user wrote is therefore marked untrusted even on a connection with allow_egress on:
the agent still answers, but its outgoing tools are held for approval, like any other run that has read untrusted
content (reason untrusted_egress; see Agents API - Untrusted content holds). Because the content was sent
under a colleague's name, the asking colleague (the driver) decides the hold, not a foreign caller's connection owner.
What each platform admits as user-typed:
- Mattermost. The relay flags a post that came from an incoming webhook, an integration, a plugin, an OAuth app or a
bot (and any post whose origin marker it cannot read). Such posts carry the creating user's id, so without the flag
their text would pass as that colleague's own words. A post made with a user's personal access token carries no
marker and cannot be detected.
An unexpected or null shape of the origin marker (
props) is treated as foreign. - Slack. Only user-typed messages are accepted; bot and subtype messages are filtered before the gateway sees them. A post made through a Slack app with a user token is indistinguishable from the user's own text and cannot be detected.
- Microsoft Teams. A quote-reply (the quoted text is another author's; Teams delivers it as a quote block in the
message text or in its HTML attachment) is flagged, as is a card submit (a message with a
valueor apostBackmarker). A quote sent only as an attachment is not forwarded to the agent; a quote that Teams puts inside the message text is forwarded as part of the message, and the turn is marked foreign (its outgoing calls are held). An unexpected or null shape (attachments,value) is treated as foreign (fail closed). Any quote or reply marker counts, so a user quoting their own earlier message is flagged as well (deliberate). A card button of typeimBackis posted by Teams as ordinary typed text and cannot be detected.
The flag follows the content. It is stored with the message, and every later turn whose replay window (the last turns of the conversation, bounded by the history limit) still contains a flagged message is untrusted as well, including a follow-up the colleague typed themselves. The replies the agent wrote while a flagged user message was in the window are flagged too, because they may repeat that content; a reply written when only flagged replies remain in the window is not. The taint therefore ends at most about two replay windows after the last foreign-origin message, provided the colleague's follow-ups are clean. One residual remains: if the agent repeats flagged content verbatim, a reply written after the last flagged user message has left the window is not flagged, so the repeated text can outlive the mark once the original and the replies written while it was in the window have aged out; until then every outgoing call of those turns is held for approval. In a new thread, turns are trusted again at once. In a shared thread or group direct message a flagged message affects every participant's turns in that thread, because they all replay it.
Limits and rules:
- Web drawer. Turns written through the web drawer are authenticated web-user turns: the drawer turn itself is not
restricted (search stays on, nothing is held or refused). The assistant reply it writes is nevertheless marked
when the conversation's replay window still contains a flagged message, so a drawer reply cannot clear a flagged
chat-bridge message out of a later replay window. If the gateway cannot read the history, the reply is marked and
the turn is not blocked. A forked conversation keeps the marks of the copied messages, and so does a conversation continued from a share link: the marks are read from the original conversation at copy time, never from the link or from the request. If the original's marks cannot be read, continuing from the link fails with 503 and no copy is created. If a copied message cannot be matched to a message of the original, it is marked whenever the original has any marked message. Editing a flagged message
keeps its flag; deleting it removes it from the replay window. A reply that only sees flagged replies (no flagged
user message) is not itself flagged, so the mark dies out after a clean follow-up. A reply the browser saves with
POST /conversations/:id/messages(roleassistant, when no stream acknowledgement arrived) gets the same mark from the same server-side rule; anyuntrusted_originin that request body is ignored, and user messages are never marked by it. - Agents that were already running unattended keep the tools their frozen consent snapshot granted (see Grandfathered agents on a marked run); every other agent is held.
- Web search. The web search allow of
allow_web_searchapplies to foreign callers only. On a full-egress turn marked untrusted, web search follows the rules above: held unless the agent is grandfathered. - Rollout. The relay and the gateway ship in the same image. The relay sends
foreign_originwith every event; the gateway reads an absent or non-boolean value as foreign (fail closed), so an event from an older relay is treated as carrying foreign content until the relay is upgraded.
Web search opt-in (allow_web_search)
On a foreign-caller turn, gateway web search is held for approval like any other outgoing call. The connection
owner can let the bot search without approval per connection via allow_web_search (default off; the API accepts only a JSON boolean — any other value is
400 allow_web_search must be a boolean; a stored value other than on counts as off. Full-tool opt-in also lets web search run without a hold). Web search egresses only model-generated search queries, PII-scrubbed and
routed to the EU-resident search provider, never an attacker-supplied URL and never code. With the flag on, the
gateway's web_search runs without a hold, and each such call is recorded in the access decision record with the rule
bridge_connection:web_search:<connection id>; if that record cannot be written, the search is not run. The flag
covers web_search and nothing else: fetch_url / agentic_fetch and external MCP writes remain held for the
connection owner, and sub-agents the agent delegates to do not inherit it: on such a turn a delegated sub-agent's built-in outgoing calls
(web_search, fetch_url, agentic_fetch) are held for the connection owner, like the agent's own, and nothing is sent until the owner approves (a sub-agent that cannot be held, for example one of several in the same round, is refused and recorded in the access decision record). Changing the flag takes effect for the next call, so a search that is still waiting for approval when the
owner turns the flag off stays held. The model provider's own built-in search is switched off on such a turn, so
the only search path is the gateway's recorded one. If the agent does not have web search enabled, the flag has no
effect. A Tier-1 (local-only) project or knowledge area still blocks web search entirely, and PII masking on the
search leg is unaffected.
Security note. Enabling web search widens the bot's outbound surface on an unauthenticated channel: a workspace user (or injected content) can prompt the agent to run a search. The query is masked and EU-resident, so the residual risk is a search being triggered, not data exfiltration to an arbitrary endpoint. Leave it off unless the bot needs current information.
Owner-knowledge note. The configured agent answers with its owner's knowledge areas and connected tools, and those answers are visible to every user mapped in that workspace. Held egress stops outbound tool calls, not what the agent chooses to say. Only configure an agent whose knowledge you are willing to expose to that workspace's members.
Full-tool opt-in (allow_egress)
For a bot whose channel members are fully trusted, the connection owner can give the asking colleague the agent's
full tool set per connection via allow_egress (default off; exactly on counts, anything else is off). When it
is on (and the agent is in scope, see Agent picker), the turn is not a
foreign-caller turn: nothing is held for being a bridge turn, and the agent's own tool configuration governs all
tools: code_interpreter, fetch_url / agentic_fetch, external MCP connectors, image generation and sub-agent
delegation, exactly as in the /easy app. allow_egress also covers web search, so allow_web_search is moot
while it is on. Defense-in-depth still applies: a Tier-1 (local-only) project or knowledge area still blocks
egress, the fetch_url SSRF guard still pins targets, and PII masking on tool-call arguments is unaffected.
Security note — read before enabling. This is a materially larger widening than web search. The bridge invoke runs with the agent's tools, so with
allow_egresson, any member of the chat workspace — and any content injected into a shared thread — can drive the agent's full toolset: execute code and fetch arbitrary URLs. MCP connector calls use the asking user's own connected credentials, never the owner's: a colleague who has not connected a connector gets a connect notice instead. Personal connectors that only the agent's owner can use are not available when someone else asks the agent. On an unauthenticated external channel this is a real data-egress and lateral-movement surface. Enable it only when you trust every member of the workspace, and prefer an agent whose tools and connectors are scoped to what that channel legitimately needs. It is default-closed on every connection and must be opted in explicitly per connection.
Agent picker — choose an assistant per DM
In a direct message with the bot, a user can switch which agent that conversation talks
to, instead of the connection's fixed default_agent_slug. The advertised form is a plain message
directive the relay delivers as text; Mattermost can also drive the same picker through registered
native slash commands (/agents + /agent) — see Native slash commands under the
Mattermost adapter:
| Command | Effect |
|---|---|
!agents |
List the assistants this user may pick (slug + name). |
!agent <slug> |
Switch this DM conversation to <slug>. |
!agent |
Show the conversation's current assistant + usage. |
Why ! and not /. The Mattermost client (and Slack/Teams) intercepts any /-prefixed
message as a slash command and, for an unregistered trigger, blocks the post with a "command
not found" nag instead of delivering it. ! is ordinary text to those clients, so
it always reaches the relay. The /-prefixed forms (/agents, /agent <slug>, /agent) are
still accepted for back-compat and for users who reach the picker via the client's "send
as a message" fallback — but ! is the advertised, reliably-working form.
Accepted / rejected. A command is exactly a single leading ! or / immediately followed
by agents / agent / agent <slug>, with <slug> matching ^[a-z0-9-]+$. Anything else — a
bare word (agents), a doubled/mixed prefix (!!agents, /!agents), a space after the prefix
(! agents), a multi-word !agent please help, or a question !agents do you support X? — is
treated as a normal message, never a rejected command. The slug is validated against the
user's entitlement and the URL slug is always the resolved agent id's slug — never the raw text.
Per-user entitlement (the authz gate). A user can only select an agent their mapped gateway user is entitled to: own ∪ user-share ∪ group-share ∪ org-approved, minus flagged/disabled. Private and cross-tenant agents are never listed or selectable. The selection is validated at pick time and re-validated every turn — if access is later revoked or the agent is deleted/disabled, the DM silently falls back to the default assistant.
Scope. DM-only. In a shared channel the commands are not interpreted and the
default assistant is used (a channel is multi-user with one conversation, so per-user
selection is incoherent). The selection persists per thread (chat_thread_map.agent_id),
keyed on the ownership-verified conversation — a user cannot rebind another user's DM.
Audit. A picked agent still runs under the service token (outgoing calls held unless the allow_egress scoping rule below applies;
MCP calls use the asking user's own credentials), but the turn's request_log.invoker_id
records the driving Mattermost user — so who-drove-what is auditable even when the agent is
owned by someone else. GDPR Art.17 erasure scrubs a driver's
id + message content on those rows.
Interaction with
allow_egress. On a connection withallow_egresson, full egress is scoped to the agent's identity, not granted blanket to whatever agent is picked:
- The connection's default (preselected) agent runs agent-authoritative for any driver — the admin who set
default_agent_slug+allow_egressdeliberately authorized that agent's toolset for the whole workspace (the "preselected connection" grant).- A picked (non-default) agent runs agent-authoritative only when the driving user owns it (
agent.created_by== the mapped driver). Any other picked agent — e.g. an org-shared agent the driver can see but does not own — is treated as a foreign-caller turn (outgoing calls held for the connection owner) even whileallow_egressis on, so a user can never drive another owner'sfetch_url/code_interpreter/ MCP connectors via that owner's agent. The same shared agent therefore has different tool capability depending on who drives it — by design (this closes the confused-deputy / credential-laundering vector).
allow_web_searchis unaffected: it is a gateway-scoped, PII-scrubbed allow (not owner-credential egress), so it still applies to a foreign-caller turn. Escape hatch: to grant every driver full egress on a specific agent, make it the connection's default agent. All inputs to this decision are server-side (created_byis set from the authenticated creator, the driver from the verified identity mapping) — the client cannot influence it.
Conversations and continuity
A chat thread maps to a reused chat_conversation (thread_key → conversation_id),
so replies in the same thread continue the same conversation. History lives in the
normal message store — the bridge adds no second copy. Each turn replays the recent,
bounded history to the (stateless) invoke; the user and assistant turns are written
together, only after a successful answer, so a failed turn never corrupts the
thread.
Replay content. The replay carries each stored turn's text as it is — no note about produced files or images is added to an assistant turn, and none is removed (models imitated such notes as their own speech; stored answers were cleaned once by migration 0454). Bridge turns are stored without linked outputs, so the web chat's conversation record has nothing to list for a bridge conversation. An assistant turn with no text is not replayed.
Thread ownership (private DMs). For a private DM thread, the mapped conversation
is reused only for its owning gateway user: if a request resolves to a different
user than the one who owns that DM's conversation, the bind is refused (fail-closed,
opaque error — the reply never reveals that the thread exists). This scopes a DM's history
to its owner, so a forged thread_key cannot pull another user's DM history into the invoke
context. A channel thread is intentionally shared — every participant continues the
same conversation — so its multi-user continuity is unaffected. The DM-vs-channel signal is
the platform's own (Mattermost/Slack channel type, Teams conversationType), derived
fail-closed (an unknown Teams type is treated as a DM and gated).
Replies the bot sends instead of an answer
When a turn cannot produce an answer, the bot posts one localized (en/de) reply instead and persists nothing for that turn, so the thread stays well-formed. Which reply depends on why:
| Situation | Reply (English wording) |
|---|---|
| Any other failure (transport error, an error status, an empty answer) | "The assistant couldn't produce an answer. Please try again." |
The answer is interrupted — the model call failed mid-answer after the assistant's tools may already have run, so the gateway answered the typed error (for example 502) with x-should-retry: false (an HTTP 2xx carrying X-AIG-Error is read the same way, as a defensive backstop; see Inference › Interrupted answers) |
"The assistant was interrupted before it could finish. Actions it had already started (for example sending a message or changing a file) may have been carried out — please check before asking again." |
| The asker's department, or a project restriction, does not allow the assistant's gateway | "Your department or a project restriction does not allow this assistant's gateway. Please contact an administrator." |
| The assistant is paused by automatic protection and waits for its owner or an administrator | "This assistant is paused until its owner or an administrator reviews it, so it can't answer right now. Please contact its owner or an administrator." |
| The assistant is being handed over and waits for the new owner to accept the hand-over | "This assistant is being handed over to a new owner and is paused until they accept the hand-over, so it can't answer right now. Please contact its owner or an administrator." |
The assistant's monthly spending limit is reached (agent_spend_cap_reached) |
"This assistant has reached its monthly spending limit, so it can't answer right now. Please contact its owner." |
The assistant's spending could not be checked (agent_spend_unverified; fail closed) |
"This assistant's spending could not be checked right now, so it did not answer. Please try again in a moment." |
A held call to a model that always searches was rejected or expired (inherent_search_rejected) |
"The held model call was not approved (rejected or expired), so it was not made." |
A held Gemini/Vertex call with Google Search grounding was rejected or expired (native_grounding_rejected) |
"The held model call with Google Search was not approved (rejected or expired), so it was not made." |
A paused or handed-over assistant cannot answer until a person acts, so asking again does not help.
Each of these replies counts as a failed turn in the bridge's invoke-error metric, like the generic one.
Long turns. A bridge turn has a tool-loop time budget of 900 s (15 min), the same as a streamed
turn, even though the bridge itself does not stream (it waits for the whole answer and posts it once). Other
stream: false calls keep 360 s. A turn that uses the whole budget is neither cut off early by the bridge nor run a
second time. When a turn is stopped
by the time limit, the bot posts what it had produced so far followed by the time-limit note, and persists
it; reply in the thread to continue from there.
Delivery semantics
Delivery is at-most-once with durable de-duplication. Each event is claimed by a
durable, node- and reload-safe record keyed by (platform, workspace, event_id), so
a platform redelivery (retries, or a redelivery to another node) is answered exactly
once — no double billing, no double reply. Each adapter therefore must supply a
platform-stable unique message id as event_id (e.g. Mattermost post_id); a
content hash is not acceptable (it would drop a legitimately repeated message).
The claim is taken before the acknowledgement. If the durable claim store is
unreachable, the bridge fails closed: it answers 503 temporarily_unavailable and
processes nothing (counted in aig_bridge_claim_failed_total), so a database outage can
never lead to the same event being billed twice. Redeliveries of a claimed event are
answered 200 {"status":"duplicate"} (aig_bridge_duplicate_total).
One residual: if a worker crashes during inference, that single reply is lost (the claim is taken but never delivered) and the user re-asks. Guaranteed delivery is a planned enhancement.
A bridged reply may take up to about 20 minutes (the assistant's 15-minute tool budget, the tool round still running when it ends, and its final answer — a code-interpreter run alone may take a minute); the platform is acknowledged immediately and the reply is posted when it is ready.
The "still working" status on a long turn
A turn that is still running about 15 seconds after the assistant starts working on the message gets one short status message in the same place the answer will go (the same DM, or the same thread), in the asking user's language: "Working on it. This can take a few minutes; the answer will appear here." (German: "Ich arbeite daran. Das kann einige Minuten dauern; die Antwort erscheint hier."). A turn that answers within 15 seconds posts no status at all.
When the answer is ready it is posted as a new message, and the status message is then rewritten in place to "The reply is below." ("Die Antwort steht unten."). The bridge never deletes the status message. Rewriting it keeps the thread readable without a dangling "working" line, and it needs no permission beyond the ones the bot already has to post. If the answer cannot be posted, the status is rewritten to the "try again" notice instead.
| Platform | Status post | Rewrite | Extra scopes |
|---|---|---|---|
| Mattermost | POST /api/v4/posts |
PUT /api/v4/posts/{id}/patch (the bot's own post) |
none |
| Slack | chat.postMessage |
chat.update (the bot's own message) |
none (chat:write as before) |
| Microsoft Teams | Bot Connector send activity | Bot Connector updateActivity (PUT .../activities/{id}) |
none |
Things to know:
- A long turn notifies twice: once for the status message and once for the answer. The rewrite is an edit and does not notify again.
- The answer can be delayed briefly if the status post is still in flight when the answer is ready (the bridge waits for that post to finish so it knows which message to rewrite). This is typically a few seconds, bounded by the platform request timeouts.
- A status failure never affects the answer. If posting or rewriting the status fails (platform error, timeout, rate limit), the answer is delivered exactly as without a status; at worst the status line stays as "Working on it".
- Message ids are validated before use, because they come from the platform's response: a Mattermost post id is
26 characters of
a-z0-9; a Slack messagetsis<digits>.<digits>(at most 32 characters); a Teams activity id is 1 to 128 characters of letters, digits and: - _ . @. An absent or malformed id means no edit is attempted; the answer is still delivered.
Configuration — per tenant, in the database
The bridge is configured per tenant, not per deployment: one row per workspace in
chat_bridge_connection, so org A and org B each point their own Mattermost/Teams/Slack
workspace at their own agent. config.resolve(platform, workspace_key) looks the inbound
event's workspace up in that table — the environment is no longer the source of truth.
Each connection carries: the owning tenant_id + gateway_id, the platform and
workspace_key (the lookup key), the tenant's chosen default_agent_id, the bot's own
bot_self_id (echo guard), the enabled flag, the allow_web_search opt-in (default 0 —
see Web search opt-in), the allow_egress opt-in (default 0 —
see Full-tool opt-in), and — encrypted at rest with the AES-256 master key — the
platform credentials blob ({secret, bot_token, base_url}) and a dedicated loopback invoke
service token (a user_id IS NULL gateway token, in its own encrypted column so a
bot-token rotation can't clobber it and the token is never exposed in the creds blob).
- Ownership boundary.
UNIQUE(platform, workspace_key)means one connection owns a workspace globally, so an inbound event resolves to exactly one tenant's config (Mattermost caveat: its team ids are unique only within one Mattermost server, so the reservation is first-come per(platform, workspace_key), not a globally trusted proof of ownership; see Mattermost). Theworkspace_keymatch is byte-exact everywhere (connection lookup, thread map, event dedup): no trailing-space padding and no case folding, soT1andT1are different keys. The per-connectionsecret(checked by the adapter'sverify) remains the real confidentiality boundary. The target gateway must bepurpose='production'to route. - Two values are deployment-global, because they are identical for every tenant and not
secret: the bridge's public host and the internal loopback target the invoke call uses. Your
operator sets the public host and enables the bridge for the deployment; on the hosted
environments the invoke call always goes to the gateway's own listener inside the host (never
over the public internet), and a development installation names an explicit local loopback
address instead. The public host doubles as the origin of the
Mattermost native-slash-command Request URL (
https://<host>/chat-bridge/mattermost/slash), so it is the single source of truth for the bridge's public host. - Resolve cache. Because
workspace_keyis attacker-controlled and resolution runs per inbound event, results are cached in two separate per-node shared dicts: a positive cache of the encrypted row (30 s) and a separate negative cache (10 s) so a flood of unknown keys cannot evict live entries. A connection create/delete updates the known-workspace list and the cache immediately on the instance that handled it; other nodes converge within 10 s. After a database fault the lookup backs off for 2 s instead of hammering the database. - Managing connections. Creating and removing connections is a tenant-admin, self-service
operation (API + UI). The
chat_bridge_connectionrow is the sole config source: a transitional per-platform fallback was removed, so a workspace with no enabled row resolves tonot_configured→403(fail-closed).
Managing connections — the tenant-admin API
Creating and deleting a connection each write one audit entry (chat_bridge.connection_created / chat_bridge.connection_deleted) in the same transaction as the change; a failed audit write rolls the change back. See Audit log.
If the audited unit is refused before anything was written (for example a database lock wait that times out), create and delete answer 503 and are safe to retry. Any other failure of the audited unit answers a sanitised 500 with no detail. After a 500 or a dropped response on create, the outcome is unknown: list the connections to see whether the row exists, and if it does and you did not intend it, delete it and create it again.
A tenant-admin manages their own connections through /admin/v1/chat-bridge/connections
(also surfaced in the SPA under Chat Integrations). Every route requires the permission
MCP_TENANT_MANAGE (a tenant-admin permission); without it the answer is 403. It cannot be granted to a custom role (held by tenant admin / admin only). The owning tenant_id is always derived from the caller's session, never the request
body. Credentials are write-only — no response ever returns bot_token, secret,
base_url, or the encrypted blobs.
| Method + path | Purpose | Accepted → Rejected |
|---|---|---|
GET /chat-bridge/platforms |
the platform picker list — { "platforms": [ { "name", "active" }, … ] }, active-first then alphabetical. Filtered to the active set (the active_chat_platforms setting, default ["mattermost"]) for a non-platform-admin; a platform admin sees every platform flagged active/inactive. Served (not filtered client-side) because the picker's tenant admins cannot read /settings. |
— |
GET /chat-bridge/connections |
list this tenant's connections (masked); 200 with an array ([] when none) |
— |
GET /chat-bridge/connections/{id} |
one connection (masked), tenant-scoped | unknown, other tenant's, deleted or malformed id → 404 { "error": "not found" } (recorded as an access.denied security event) |
POST /chat-bridge/connections |
create; 201 with the masked row |
see below |
PATCH /chat-bridge/connections/{id} |
enable-toggle / opt-ins / default agent / rotate a secret; 200 with the masked row |
unknown, other tenant's, deleted or malformed id → 404 { "error": "not found" } (recorded as an access.denied security event, also when the connection is deleted concurrently); see below |
POST /chat-bridge/connections/{id}/provision-slash |
(re)provision the Mattermost native slash commands | unknown or another tenant's id → 404 { "error": "not found" } (recorded as an access.denied security event); Slack/Teams → 400 platform_no_slash; rate → 429 rate_limited |
DELETE /chat-bridge/connections/{id} |
remove (revokes the service token first); 200 { "deleted": true } |
unknown, other tenant's, deleted or malformed id → 404 { "error": "not found" } (recorded as an access.denied security event) |
Create, a credential rotation on PATCH and provision-slash share one per-tenant rate limit of 30 requests per
60 seconds; over it the answer is 429 { "error": "rate limited", "code": "rate_limited" }; provision-slash also
answers 400 { "error": "platform has no native slash commands", "code": "platform_no_slash" }. An id that names no
connection of your tenant answers 404 { "error": "not found" } whether it never existed or belongs to another
tenant (byte-identical), and is recorded as an access.denied security event.
Every /chat-bridge/connections… route (not /chat-bridge/platforms) takes its tenant from the caller's
session and accepts no tenant_id. A caller with no tenant, any role and platform administrators included,
is refused with 403 { "error": "forbidden", "code": "caller_has_no_tenant" } before anything is read, written or
rate-limited; like every admin 403 it is recorded as an access.denied security event.
Storage faults on these routes follow Storage faults: a failed read
before anything is written (the connection, the gateway, the agent, the workspace-uniqueness check) is
503 { "error": "temporarily unavailable; retry later" }. An update (PATCH, any field: enabled,
allow_web_search, allow_egress, a credential rotation, the default agent) that wrote nothing — the row was busy
(bounded wait of about 5 s), every attempt conflicted, or the statement was never sent — is the same 503 and is
safe to retry (see the default-agent paragraph below). Any other failed write (creating or deleting the connection,
minting or revoking its token, an update with an unknown outcome, a crypto or configuration fault) is the sanitised
500 { "error": "internal error", "request_id": "…" }.
Provision-slash (Mattermost only). Idempotent, non-destructive: the gateway lists the workspace's
custom commands and, per trigger (agent, agents), adopts an existing command whose trigger and
URL match the bridge slash endpoint (regenerating its token) or creates a fresh one, then stores the
resulting verification tokens on the connection. It never deletes a command and never touches one whose
URL is not the bridge endpoint. The Mattermost API responses are treated as untrusted input: a command
id is validated (26-char [a-z0-9]) before it is used in any URL, tokens are shape-checked, and no
response body is logged. Returns 200 { "provision": { "agent": <reason>, "agents": <reason> } } where
each reason ∈ ok | public_url_unconfigured | mm_forbidden | mm_unreachable | mm_bad_response |
trigger_taken; a non-ok reason is not an HTTP error (the connection stays usable). Requires the
bot's manage_slash_commands permission and Enable Custom Slash Commands on the Mattermost server;
mm_forbidden signals one of those is missing. The public Request URL is derived from the deployment's
public bridge host (https://<host>/chat-bridge/mattermost/slash); when that host is not configured the reason is
public_url_unconfigured.
Create body: { platform?, workspace_key, gateway_slug, default_agent_slug,
allow_web_search?, allow_egress? } plus the selected platform's credential fields (below). platform is optional and defaults to mattermost only when the key is absent; a present value that is not a supported platform string (an unknown name, "", null, a number or an object) is 400 with code: "invalid_field" and field: "platform". agent_slug is accepted as an alias of default_agent_slug on create only. default_agent_slug (or the alias) is validated like on PATCH: a present value that is not a non-empty string of at most 255 characters (including null) is 400 invalid_field:default_agent_slug (invalid_field:agent_slug for the alias); when both are absent the create is 400 missing required field. If the caller's tenant has been deleted, create answers 403 { "error": "forbidden", "code": "tenant_deleted" }. The owning tenant
and the bot's own id (bot_self_id, the echo guard) are derived server-side — never sent. Each
adapter DECLARES a provisioning spec that validates its own fields fail-closed; the credential
shape lives in exactly one place per platform. A missing workspace_key, gateway_slug or default_agent_slug is 400 missing required field (code: field_required); a present but wrong-typed workspace_key or gateway_slug keeps the same missing required field text but carries code: invalid_field (key off code, not the text); any other invalid field is a 400, a platform that
cannot be reached while verifying the bot is a 502, and a workspace that is already configured is a 409 (see Error codes). After the request-field checks, create checks in this order and answers the first failure: the platform, the workspace_key, the credentials and the bot verification, the workspace ownership proof, the gateway, the default agent, then whether the workspace is already configured. So an unknown gateway_slug sent with credentials the platform rejects answers bot_verification_failed.
Shared fields (every platform):
| Field | Accepted | Rejected → status |
|---|---|---|
platform |
"mattermost", "slack", or "teams" |
any other → 400 invalid_field |
gateway_slug / default_agent_slug |
an agent that belongs to a gateway in the caller's tenant | unknown → 400 invalid_field (gateway_slug) or 400 agent_not_found (default_agent_slug) |
workspace_key |
per-platform charset (below), at most 191 bytes; not already configured | bad → 400 (also invalid UTF-8, a control / invisible formatting character, or leading / trailing whitespace, ASCII or a Unicode space separator such as NBSP / U+3000 → bad_workspace_key); duplicate → 409 |
allow_web_search |
optional boolean (default false) — owner opt-in letting the bot use web search (only that egress tool) |
non-boolean → 400 invalid_field |
allow_egress |
optional boolean (default false) — owner opt-in giving the bot its agent's full tool set (all tools; supersedes allow_web_search). See Full-tool opt-in |
non-boolean → 400 invalid_field |
| rate | per-tenant limit on the create/rotate | exceeded → 429 rate_limited |
Error codes
Every 4xx of the connection routes, and every 502, carries a top-level code next to the unchanged error text and status; a field names the offending body key where exactly one is at fault. Key off code, not the prose.
code |
Status | field |
Meaning |
|---|---|---|---|
field_required |
400 |
the key | A required field is absent, null or "". |
invalid_field |
400 |
the key | A field is present but has a wrong type or value. For an optional field (and default_agent_slug on PATCH) a present null is also invalid_field; so is an optional credential field (for example slash_token) sent at create as null, "" or a non-string. Only an absent optional field is skipped. |
unknown_field |
400 |
the key (capped) | The body names a key the route does not accept. |
read_only_field |
400 |
the key | PATCH names a field that cannot change after create (for example workspace_key). |
nothing_to_update |
400 |
none | PATCH carries no updatable field. |
malformed_body |
400 |
none | The body is not valid JSON, not valid UTF-8, not a JSON object (a scalar, null or array), or holds a number that is not finite. The error text names which (request body is not valid JSON, request body is not valid UTF-8, request body must be a JSON object, request body contains a number that is not finite (NaN / Infinity / out of range)); an absent body is read as {}. |
agent_not_found |
400 |
none | The gateway has no agent with that slug. |
agent_external |
400 |
none | The agent is external and cannot be bridged. |
bot_verification_failed |
400 |
none | The platform answered, but the bot could not be verified. The error text is derive_invalid (or bot_self_id too long) and stays as it is; key off code. |
workspace_already_configured |
409 |
none | The workspace already has a connection. |
workspace_ownership_failed |
400 |
none | The platform did not prove that these credentials belong to the workspace_key, or the proof could not be evaluated. Create and credential rotation both run the proof before anything is stored; a rotation that fails it changes nothing, including any enabled sent in the same request. A flags-only PATCH does not run it. Slack declares the proof: the gateway calls Slack's auth.test with the candidate bot token and requires the returned team_id to equal workspace_key exactly. A different workspace answers this 400; a response that is unreadable, not ok, or carries a missing or malformed team_id is not proof and answers the 502 platform_unreachable instead. On create the proof runs before the duplicate check, so a token from another workspace never learns whether workspace_key is already configured. A rotation of only the signing_secret re-proves the stored bot token. Microsoft Teams declares the proof too: the gateway makes a fresh Entra client-credentials token request at <authority>/<workspace_key> with the candidate bot_app_id and client_secret and the Graph scope, never reading or filling the shared token cache. The token must carry tid equal to workspace_key, appid (or, only when appid is absent, azp) equal to the candidate bot_app_id, a matching issuer, an unexpired exp, and a non-empty roles claim (proof that an admin consented to the app in that tenant). Entra refusing the request (400/401), a token for another tenant, or a token without roles answers this 400. A transport error, a 5xx/429, an unreadable body or token, an absent or malformed tid, a mismatching appid/azp (including a present non-string appid), an issuer outside the tenant's issuer set, an absent exp, an expired token, an nbf in the future, or an Entra 403/404/other non-2xx (other than 400/401) is not proof and answers the 502 platform_unreachable. Rotating the client_secret re-proves the new secret against the stored bot_app_id. Any other platform that declares no proof is not checked: Mattermost declares none (its workspace_key is only format-validated). |
platform_unreachable |
502 |
none | The platform could not be reached while verifying the bot (error is could not reach the chat platform to verify the bot), or while verifying workspace ownership (error is could not reach the chat platform to verify workspace ownership). Retry later; nothing was stored. |
tenant_deleted |
403 |
none | The caller's tenant has been deleted. |
rate_limited |
429 |
none | The per-tenant limit above. |
invalid_request |
400 |
none | Defensive fallback for a refusal with no more specific code. |
How the web app presents these. The Add chat connection and rotate pages map a refusal to a specific message only when the status and code match the table (workspace_ownership_failed with 400, workspace_already_configured with 409, platform_unreachable with 502, bot_verification_failed with 400, invalid_field / field_required with 400 and field: "workspace_key"). An absent code falls back to the frozen error sentinel (a string, or the nested {"error":{"code"}} shape); a present but malformed or unknown code, or a status that does not match, gets the generic create or rotate failure text. English and German texts are provided.
PATCH checks in this order: immutable keys (read_only_field), the default_agent_slug type, the credential rate limit, and flag types / nothing_to_update run before the connection lookup; unknown or non-rotatable credential keys are checked after it, so on an unknown or another tenant's id they answer the audited 404 (identical for both).
Unknown, foreign, deleted and malformed ids on GET, PATCH and DELETE are the plain 404 { "error": "not found" } above and carry no code.
Mattermost — credentials { base_url, bot_token, secret }; workspace_key = the MM team id. The
slash_token / slash_list_token (for the /agent and /agents native slash commands) are
auto-populated by the gateway on create — it registers the commands via the Mattermost API and
captures their tokens (see Provision-slash above). They may still be supplied explicitly at create or
rotated via PATCH (write-only), but you no longer create the commands by hand.
| Field | Accepted | Rejected → status |
|---|---|---|
base_url |
an https URL that resolves to a public IP | http://, a private/link-local/metadata IP, or a non-resolvable host → 400; the gateway can't reach the Mattermost API → 502 |
workspace_key |
the Mattermost team id: exactly 26 characters of [a-z0-9] |
a malformed string (wrong length, uppercase, a hostname) → 400 invalid_field:workspace_key (bad_workspace_key), checked before any call to Mattermost; a non-string (number, array, object) → the generic 400 invalid_field ("missing required field" text); absent, null or "" → 400 field_required |
bot_token / secret |
any non-empty string (write-only) | missing → 400 |
slash_token / slash_list_token |
optional — the Mattermost-generated tokens for the /agent and /agents native slash commands (write-only); may be set at create or added later via PATCH (see Native slash commands) |
present-but-empty, null or non-string → 400 (at create and on PATCH) |
base_url is tenant-supplied and fetched server-side (at create and on every inbound event),
so it is SSRF-guarded: https-only, the connect IP is pinned after a private-range check, and the
operator allowlist is not honoured for tenant URLs. On create the gateway calls GET
/api/v4/users/me only to derive the bot's own id (the echo guard) — it does not treat that
call as proof of workspace ownership; the per-connection secret remains the real confidentiality
boundary. This SSRF gate + get_me run only on the Mattermost path.
Mattermost declares no workspace-ownership proof, so the 26-character check is a format check, not proof
that the credentials belong to that team: the per-connection secret stays the confidentiality boundary.
Mattermost team ids are unique only within one Mattermost server, so neither the format check nor the bot token
working against the administrator-supplied base_url (GET /users/me) is a globally trusted ownership proof.
The key is reserved first-come per (platform, workspace_key) and released when that connection is deleted;
a conflicting reservation is resolved by Myra support (there is no automatic takeover or transfer). Migration
0139's header comment "proof-of-ownership at create" is historical: today only Slack and Teams declare a proof.
Inbound, the gateway selects the connection from the relay's workspace_key (or the slash command's team_id)
and, after the secret is verified, processes and deduplicates the event under the workspace of that connection
(its own workspace_key), never a value carried in the request body, so a body naming another team cannot bind the
event, its dedup claim or its thread to that team. A slash command is a separate flow: the gateway verifies the slash
token of the connection selected by team_id; it neither claims nor deduplicates an event. An absent, empty or non-string key answers 403, and so does an
unknown, foreign or malformed key (opaque, no distinction).
Connections created before this check with a key that is not a 26-character id keep their reservation and inbound routing, but cannot send approval DMs (those need a real team id in a URL path). Recreate such a connection with the real 26-character team id (deleting the old row releases the reservation).
Existing connections keep their reservation. Myra support can check on request whether an existing connection's credentials still belong to its workspace; nothing is changed automatically.
Slack — credentials { signing_secret, bot_token }; workspace_key = the Slack team id.
bot_self_id (the bot's own U… user id) is derived via auth.test, which also verifies the
token. There is no base_url — the Slack Web API host is the fixed https://slack.com constant.
| Field | Accepted | Rejected → status |
|---|---|---|
workspace_key |
^[A-Z0-9]+$, ≤ 191 |
else → 400 |
signing_secret / bot_token |
any non-empty string (write-only) | missing → 400; token not usable via auth.test → 502; token from another workspace → 400 workspace_ownership_failed |
Microsoft Teams — credentials { bot_app_id, bot_app_type, bot_home_tenant_id, client_secret,
service_url }; workspace_key = the Entra tenant GUID. It must be the lowercase tenant GUID: a non-GUID or uppercase key is refused with 400 bad_workspace_key before any token request. Create and credential rotation are then
refused with 400 workspace_ownership_failed unless Entra proves the credentials belong to that tenant (502 platform_unreachable when it cannot be proven; see the error codes). bot_self_id = 28:<bot_app_id>
(derived, no network).
| Field | Accepted | Rejected → status |
|---|---|---|
workspace_key / bot_home_tenant_id / bot_app_id |
a canonical Entra tenant / app GUID (workspace_key and bot_app_id lowercase) |
non-GUID → 400; an uppercase bot_app_id → 400 invalid_field:bot_app_id (Entra's appid and the inbound token aud are lowercase and compared byte-exact); for workspace_key, a non-GUID or uppercase value is 400 bad_workspace_key (checked before any token request) |
bot_app_type |
"multitenant" or "singletenant" |
any other → 400 |
service_url |
a Bot Connector host (*.botframework.com / smba.trafficmanager.net) |
any other host → 400 |
client_secret |
any non-empty string (write-only) | missing → 400 |
The Graph / AAD / JWKS hosts are the fixed Microsoft public-cloud endpoints (dev base overrides are honoured only when operator-allowlisted, empty in prod), so a tenant admin cannot redirect the trust root or egress.
Patch accepts { enabled } (toggle), { allow_web_search } (web-search opt-in toggle, a
boolean — non-boolean → 400), { allow_egress } (full-tool opt-in toggle, a boolean —
non-boolean → 400), and a per-platform secret rotation: Mattermost { bot_token } and/or the
optional { slash_token } / { slash_list_token } (the native slash-command tokens — set or rotate
them here);
Slack { bot_token } and/or { signing_secret }; Teams { client_secret }. A patch carrying only
allow_web_search or only allow_egress is valid and takes effect immediately (within the ~30 s
config-cache TTL), and is not treated as a credential rotation (so it is not rate-limited). Every other field — workspace_key,
gateway_slug, gateway_id, agent_slug, platform (answer 400 <field> cannot be changed after create), and any non-rotatable credential (Mattermost
base_url/secret; Teams bot_app_id/bot_app_type/bot_home_tenant_id/service_url) — is
immutable after create: a body carrying one is a 400, never a silent ignore. The one identity-like field that can change is the default agent:
{ "default_agent_slug": "<slug>" } (a non-empty string of at most 255 bytes; any other type, "" or null is
400 invalid_field:default_agent_slug) re-targets the connection to another agent. The slug is resolved on the
connection's own gateway (never a body field) and must be an agent in the caller's tenant that the caller may use
(owner, tenant admin or admin), that runs as a model agent, is not blocked by a governance review and is not paused
(hand-over or automatic protection). Every refusal except an externally hosted agent (400 agent_external) is the same
400 agent_not_found, so the response is no oracle for other agents. It is not a credential rotation (not rate-limited) and
is applied before any rotation in the same body. The caller needs the same permission as every other chat-bridge route
(MCP_TENANT_MANAGE). Each change is audited as chat_bridge.default_agent_changed (connection, platform, old and new agent,
actor). The change and its audit row commit together: if the audit row cannot be written the
default agent is not changed — 503 temporarily unavailable; retry later when nothing was written
(for example a busy row, bounded at about 5 s; safe to retry), otherwise the sanitised 500. A rotation
decrypts the stored blob, swaps only the named secret(s) (the rest is preserved), and
re-encrypts. It does not change bot_self_id — a rotation is a new credential for the same
bot; changing the underlying bot is a delete + recreate, not a rotation. The resolve cache is
invalidated so the new secret takes effect immediately on that node (others converge within the 30 s TTL).
A credential rotation must first pass the platform's workspace-ownership proof (where a platform declares one) before anything is written; see the workspace_ownership_failed row of the error codes. A flags-only PATCH is not a rotation and makes no call to the platform.
If the stored bot token has since been revoked or become invalid, a rotation of only the signing_secret re-proves that stored token, answers 502 and changes nothing; rotate bot_token and signing_secret together. A rotated bot_token must belong to the same Slack app and bot user: the stored echo-guard bot_self_id is kept on rotation.
Mattermost adapter
The Mattermost adapter delivers the natural DM + @mention experience. Because the
gateway is inbound-HTTP only, a small relay service (holds the Mattermost bot
websocket) forwards events to POST /chat-bridge/mattermost/events as a normalized
JSON body:
{ "secret": "…", "workspace_key": "<team id>", "user_id": "<26-char id>",
"channel_id": "<26-char id>", "is_dm": true, "root_id": "", "post_id": "<26-char id>",
"text": "<message, @mention-stripped>" }
- What the relay forwards — exactly
{direct messages to the bot}∪{messages that @mention the bot in a channel the bot is a member of}, mention-stripped, nothing else (a bot only receives websocket events for its DMs and channels it has joined; a channel post that doesn't address the bot never bills an inference). A 1:1 DM is always to the bot; a group DM or channel requires an explicit@<botusername>token in the message text every turn. This decision is made from the message TEXT, not Mattermost's server-sidementionsnotify-list — for a@channel/@here/@allbroadcast the server expands that list to every online member including the bot's own id, so a notify-list gate made the bot answer broadcasts nobody addressed to it. A broadcast is therefore ignored; only a post that literally names@<botusername>engages the bot. It stampsworkspace_keywith its configured team id (Mattermost DMs carry no team id) and drops the bot's own + system posts. - Threading — a DM keys the conversation by its channel (the 1:1/group channel is the conversation); a channel @mention roots a thread and the reply is posted in it.
- Identity — the adapter resolves
user_idto an email viaGET /api/v4/users/{id}. The directory email is trusted (Mattermost returnsemail_verified: nullfor admin-provisioned/SSO users, so anemail_verified == truegate would reject them — the adapter checks email presence, not that flag). The deployment must run withShowEmailAddress = true(or a system-admin bot token) so that endpoint returnsemail; otherwise every user is silently unmapped. Required bot capability: read users + create posts. For approval DMs the bot must also be a member of the holder's team, be allowed to read the holder's email (see above) and be allowed to create direct channels.
Security — the relay secret is a tenant-wide credential
The secret is the sole authenticator and the relay asserts user_id, so a holder
of the secret can drive inference as any mapped gateway user in that tenant, from the
public endpoint. It is compared constant-time (SHA-256 of both sides) and must be a
high-entropy, rotated value carried only in the request body (which is therefore
never logged). The relay→gateway hop must be network-restricted (IP-allowlist or
mTLS on /chat-bridge/*); do not rely on the body secret alone over the open vhost.
Mattermost connection fields
A Mattermost connection carries workspace_key (team id), the tenant's default_agent,
bot_self_id (the bot's MM user id, for the echo guard), and the encrypted credentials
{ secret, bot_token, base_url } — plus, optionally, the two native slash-command tokens
{ slash_token, slash_list_token } (see Native slash commands below). These are stored in
chat_bridge_connection (see Configuration — per tenant above), set via the tenant-admin API
. Every known adapter is registered unconditionally at worker boot — the endpoint is
always live, and a workspace with no configured connection simply fails closed with a 403. The websocket relay + its secret/token provisioning ship
with the relay service.
Native slash commands — /agents + /agent
The DM agent picker (above) is a plain message directive (!agents / !agent <name>), because the
Mattermost client intercepts a /-prefixed message. It additionally supports real, registered
Mattermost slash commands for the same picker, on a separate synchronous endpoint (not the
websocket relay):
POST https://ai-api.myra.eu/chat-bridge/mattermost/slash
Content-Type: application/x-www-form-urlencoded
token=<command token>&command=/agent&text=<name>&team_id=<team>&channel_id=<dm>&user_id=<user>&…
A tenant admin creates two custom slash commands in Mattermost — /agents (list) and /agent
(pick/show) — both pointing at this URL with request method POST, then copies each command's
Mattermost-generated token into the connection (slash_list_token for /agents, slash_token
for /agent) via a PATCH (see Managing connections). Until both tokens are set the endpoint fails
closed (403) for the unconfigured command, while the relay and the ! directives keep working.
The reply is ephemeral (only the invoking user sees it), and uses the same picker grammar and
per-user entitlement gate as the ! path — there is no second command parser. The reply text
advertises the native / form.
| Command (Mattermost) | Effect |
|---|---|
/agents |
List the assistants this user may pick. |
/agent <name> |
Switch this DM to <name>. |
/agent |
Show the current assistant + usage. |
Accepted request shape (the whole body is untrusted until the token verifies — fail closed):
| Part | Accepted | Rejected → status |
|---|---|---|
| Method | POST only |
any other → 405 |
| Path | /chat-bridge/mattermost/slash |
other platform → 404 |
| Body | application/x-www-form-urlencoded, ≤ 32 KB |
> cap → 413 (edge answer {"error":"payload_too_large"}, no code) |
team_id |
a non-empty string that resolves to an enabled connection (it is the workspace_key) |
empty / unknown → opaque 403 |
token |
must equal a configured slash token (slash_token or slash_list_token) for that connection, constant-time compared |
missing / mismatch / none configured → opaque 403 |
| Rate | per-(mattermost, team) sliding window (its own budget, separate from /events); no per-IP limit; checked right after the token, before the fields are read |
exceeded → 429 |
command / user_id / channel_id / text |
each form field at most once, with a value if present (text may be empty) |
a repeated field → 400 {"code":"duplicate_key"}; a field sent with no =value → 400 {"code":"malformed_body"} (both only after the token verified, and alerted as bridge_body_refused, see Inbound event body) |
command / user_id / channel_id |
non-empty strings; channel_id ≤ 191 chars (the DB thread-key column width) |
missing / empty / channel_id > 191 → opaque 403 |
text |
optional (empty for /agents and bare /agent) |
— |
Identity, binding, execution are identical to the message path: the user_id is resolved to a
tenant-pinned gateway user (fail-closed, Art. 18 / viewer gated); an unmapped / restricted user gets a
localized ephemeral, never silence. The pick binds the same DM conversation the relay uses
(thread_key = channel_id), so it controls the relay DM's agent. The endpoint performs no
inference — it only lists or switches — so no egress happens here.
The picker is for direct messages. A slash command carries no channel-type signal, so the endpoint
does not distinguish a DM from a shared channel without an extra API round trip it deliberately avoids
(to stay inside Mattermost's short slash-command deadline). Invoked in a shared channel it binds a
per-user conversation keyed on that channel that the relay's channel threads (keyed on
channel_id:root) never consult — so the selection is effectively a no-op for that channel, and a
second user's invocation is refused fail-closed. Use /agents / /agent in a DM with the bot.
Precondition — register the commands in the connection's team. A Mattermost custom slash command is team-scoped, and the connection's
workspace_keyis that team id (unique across connections on the gateway, first-come; Mattermost team ids are only unique per Mattermost server, so this is not an ownership proof). Register/agents+/agentin the same team the bot serves; a command invoked from a different team sends a differentteam_id, which resolves to no connection and fails closed (403) — it can never bind or act across tenants.Security note — the slash token is an impersonation-grade credential. Unlike the relay hop, this endpoint must be internet-reachable (Mattermost's servers POST to it), so it cannot be network-restricted; the token is the boundary. The form's
user_idis asserted by the caller and identity is derived from it, so a leaked slash token lets a holder act as any workspace user for the picker: enumerate that user's visible agent names and rebind their DM's agent. It grants no inference or tool egress (strictly less than the relay secret), but treat it with the same care — keep it secret, rotate it (viaPATCH), and never log it. The gateway compares it constant-time and never logs the token; a rejected request emits one greppableslash token rejectedWARN with the workspace only.
Slack adapter
The Slack adapter delivers the DM + @mention experience over the Slack Events API (inbound HTTP — not Socket Mode). Slack itself POSTs every event to the one public Request URL; there is no relay or websocket. The tenant configures their Slack app's Request URL as:
- The
?ws=<team_id>query is required. Slack'surl_verificationhandshake body carries noteam_id, so the workspace is taken from the Request-URL query (Slack preserves the query string on every delivery, including the handshake and retries).team_idIS the storedworkspace_key. Thewsvalue is only a resolution hint — it is attacker-controlled and is not a trust boundary; the request signature is the sole authenticator.
Request signing — the only trust boundary
Every request must carry a valid Slack request signature:
| Header | Meaning |
|---|---|
X-Slack-Signature |
v0=<hex> — HMAC-SHA256(signing_secret, "v0:" + timestamp + ":" + raw_body) |
X-Slack-Request-Timestamp |
unix seconds; rejected if more than 5 minutes from now (replay guard) |
The signature is verified over the raw request body exactly as received, constant-time,
against the tenant's signing_secret, before the body is parsed. A wrong/forged ws
selects a wrong-or-absent signing secret, so the HMAC fails and the request is rejected. An
unknown workspace, a disabled connection, and a bad signature all return the identical opaque
403 {"error":"forbidden","code":"forbidden"} — the endpoint is not a tenant-existence oracle, and the
url_verification challenge is echoed only for a correctly-signed request.
| Part | Accepted | Rejected → status |
|---|---|---|
?ws= |
uppercase-alnum team id that resolves to an enabled Slack connection | missing / bad / unknown → 403 |
| Signature | valid v0= HMAC over the raw body, fresh timestamp |
absent / malformed / stale / mismatch → 403 |
| Event | event_callback with a message in a DM (channel_type:"im") or an app_mention in a channel, or a url_verification handshake |
anything else — a plain channel/group message with no @mention, bot echo, edits/joins, other types → ignored 200 |
Events, threading, identity
- What's handled — direct messages to the bot (
messagewithchannel_type:"im") and channelapp_mentions. A plainmessagein a public/private channel or group DM (no@mention) is deliberately ignored — otherwise the bot would answer (and bill) every message in any channel it is a member of; the Slack app's event-subscription config is treated as the client, never the admission boundary. The bot's own posts are dropped (bot_idpresent, or the author is the bot's own user id) so it never answers itself; any messagesubtype(edits, joins, bot messages) is ignored. The leading<@bot>mention is stripped from the text. - Threading — a DM keys the conversation by its channel (the DM is the conversation, reply
un-threaded); a channel
app_mentionroots a thread atthread_ts(fallbackts) and the reply is posted in that thread. - Dedup — Slack's top-level
event_idis the durable de-duplication key, so a Slack retry is answered exactly once. - Identity — the adapter resolves the Slack user to an email via
users.info(the bot needs theusers:read.emailscope). Slack emails are workspace-managed (SSO/enterprise) so the directory email is trusted, then looked up only within the connection's tenant — the same fail-closed, tenant-pinned mapping as every adapter. Only members of the connected workspace are mapped: theusers.inforecord must carry ateam_idbyte-equal to the connection'sworkspace_keyand must not be flaggedis_stranger. A Slack Connect guest from another organisation (foreignteam_id, oris_stranger: true) whose profile email happens to match a tenant user is not mapped — they get the same "not linked" (unmapped) reply as any unknown user, with no agent run. An absent or malformedteam_id, or a malformedis_stranger, is refused too (fail closed); only an absent orfalseis_strangeris accepted. The refusal reason is logged (not_workspace_member: <reason>), never the email.
Slack connection fields
A Slack connection carries workspace_key (the Slack team_id), the tenant's
default_agent, bot_self_id (the bot's own Slack user id U…, for the echo guard), and
the encrypted credentials { signing_secret, bot_token }. The Slack Web API host is the fixed
https://slack.com constant — it is never taken from tenant config (Slack has no per-tenant
host; a tenant-supplied host would be an email-forgery / SSRF vector), so no base_url is stored
for Slack.
Workspace-ownership proof: it runs at create and on every credential rotation (including a rotation of
only the signing_secret), with 2 auth.test calls on create and 1 on rotation, before the duplicate
check. An unproven request therefore learns nothing about whether the workspace is configured; a
proven duplicate is still a 409.
A tenant-admin creates a Slack connection through the self-service API/UI (see Managing
connections), which stores exactly the {signing_secret, bot_token} shape and derives
bot_self_id via auth.test. The adapter is also exercised end-to-end via the
dev-instance Slack E2E harness.
Teams limitations
bot_home_tenant_idequal toworkspace_keyis not proof. Ownership rests on the uncached Entra token request, not on that equality.- Admin consent is required. A token without application
rolesis refused, so the app must be consented in the customer tenant before the connection can be created or its secret rotated. - Public cloud only. National clouds (
*.us,*.cn) use different authorities and are not supported.
Slack limitations
- Enterprise Grid org-wide installs are not supported:
auth.testreports the org, not the workspace, so the ownership proof refuses it. Install the app per workspace. - Approval DMs need the scopes
users:read,users:read.email,im:writeandchat:write. An app installed withoutusers:read.emailsends no DM until it is reinstalled with the new scopes. - Enterprise Grid / Slack Connect: the approval DM applies the same workspace-membership rule as
inbound identity: a user whose
team_idis absent, malformed or differs from the connected workspace, or who is flaggedis_stranger, gets no approval DM (fail-closed). - Enterprise Grid / externally-shared channels: an event whose own top-level
team_idis absent or foreign (Enterprise Grid events may carry the identity only underauthorizations[]) is ignored at parse. A foreign-team oris_strangeruser inside a correctly signed event for the connected workspace (shared channel / Slack Connect) is not ignored but refused with the "not linked" reply (see Identity above). Standard single-workspace apps only.
Microsoft Teams adapter
The Teams adapter delivers the DM + @mention experience over the Bot Framework messaging endpoint (inbound HTTP — not websockets, not a relay). An Azure Bot POSTs every Teams message as an Activity to the one public messaging URL; Teams' own routing means the endpoint only ever receives 1:1 (personal) messages and channel @mentions, so there is no admission surface to filter. The tenant points their Azure Bot's messaging endpoint at:
POST https://ai-api.myra.eu/chat-bridge/teams/events
Authorization: Bearer <Bot Framework JWT>
Content-Type: application/json
The workspace is channelData.tenant.id (the Entra tenant GUID) taken from the
Activity body. It only selects the candidate connection — it is unsigned; the JWT's
aud is the real cross-tenant gate.
Inbound JWT — the only trust boundary
Every request must carry a valid Bot Framework JWT in the Authorization: Bearer
header — exactly Bearer <token> (case-insensitive scheme, one space, no whitespace or control
characters in the token, at most 16 KB in the parser — in practice the HTTP front end limits a header line to 8 KB and answers longer ones with 400); a missing prefix, another scheme, extra or different
whitespace, or a repeated Authorization header is rejected before any verification. It is
validated before the body is parsed, fail-closed, using the same RS256
envelope as OIDC login (one shared implementation — RS256 pinned, crit/embedded
jwk/jku/x5u rejected, kid required, RSA ≥ 2048, canonical base64url):
| Check | Rule |
|---|---|
| Signature | RS256 over the token, verified against the pinned Bot Framework JWKS (keys fetched only from the derived well-known URL, SSRF-gated + cached) |
iss |
multitenant → exactly https://api.botframework.com; singletenant → exactly https://login.microsoftonline.com/<bot_home_tenant_id>/v2.0 (or the https://sts.windows.net/<tid>/ v1 form) — never accept-any-tenant |
aud |
must equal the connection's bot_app_id (a distinct bot app id per workspace — the cross-tenant boundary) |
serviceurl |
mandatory; after normalize (lowercase, strip trailing /) must equal the connection's configured service_url — this binds the signed token to our reply target (an SSRF pin: a forged serviceUrl in the body can never redirect our reply) |
exp / nbf / iat |
exp is required; each claim that is present must be a number; exp not more than 300 s in the past, nbf/iat not more than 300 s in the future |
An unknown tenant, a disabled connection, a bad/expired/forged token, a wrong aud,
a wrong issuer, and a serviceUrl mismatch all return the identical opaque
403 {"error":"forbidden","code":"forbidden"} — the endpoint is not a tenant-existence oracle.
The connection declares bot_app_type (multitenant or singletenant); a
bad/missing value is rejected (never accept-any). Single-tenant is supported because
DACH M365 enterprises frequently mandate single-tenant Entra app registrations.
Accepted Activity shape
| Field | Accepted | Rejected → behaviour |
|---|---|---|
type |
"message" |
anything else (conversationUpdate, typing, reactions…) → ignored 200 |
channelData.tenant.id |
a canonical Entra tenant GUID (the workspace) | absent / non-GUID → opaque 403 |
from.aadObjectId |
a canonical GUID (resolved to an email via Graph) | absent / malformed → ignored 200 |
from.id |
any id except the bot's own 28:<bot_app_id> |
the bot's own id (echo) → ignored 200 |
conversation.id |
alnum + : ; = @ . _ - only, ≤ 191 chars |
contains / ? # % / whitespace / control, or > 191 → ignored / temporary reply |
text |
non-empty after <at>…</at> mention markup is stripped |
empty after strip → ignored 200 |
id |
the platform-stable Activity id (durable dedup key): 1–191 characters of A-Z a-z 0-9 : ; = @ . _ - |
missing, empty, non-string, longer than 191 or with other characters → the Activity is ignored (200), never processed without a dedup key |
Threading, identity, delivery
- Threading —
conversation.idis both the conversation-binding key and the reply target (POST <service_url>/v3/conversations/<id>/activities), so there is no separate thread map. A DM's 1:1 conversation id keeps one continuous conversation; a channel @mention's thread conversation id posts the reply in that thread. - Identity — the adapter mints the bot's AAD app-only token and calls Microsoft
Graph
GET /v1.0/users/<aadObjectId>?$select=mail,userPrincipalName(bearer attached only to Graph's fixed host or an operator-allowlisted E2E host, connect-IP-pinned), takingmail(or a routable, non-#EXT#userPrincipalName). The email is then looked up only within the connection's tenant — the same fail-closed, tenant-pinned mapping as every adapter. Precondition: the bot's Azure app holds the GraphUser.Read.Allapplication permission (admin-consented). - Reply — posted via the Bot Connector with a freshly minted Connector app token
(minted from the botframework.com directory for a multitenant bot, or the bot's home
tenant for a singletenant one). The reply is UTF-8-safe-truncated to a Connector-safe
byte budget with a
… (truncated)marker; theservice_urlhost is pinned to*.botframework.com/smba.trafficmanager.net(or an operator-allowlisted host) so a drifted host never receives the bearer. - Dedup — the Activity
idis the durable de-duplication key, so a Bot Framework retry is answered exactly once.
Teams connection fields
A Teams connection carries workspace_key (the Entra tenant GUID), the tenant's
default_agent, bot_self_id (28:<bot_app_id>, for the echo guard), and the encrypted
adapter_config { bot_app_type, bot_app_id, client_secret, bot_home_tenant_id,
service_url }. The Graph / AAD / JWKS hosts are the fixed Microsoft public-cloud
endpoints and are never taken from tenant config in production; dev-only base
overrides (graph_base, aad_authority_base, bf_jwks_uri) are honoured only when
their host is on the operator-configured egress allowlist (empty in
prod), so a tenant admin can never redirect the trust root or egress.
A tenant-admin creates a Teams connection through the self-service API/UI (see Managing
connections), which stores exactly this five-field adapter_config and derives bot_self_id
as 28:<bot_app_id>. The dev-only base overrides above are not accepted by the create
API — they are seed/E2E knobs. The adapter is also exercised end-to-end via the dev-instance Teams
E2E harness (dev-instance.sh teams-bridge-e2e) against a fake Bot Framework (real RS256-signed
inbound JWTs verified against its JWKS).
Teams limitations
- No approval DMs (see Approval DMs): the adapter does not support proactive messages.
- Public cloud only — government clouds (
*.us,*.cn) use different issuers/JWKS hosts and are out of scope. - A conversation id longer than 191 characters exceeds the shared
thread_keycolumn and gets atemporaryreply (widening that column touches the whole bridge core — a separate ticket). - Markdown replies only (
textFormat:"markdown"); Adaptive Cards are not yet emitted.
Approval DMs
When an agent run is held for a tool approval, the holder's approver is notified by email and push as before, and additionally by a direct message in every chat workspace they are connected to (an enabled bridge connection of the same tenant in which their email resolves). The DM is a pointer, not a decision surface:
- It names the agent, the gated tool(s), the due date and whether two approvals are needed, and shows a masked
argument preview only: arguments are shown only for a call stored with
args_masking = masked; a call whose arguments could not be masked contributes its tool name only. Masking redacts personal data and secrets; benign text is shown as masked. - It carries one deep link to
/approvals/tools/<review_id>. There is no approve or reject in chat: the decision is taken in the web app, under the approver's own login. - At most 5 connections are tried per hold within a 15 s budget, at most one DM per platform identity. Delivery is best-effort; a failure is logged as a status token only and never retried inline.
- The match is by email only: the holder's email is looked up on the chat platform, and its trust rests on that
platform's verified/managed identities (SSO is recommended). An unknown, deactivated or
bot account, or one outside the connected workspace, gets nothing (fail-closed). Holders with a test-fixture email
domain (
.test,.invalid,.localhost,.example,.local) are never notified. - Teams is not supported (no proactive-conversation reference is stored): no DM is sent.
- One chat notification per approver. When the hold belongs to a run that was started from a chat thread (see Held for approval above) and the approver is the colleague who asked in that thread, the thread already carries the hold notice, so no DM is sent for that connection. Email and push are unchanged. A hold of any other run (scheduled, web, API), a hold approved by someone other than the asker, and the approver's other chat workspaces keep the DM.
Second-approver DMs
With four-eyes approval, the holder's first approval moves the hold to awaiting second approval and every
eligible second approver (the same people who receive the "Second approval needed" mail and push) additionally
gets a direct message in every chat workspace they are connected to. It uses the one shared sender and the same
rules as the holder's DM (email-only match, fail-closed, test-fixture domains excluded, masked preview only, one
deep link to /approvals/tools/<review_id>, no approve or reject in chat, Teams not supported), with the wording
"approved once, needs your second approval".
- Not suppressed by the chat thread. The asker-thread de-duplication above applies to the holder's DM only; a second approver is always told.
- Shared budget. All second-approver DMs of one hold share one 30 s budget, and the connection list is read once for all recipients. When the budget runs out, the remaining approvers get mail and push only (logged as a warning with the count). The budget is best-effort: a call already in flight when it expires can overrun it by up to one adapter timeout (a few seconds).
- Per-connection breaker. When a chat platform answers a DM with HTTP
429(also from the user lookup, team membership or open-conversation step), or the chat server cannot be reached at all (transport failure), the remaining DMs of that hold through that connection are skipped instead of being sent into the limit or into one timeout per recipient; other connections are unaffected. - Delivery is best-effort and never retried inline; a failure never blocks the decision.
Protection pause DMs
A second DM kind uses the same machinery: when automatic protection pauses an agent, its owner gets a direct message in every chat workspace they are connected to, once per pause (a second detection of an already paused agent sends nothing; a pause after a resume is announced again).
- It carries the same reason text as the pause mail and one deep link to the agent. The agent is resumed in the web app; nothing can be decided in chat.
- Same adapters, caps and dedupe as the approval DMs: email-only match with the same fail-closed rules and test-fixture domain exclusion, at most 5 connections within a 15 s budget, at most one DM per platform identity, best-effort and never retried inline. Teams is not supported.
- On Slack the link is a button whose
action_idis nowopen_link(previously approval-specific); the button only opens the URL.
Third-party responses consumed
| Platform | Call | Accepted | Rejected |
|---|---|---|---|
| Slack | auth.test |
2xx, ok:true (boolean), team_id string ^[A-Z0-9]{1,191}$ byte-equal to workspace_key; user_id ^[A-Z0-9]{1,64}$ (create) |
foreign well-formed team_id → 400 workspace_ownership_failed; transport error, non-2xx, non-object body, ok not true, absent or malformed team_id → 502 platform_unreachable |
| Teams | Entra token endpoint POST <authority>/<workspace_key>/oauth2/v2.0/token (create and credential rotation; fresh, uncached) |
2xx JSON with a decodable access_token whose tid equals workspace_key (lowercase GUID), appid (or, only when appid is absent, azp) equal to the candidate bot_app_id, iss is in the tenant's issuer set, exp is in the future, and roles is a non-empty array of non-empty strings |
Entra 400/401, foreign tid, absent/empty roles → 400 workspace_ownership_failed; transport error, 5xx/429, non-JSON body, no or undecodable access_token, absent/null/non-string/empty tid, appid/azp mismatch (including a present non-string appid), iss outside the issuer set, absent or expired exp, nbf in the future, Entra 403/404/other non-2xx (not 400/401) → 502 platform_unreachable |
| Slack | users.lookupByEmail |
ok:true, user id matching ^[UW][A-Z0-9]+$, boolean deleted:false and is_bot:false, team_id equal to the connected workspace and is_stranger absent or false |
users_not_found (no_user); deleted, bot, other-workspace or is_stranger user; absent, empty or non-string team_id; non-boolean is_stranger (rejected_user); absent or non-boolean deleted/is_bot, malformed id (malformed); any other Slack error (slack_error) |
| Slack | conversations.open |
ok:true, channel id ^D[A-Z0-9]+$ |
anything else |
| Slack | chat.postMessage |
ok:true |
ok:false, non-2xx, transport error |
| Mattermost | GET /api/v4/users/email/{email} |
2xx, 26-char id, numeric delete_at == 0, is_bot absent or boolean false |
404 (no user); deactivated or bot; absent delete_at, non-boolean is_bot, malformed id (malformed) |
| Mattermost | GET /api/v4/teams/{team}/members/{user} |
2xx with user_id equal to the requested user and numeric delete_at == 0 |
403/404, other user id, left the team; absent or non-numeric delete_at (malformed) |
| Mattermost | POST /api/v4/channels/direct |
2xx, 26-char channel id | anything else |
| Mattermost | POST /api/v4/posts |
2xx | non-2xx (status-only error) |
All upstream bodies are untrusted; errors are mapped to status-only tokens and never logged with a body. auth.test logs Slack's error code at WARN after a strict filter (never the body or the token).
Known limitations
- No rich cards yet (replies are text). Per-DM agent switching is supported — see the Agent picker section above.
Numbers in chat-bridge responses are written exactly. If a response cannot be encoded, the endpoint answers 500 with { "error": "internal error", "code": "response_encode_failed" }; see Error codes.