Skip to content
Docs

How to connect a Teams agent

This guide connects Microsoft Teams to your Agent: someone @mentions your agent in a Teams channel, the message triggers a flow, and the agent’s answer is posted back into a channel, with conversation memory per Teams thread.

Unlike Slack and Discord, Teams does not use a socket connection or the gateway service. Teams is a webhook channel: Teams delivers each message over HTTP to a Publicus webhook, the same way Telegram and WhatsApp do. You wire up two webhooks that point in opposite directions:

  • An outgoing webhook in Teams (the trigger): people @mention its name in a channel, and Teams sends the message to your Publicus webhook URL, signed with a shared secret that Publicus verifies on every request.
  • A workflow webhook in Teams (the reply): the flow posts the agent’s answer to this URL, and Teams shows it in the channel the webhook was created for.
  • A Microsoft Teams team where you can manage apps, so you can create an outgoing webhook and add a workflow.
  • An LLM provider key for the Agent, either stored as a secret or already set as a workspace key under AI models.
  1. In your workspace, go to Webhooks (under Services) and create one. Give it a name, and set Channel handler to Microsoft Teams. The handler is what verifies each request’s HMAC signature; leave Shared secret empty for now, because Teams only reveals the secret in the next step.

    The webhook form with Channel handler set to Microsoft Teams, which adds a Shared secret picker with a New secret button
    The webhook form with Channel handler set to Microsoft Teams, which adds a Shared secret picker with a New secret button
  2. Save, then copy the webhook’s address, under its name, with Copy. This is the callback URL Teams needs.

The webhook's address under its name at the top of its page, with Copy beside it
The webhook's address under its name at the top of its page, with Copy beside it
  1. In Teams, open the team, go to Manage team → Apps, and choose Create an outgoing webhook (the exact location varies a little between Teams client versions).
  2. Set the name (this is what people @mention, so pick something like Support), paste the Publicus webhook URL from step 1 as the callback URL, and add a description.
  3. When you create it, Teams shows a security token once. Copy it before closing the dialog. This is the shared secret Publicus verifies signatures with, and it does not expire.

3. Store the secret and finish verification

Section titled “3. Store the secret and finish verification”
  1. Back in Publicus, edit your webhook and pick a secret in Shared secret. The field’s + button creates the secret in place: name it teams_shared_secret and paste the security token from step 2 as the value.

    The Create secret dialog opened from the Shared secret field, with Name and Secret value fields, and Create and Cancel
    The Create secret dialog opened from the Shared secret field, with Name and Secret value fields, and Create and Cancel
  2. Save. From now on, Publicus checks the Authorization: HMAC signature on every request against this secret before anything is stored or run. Requests that fail the check are rejected and leave no trace in the webhook’s request log.

The flow answers by posting a message card to a Teams webhook URL that targets one channel.

  1. In Teams, open the channel the agent should answer in, and add a workflow from the template Post to a channel when a webhook request is received (the Workflows app). Point it at the team and channel, and copy the request URL it gives you.
  2. Store the URL as an opaque secret named teams_webhook_url in Secrets (a tab of Connections). This keeps the URL out of the flow definition, so it is not exported with the flow.

Create the flow that answers each @mention. On the Templates page (under Automation), the Channel / Teams example in the One flow per node section imports a minimal flow with the reply node already wired, or start from an empty flow and add the nodes yourself.

  1. Add a Webhook trigger node (under Triggers — start the flow), point its webhook field at the webhook from step 1, and connect its trigger handle to Start.

  2. The incoming request lands on $start, with the Teams message under $start->payload:

    Field Expression
    message text {!! $start->payload->text !!}
    conversation id {{ $start->payload->conversation->id }}
    sender id {{ $start->payload->from->id }}
    sender name {!! $start->payload->from->name !!}

    The message text includes the @mention itself as a tag, for example <at>Support</at> where is my order?. Use {!! !!} for the text and the sender name so characters like quotes, apostrophes, and ampersands reach the agent unescaped.

  3. Wire Start → Agent → Teams. On the Agent, set prompt to {!! $start->payload->text !!} and tell it in systemMessage that every message starts with an <at> mention tag it should ignore. Leave credential empty to use the workspace key for the provider, or pick your own LLM secret.

  4. Connect a Chat Thread node to the Agent’s Memory handle, with channel set to teams, conversationId to {{ $start->payload->conversation->id }}, and userId to {{ $start->payload->from->id }}. In Teams, every new channel post starts a new conversation id, and replies inside that post’s thread share it, so the agent’s memory follows the Teams thread.

  5. On the Teams reply node (under Channels — send a reply), set webhookUrl to {!! $secrets->teams_webhook_url !!} and text to {!! $prev->content !!}. Both need {!! !!}: the workflow URL contains query parameters with &, and the agent’s answer may contain characters that escaping would corrupt. The optional title and themeColor fields style the message card.

  6. Publish the flow, then arm the trigger: click the Webhook node’s badge on the canvas and switch Active on. Arming takes effect immediately. Live messages run the published version, so later edits to the draft do not reach Teams until you publish again; a flow that has never been published answers from its draft.

  • Delivery: @mention the webhook’s name in a channel of the team, for example @Support what can you help with?. The request appears in the webhook’s Deliveries tab (and under Traffic in Operations), with the run it started.

    A webhook's Deliveries table listing each inbound call with its time, method, endpoint, outcome and the number of runs it started, with View and a ⋮ row menu on each row
    A webhook's Deliveries table listing each inbound call with its time, method, endpoint, outcome and the number of runs it started, with View and a ⋮ row menu on each row
  • Run: under Runs, a run of your flow completes.

  • Reply: the agent’s answer appears in the channel the workflow webhook targets, posted by the Workflows bot.

  • Memory: under Conversations, a thread exists for the Teams conversation. Reply inside the same Teams post’s thread with a follow-up @mention that refers to your earlier message, and confirm the agent remembers.

  • Teams shows an error under the @mention: partly expected. Publicus acknowledges the request and processes it in the background, so Teams gets no inline reply message to render. The real answer arrives separately through the workflow webhook. Only investigate if that separate message never comes.

  • Nothing appears in the Deliveries tab: the signature check is failing or the URL is wrong. Confirm the teams_shared_secret secret holds the security token exactly as Teams showed it, and that the outgoing webhook’s callback URL matches the Publicus webhook’s address. Rejected requests are refused before storage, so they never show up. Also check the webhook’s Allowed IP addresses is empty, or includes Microsoft’s addresses.

  • A request appears but starts no run: the trigger is not armed, points at a different webhook, or its trigger handle is not connected to Start. The Deliveries tab’s Runs column shows what each request started, and skips are recorded on the request.

  • No reply arrives in Teams: open the run under Runs; a failed reply node also marks the run failed. If the reply node failed with Teams webhook returned unexpected status, the error names the status it received: an error status means the teams_webhook_url secret holds a wrong URL or the workflow in Teams is turned off, while a 202 means the workflow accepted the card without the 200 answer the node requires, so check whether the card still arrived in the channel.

  • The reply lands in the wrong channel: a workflow webhook posts to the one channel it was created for. Create a webhook per channel if the agent should answer in more than one.

  • A message got no reply while another was being answered: the Webhook trigger’s without overlapping setting (on by default) skips a new run while one is still in progress, and records the skip on the request. Turn it off to answer concurrent messages.

    A stored webhook call opened from its request log: headers, payload, a Skips section giving the reason each flow did not run, such as an overlapping execution, and the runs it started
    A stored webhook call opened from its request log: headers, payload, a Skips section giving the reason each flow did not run, such as an overlapping execution, and the runs it started
  • The agent forgets mid-conversation: memory is keyed by the Teams conversation id. A fresh channel post starts a new conversation, and only replies within the same post’s thread share memory.