Connecting Microsoft Teams

1. Register the bot

At https://portal.azure.com create an Azure Bot resource.

  • Type of App: Multi-tenant unless you have a reason to pin it to one tenant.
  • Under Configuration → Microsoft App ID, note the id.
  • Manage → Certificates & secrets → New client secret: create one and copy the value immediately, it is shown once.

2. Secrets and variables

wrangler secret put TEAMS_APP_ID          # the Microsoft App ID
wrangler secret put TEAMS_APP_PASSWORD    # the client secret value
Variable Meaning
TEAMS_APP_ID Secret. Absent ⇒ Teams is not configured.
TEAMS_APP_PASSWORD Secret. Required.
TEAMS_TENANT_ID Only for a single-tenant bot.
TEAMS_SERVICE_URL Optional fallback Connector URL — see below.
TEAMS_PATH_PREFIX Defaults to /teams.

An app id without a password fails the deployment rather than starting a bot that can verify nothing.

3. Messaging endpoint

In the Azure Bot resource, Configuration → Messaging endpoint:

https://<worker>/teams/messages

Then Channels → Microsoft Teams to enable the Teams channel, and package an app manifest (via Developer Portal) whose bots[0].botId is the Microsoft App ID. Install that package into your team.

Scopes

There are none to grant. Teams is the odd one out: the bot calls the Connector with a client-credentials token for the single fixed scope https://api.botframework.com/.default, which the app registration already has by being an Azure Bot. There is no consent screen and no permission list, and what the bot may do follows from where the app is installed — the manifest's bots[0].scopes (personal, team, groupChat), which is an install target rather than a permission.

Set all three unless you have a reason not to. personal is what makes conversation.directMessage() work at all: POST /v3/conversations is refused for a user who has not installed the app in personal scope.

The one thing that is a permission is resource-specific consent (RSC) in the manifest — authorization.permissions.resourceSpecific, granted by the team owner rather than a tenant administrator. ChannelMessage.Read.Group is the member worth knowing about: it is the only realistic route to channel history for a bot, which is why the history capability is undeclared here today. Nothing in the adapter reads it yet, so adding it buys nothing until it does.

What Teams cannot do

These are limits of the Bot Framework, not gaps in the SDK. The adapter does not declare them, so conversation.can(...) reports false:

Capability Why not
reactions The Connector has no endpoint for a bot to place a reaction. Teams delivers reaction events, but a bot can only read them.
ephemeral Teams has no message visible to one member of a channel.
fileUpload Sending a file needs a file-consent card — the bot asks, the user accepts, and the bytes go up in a second exchange — which works in personal scope only. Reading one is a different matter: fileDownload is declared, for a file attached in a chat and for an inline image. A file posted in a channel lives in the team's SharePoint site and needs Microsoft Graph, so download() refuses that one by name.
history Reading channel messages needs Graph's protected ChannelMessage.Read.All, which requires admin consent and Microsoft approval.
slashCommands Teams has no slash commands for bots — its "commands" only pre-fill the compose box and arrive as ordinary messages.

What only Teams can do

typing. Teams is the only supported platform where a bot can show a typing indicator. Slack and Google Chat offer apps no such API.

if (conversation.canShowTyping) await conversation.typing();

The serviceUrl

The Bot Framework has no fixed API host. Every activity carries a serviceUrl naming the Connector instance that delivered it, and replies go back there.

The adapter remembers the serviceUrl per conversation, which is Microsoft's documented pattern. A consequence: a conversation this worker has never received an event from has no known serviceUrl, so a proactive message to it fails with a message saying so. Set TEAMS_SERVICE_URL (a tenant's value is stable) if the bot needs to post somewhere before it has heard from it — a channel people watch, typically.

Security

Every request carries an RS256 token from the Connector. The adapter verifies it against the Bot Framework's published keys (resolved through OpenID discovery), pins the algorithm, and checks issuer, audience and expiry.

Most importantly it checks the serviceUrl claim against the activity body. serviceUrl is where the bot posts its replies, with its bearer token attached. Without that check, anyone could POST a fake activity naming their own host and the bot would hand its Connector credentials straight over. A failing request gets an opaque 401.

Formatting

Teams renders the narrowest Markdown of the three platforms. In a text message, headings and horizontal rules render as literal characters, images do not render at all, and lists only render on desktop.

So the adapter routes anything structural — a heading, a divider, an image, label/value fields, buttons — into an Adaptive Card, which renders identically everywhere. Plain prose stays as text, where it looks like a person typed it. Nothing in a bot changes; the neutral blocks are the same.

Related: Capabilities, Deploying a bot, Connecting Slack, Connecting Google Chat.

← Connecting Google ChatConnecting email →