Microsoft Teams
People talk to kōjō in Teams in a personal chat with the bot, or by mentioning it in a channel or a group chat. kōjō answers in the thread and asks for approvals with a card that has buttons.
See Surfaces for how Teams compares with the other chat platforms, and Who may trigger what for what a request may do, depending on who sent it.
How it connects
A Teams bot is an Azure Bot registration. Teams hands every message to Microsoft’s Bot Connector service, which posts it to the bot’s messaging endpoint. kōjō answers by calling the Bot Connector’s REST API.
| Direction | How | Needs |
|---|---|---|
| Messages and button clicks to kōjō | The Bot Connector posts to <public_url>/teams/messages with a bearer token. |
server.public_url is https and that path is reachable from the internet. |
| Replies and approvals from kōjō | Calls to the Bot Connector at the service URL the message named (https://smba.trafficmanager.net/...), with an access token kōjō gets from Microsoft Entra ID with the bot’s app ID and password. |
kōjō reaches login.microsoftonline.com, login.botframework.com and smba.trafficmanager.net. |
Nothing in a request is acted on before its token is verified:
| Check | A request that fails gets |
|---|---|
The token is signed with a key the Bot Connector publishes (RS256, a key of at least 2048 bits). The keys are read from the OpenID metadata at login.botframework.com, cached, refreshed every 6 hours, and fetched again when a token names a key that is not cached, at most once a minute. |
401 |
The issuer is https://api.botframework.com. |
401 |
| The audience is the bot’s app ID. | 401 |
| The token is within its validity period, with 5 minutes of tolerance. | 401 |
The token’s serviceurl claim is the service URL of the activity. |
403 |
| The activity comes from Teams, and the signing key is endorsed for Teams. | 403 |
The service URL is a Teams endpoint: smba.trafficmanager.net, the GCC, GCC High and DoD hosts, or the host of service_url. kōjō sends its own token there next, and sends it nowhere else. |
403 |
The tenant is tenant_id or one of allowed_tenants. |
403 |
When the signing keys cannot be fetched and none are cached, the answer is 503. Bodies are limited to 1 MiB.
sequenceDiagram
participant U as User in Teams
participant B as Bot Connector
participant K as kōjō
participant E as Entra ID
U->>B: a message that mentions the bot
B->>K: POST /teams/messages with a bearer token
K->>B: read the signing keys, unless cached
Note over K: Signature, issuer, audience, validity, service URL, tenant
K->>E: client credentials for an access token, unless cached
K->>B: who is the sender, from the conversation roster
Note over K: The sender's email gives the role. The session is queued
K-->>B: 200
Note over K: The session runs
K->>B: POST the reply to the conversation, at the activity's service URL
B->>U: the reply, in the thread
Delivery is at least once. kōjō acknowledges an activity once it has accepted it and drops one that is sent again. When kōjō cannot accept an activity it answers 500, and the activity is handled if it comes again.
Set up
The bot is registered in Azure, then installed in Teams as an app.
Register the bot in Azure
-
In the Azure portal choose Create a resource, search for
botand create an Azure Bot. Under Microsoft App ID choose Single Tenant as the type of app and let Azure create a new app ID, or name an existing app registration of your tenant. -
Open the bot’s Configuration blade:
- Copy the Microsoft App ID and the App Tenant ID.
- Set the Messaging endpoint to
https://kojo.example.com/teams/messages: yourserver.public_urlfollowed by/teams/messages. - Select Manage next to the app ID, create a client secret under Certificates & secrets, and copy its value. That is
app_password.
-
Open Channels, select Microsoft Teams, agree to the terms and apply.
-
Add Teams to
kojo.yamland put the secret in the environment kōjō reads:server: public_url: https://kojo.example.com chat: teams: app_id: 6f9619ff-8b86-4d11-b42d-00c04fc964ff # Microsoft App ID app_password: ${TEAMS_APP_PASSWORD} # the client secret tenant_id: 72f988bf-86f1-41af-91ab-2d7cd011db47 # App Tenant ID -
Run
kojo doctor. Itschat teamscheck gets an access token with the app ID and the password, and reads the Bot Connector’s signing keys.
kōjō refuses to start with chat.teams and a public URL that is not https, unless dev: true. It serves the Teams channel only: Test in Web Chat in the Azure portal gets a 403.
| Type of app in Azure | kojo.yaml |
|---|---|
| Single Tenant | tenant_id. The bot serves that tenant. |
| Multi Tenant | No tenant_id, and allowed_tenants with the tenants whose users may talk to the bot. Azure has not created multi-tenant bots since July 31, 2025; the ones that exist keep working. |
| User-Assigned Managed Identity | Not supported: kōjō signs in with a client secret. |
A multi-tenant bot can be installed by any organization, and kōjō takes a user’s email from the tenant the message came from. That is why it only answers the tenants you list.
Install the app in Teams
A bot is installed in Teams as an app: a zip with a manifest and two icons. kojo setup teams writes it:
kojo setup teams --app-id 6f9619ff-8b86-4d11-b42d-00c04fc964ff --public-url https://kojo.example.com
It writes kojo-teams.zip and prints the steps that remain. The package holds manifest.json (manifest version 1.19; the bot, installable in personal chats, teams and group chats), color.png (192×192) and outline.png (32×32). Flags change the name, the version and the links shown on the app’s page: see kojo setup teams.
- For yourself or one team: in Teams choose Apps → Manage your apps → Upload an app → Upload a custom app, pick the zip, and add the app to a chat or to a team. Your organization must allow custom apps.
- For the whole organization: in the Teams admin center choose Teams apps → Manage apps → Upload new app. People then find the bot under Apps → Built for your org.
The bot has to be added to a team before it can be mentioned in that team’s channels or post there. To update an installed app, write the package again with a higher --app-version and upload it in the same place.
Then give the operator role, in the dashboard under Settings → Access, to the people who may trigger code changes and decide approvals from Teams.
Roles
What a request may do depends on the sender’s role in kōjō, as on every chat surface: see who may trigger what. kōjō asks the Bot Connector for the sender’s entry on the roster of the team or the chat, and maps its email address to a role through the rbac object. When the entry has no email, the user principal name is used, unless it is a guest’s (…#EXT#@…).
| Sender | The request |
|---|---|
| An email with the operator or admin role | May change code, within the merge policy. |
An email with a lesser role, or one rbac does not name |
Runs untrusted: read-only answers. |
| No email: the roster lookup failed, or the user is a guest without one | Runs untrusted. |
Lookups are cached for an hour per user.
Mentions, messages and replies
Write to the bot in plain words. Each message becomes one session, unless it goes to a session already at work in its thread (below).
| Where | What reaches kōjō | Where kōjō answers |
|---|---|---|
| Personal chat with the bot | Every message. | In the chat. |
| Channel of a team | Messages that mention the bot: @kojo why does the nightly build fail? |
In the thread of the message. A mention in a new post starts the thread under that post. |
| Group chat | Messages that mention the bot. | In the chat. |
While a session is at work, an operator’s mention in its channel thread goes to that session instead of starting another one: its next step reads it. A personal chat and a group chat have no threads, so there every message is a new session. See Talking to a session at work.
The mention is removed from the text before the request is read. Whether a message mentions the bot is taken from what Teams reports about the message, not from its text, so writing <at>kojo</at> by hand does nothing. Messages that do not mention the bot, edits, deletions, reactions and messages of other bots are ignored.
kōjō picks the repository as it does for Slack: the one named in the message as forge/owner/name, or the only enabled one.
A session keeps the conversation and the service URL its request came from, so the reply does not depend on anything a replica holds in memory: it is sent after a restart, and by whichever replica runs the session.
Messages kōjō writes
Messages are sent as Markdown, in Teams’ extended Markdown mode: headings, lists, code blocks, tables and links are shown as such. kōjō changes three things on the way. Raw HTML is shown as text, not interpreted. Images become links, so that opening a message fetches nothing from a server the message chose. A text longer than 12,000 characters continues in further messages of the same thread; a code block that spans two messages is closed in one and reopened in the next. With text_format: markdown kōjō uses Teams’ older Markdown mode, and sends tables as code blocks and check boxes as ☐ and ☑.
Approvals
When the merge policy asks a human, kōjō posts an Adaptive Card in the thread: the question, the details, and the buttons Approve and Deny. The questions, and what happens without an answer, are the same as in Slack. The session waits until someone decides or the question’s deadline passes.
A click reaches kōjō through the same endpoint and the same token check as a message. Only a user with the operator or admin role decides. A click from anyone else changes nothing: the buttons stay, kōjō says in the thread that the operator role is needed, and the attempt is written to the audit log. The first valid click stands, and the card is replaced by one without buttons that shows the outcome and who decided.
The buttons are Action.Execute actions of an Adaptive Card of version 1.4, each with an Action.Submit as fallback for clients that do not know Action.Execute. kōjō accepts both kinds of click.
Schedules
A schedule can report to Teams with notify: teams:<conversation ID>. For a channel that is the channel’s ID, which is in the link Teams gives under Get link to channel: the part between /channel/ and the next /, URL-decoded.
notify: teams:19:aebd0ad4d6ab42c8b9ed19c251c2fc37@thread.tacv2
The report starts a new post in that channel. The app must be installed in the team. Such a message answers no incoming one, so it is sent to service_url, by default https://smba.trafficmanager.net/teams/.
Other clouds and limits
| Setting | Default | Change it for |
|---|---|---|
service_url |
https://smba.trafficmanager.net/teams/ |
GCC: https://smba.infra.gcc.teams.microsoft.com/teams. GCC High: https://smba.infra.gov.teams.microsoft.us/teams. DoD: https://smba.infra.dod.teams.microsoft.us/teams. |
login_url |
https://login.microsoftonline.com |
Azure Government: https://login.microsoftonline.us. |
token_scope |
https://api.botframework.com/.default |
Azure Government: https://api.botframework.us/.default. |
openid_metadata_url |
https://login.botframework.com/v1/.well-known/openidconfiguration |
Azure Government: https://login.botframework.azure.us/v1/.well-known/openidconfiguration. |
The issuer that tokens must name is read from the OpenID metadata document. These URLs must be https unless dev: true.
- Access token. kōjō keeps the bot’s access token in memory and replaces it 5 minutes before it expires. When the Bot Connector refuses a token, kōjō gets a new one and tries once more. The token and the password are never logged, and kōjō follows no redirect from the login service or the Bot Connector.
- Throttling. A call the Bot Connector answers with
429,412,502or504is made up to three times, with a pause that doubles and honoursRetry-Afterup to 10 seconds. - Cards. A card shows at most 4,000 characters of an approval’s text and 40 lines of each code block in it, and at most 6 buttons.
- Several replicas. Any replica can receive an activity and any replica can answer. Each replica remembers the activities it accepted for an hour; a message that is delivered again to another replica is recognised by the store and starts no second session.