chat / adapter-teams
AGENTS.md2.4k starsChanged 59 days agoMITView on GitHub
Guidance for coding agents working inside the Microsoft Teams adapter package. The top-level repository AGENTS.md covers monorepo-wide build, lint, and release rules — read it first. This file documents the adapter-specific surface, conventions, and pitfalls. @chat-adapter/teams connects a Chat SDK bot to a Microsoft Teams tenant via the Bot Framework + Microsoft Graph. It covers: - HTTP webhook endpoint at /api/webhooks/teams (Bot Framework Activity payload, JWT-signed by Microsoft). - Adaptive Card rendering for cards, modals (Task Modules), and inline-action buttons.…
- Reads credentials
Trending
Quiet since March.thin dataabout the whole repository
Who's talking about vercel/chat
- @camilleroux.com“Un SDK TypeScript unifié pour créer des chatbots qui fonctionnent sur Slack, Teams, Google Chat, Discord, …”Bluesky · Mar 3, 2026 · 3 likes
- @technews4869.bsky.social“github.com/vercel/chat GitHub - vercel/chat: A unified TypeScript SDK for building chat bots across Slack, …”Bluesky · Mar 7, 2026 · 1 likes
- @yug1224.com“チャットアプリ開発に使える統一SDKを提供するツールらしい 様々なプラットフォーム対応で便利そうだな yug1224 starred vercel/chat https://github.com/vercel/chat”Bluesky · Mar 7, 2026 · 1 likes
- @news.humancoders.com“Vercel lance Chat SDK : un SDK TypeScript unifié pour créer des bots multi-plateformes”Bluesky · Mar 5, 2026 · 1 likes
- @github-trending-js.bsky.social“🔥 Hot Repo! 🔥 (100+ new stars) 📦 vercel / chat ⭐ 871 (+121) 🗒 TypeScript A unified TypeScript SDK for …”Bluesky · Feb 27, 2026 · 1 likes
The biggest 5 of 5 mentions linking to the repository that our crawl found. Each line is their own headline.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository44 other files it gives its agents.
- AGENTS.mdAGENTS.md
- apps/docs/AGENTS.mdAGENTS.md
- chat-sdkAGENTS.md
- packages/adapter-discord/AGENTS.mdAGENTS.md
- packages/adapter-gchat/AGENTS.mdAGENTS.md
- packages/adapter-github/AGENTS.mdAGENTS.md
- packages/adapter-instagram/AGENTS.mdAGENTS.md
- packages/adapter-linear/AGENTS.mdAGENTS.md
- packages/adapter-messenger/AGENTS.mdAGENTS.md
- packages/adapter-notion/AGENTS.mdAGENTS.md
- packages/adapter-slack/AGENTS.mdAGENTS.md
- packages/adapter-telegram/AGENTS.mdAGENTS.md
- packages/adapter-web/AGENTS.mdAGENTS.md
- packages/adapter-whatsapp/AGENTS.mdAGENTS.md
- packages/chat/src/adapters/AGENTS.mdAGENTS.md
- packages/create-chat-sdk/AGENTS.mdAGENTS.md
- packages/create-chat-sdk/_template/AGENTS.mdAGENTS.md
- packages/state-ioredis/AGENTS.mdAGENTS.md
- packages/state-memory/AGENTS.mdAGENTS.md
- packages/state-pg/AGENTS.mdAGENTS.md
- packages/state-redis/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- packages/adapter-discord/CLAUDE.mdCLAUDE.md
- packages/adapter-gchat/CLAUDE.mdCLAUDE.md
- packages/adapter-github/CLAUDE.mdCLAUDE.md
- packages/adapter-linear/CLAUDE.mdCLAUDE.md
- packages/adapter-messenger/CLAUDE.mdCLAUDE.md
- packages/adapter-slack/CLAUDE.mdCLAUDE.md
- packages/adapter-teams/CLAUDE.mdCLAUDE.md
- packages/adapter-telegram/CLAUDE.mdCLAUDE.md
- packages/adapter-web/CLAUDE.mdCLAUDE.md
- packages/adapter-whatsapp/CLAUDE.mdCLAUDE.md
- packages/create-chat-sdk/CLAUDE.mdCLAUDE.md
- packages/create-chat-sdk/_template/CLAUDE.mdCLAUDE.md
- packages/state-ioredis/CLAUDE.mdCLAUDE.md
- packages/state-memory/CLAUDE.mdCLAUDE.md
- packages/state-pg/CLAUDE.mdCLAUDE.md
- packages/state-redis/CLAUDE.mdCLAUDE.md
- add-adapterSkill
- technical-writerSkill
- chat-sdkSkill
- chat-sdkSkill
- chat-sdkSkill
- chat-sdkSkill
The file
We split this AGENTS.md into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 264
Conversation IDs leak channel ↔ DM context: Use isDM rather than parsing the encoded blob.
- Very specific: line 269
Threaded replies require a root
messageId: When you reply, encode the root into the thread id (see thread-id.ts). - Very specific: line 288
When you add support for a new Activity type, capture a fresh fixture in sample-messages.md so the parser tests stay grounded.
- Distinctive: line 296
Use the named-export style throughout.
- Very specific: line 297
Keep index.ts slim — push helper logic into cards.ts, markdown.ts, modals.ts, graph-api.ts, etc.
- Very specific: line 301
Avoid process.env outside the factory.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — @chat-adapter/teams
Guidance for coding agents working inside the Microsoft Teams adapter package. The top-level repository AGENTS.md covers monorepo-wide build, lint, and release rules — read it first. This file documents the adapter-specific surface, conventions, and pitfalls.
Overview
@chat-adapter/teams connects a Chat SDK bot to a Microsoft Teams
tenant via the Bot Framework + Microsoft Graph. It covers:
- HTTP webhook endpoint at
/api/webhooks/teams(Bot Framework Activity payload, JWT-signed by Microsoft). - Adaptive Card rendering for cards, modals (Task Modules), and inline-action buttons.
- Microsoft Graph fallbacks for fetch/list endpoints the Bot Framework doesn't expose.
- Single-tenant and multi-tenant app support, plus channel + DM conversations and threaded replies.
- Streaming with the Bot Framework Activity update flow (post a placeholder, edit as deltas arrive).
The adapter wraps both transports — Bot Framework for inbound
events/outbound posts and Graph API for richer reads — through a
single TeamsAdapter instance.
Directory layout
packages/adapter-teams/
├── src/
│ ├── index.ts # TeamsAdapter + createTeamsAdapter factory
│ ├── index.test.ts
│ ├── app.ts # TeamsApp: SDK App that targets per-thread service URLs
│ ├── bridge-adapter.ts # adapter-side glue between Bot Framework + Chat SDK
│ ├── api/ # low-level Bot Connector REST primitives
│ ├── cards.ts # Card / PostableMessage → Adaptive Cards
│ ├── cards-primitives/ # plain-object Adaptive Card primitives
│ ├── cards.test.ts
│ ├── config.ts # configuration parsing & env resolution
│ ├── errors.ts # AuthenticationError / RateLimit mapping
│ ├── errors.test.ts
│ ├── format/ # runtime-free Teams string helpers
│ ├── graph/ # low-level Microsoft Graph REST primitives
│ ├── graph-api.ts # Microsoft Graph client wrapper
│ ├── graph-api.test.ts
│ ├── installation.ts # installationUpdate action parsing
│ ├── markdown.ts # TeamsFormatConverter (mdast ↔ Teams HTML)
│ ├── markdown.test.ts
│ ├── modals.ts # Modal → Task Module conversion
│ ├── modals-primitives/ # plain-object Task Module primitives
│ ├── modals.test.ts
│ ├── test-utils.ts # TestTeamsAdapter harness shared by SDK-router tests
│ ├── thread-id.ts # encode/decode/isDM helpers
│ ├── types.ts # internal Teams payload typings
│ └── webhook/ # parse-only Activity webhook primitives
├── sample-messages.md # captured Bot Framework activities
├── package.json
├── tsconfig.json
├── tsup.config.ts
├── vitest.config.ts
└── README.mdbridge-adapter.ts adapts the @microsoft/teams.apps route handler
into the Chat SDK adapter contract. Keep it free of business logic —
convert and forward only.
Build, test, typecheck
pnpm build
pnpm dev
pnpm test
pnpm test:watch
pnpm typecheck
pnpm clean
# from repo root
pnpm --filter @chat-adapter/teams build
pnpm --filter @chat-adapter/teams testReplay tests for Teams live in
packages/integration-tests/src/replay-teams-*.test.ts — extend the
fixture corpus instead of mocking new payloads when adding behavior.
Public surface
The package's main exports (see src/index.ts):
createTeamsAdapter(config?)— primary factory. Auto-detectsTEAMS_APP_ID,TEAMS_APP_PASSWORD,TEAMS_APP_TENANT_ID,TEAMS_APP_TYPE(single/multi tenant), and the optionalTEAMS_GRAPH_TENANToverrides.TeamsAdapterclass — implementsAdapter<TeamsThreadId, unknown>. Public methods:handleWebhook,postMessage,editMessage,deleteMessage,addReaction,removeReaction,startTyping,openModal,pushModal,fetchThread,listThreads,fetchMessages,fetchSingleMessage,fetchChannelInfo,postChannelMessage,openDM.- Configuration types:
TeamsAdapterConfig,TeamsThreadId. - Helpers re-exported from sub-modules:
cardToAdaptiveCard,cardToFallbackText,TeamsFormatConverter,decodeThreadId,encodeThreadId,isDM.
Low-level subpaths are exported for custom runtimes that do not want the full Chat SDK adapter graph:
@chat-adapter/teams/api— fetch-based Bot Connector message, typing, and conversation helpers.@chat-adapter/teams/graph— fetch-based Microsoft Graph reads with explicitteamId,channelId, orchatId.@chat-adapter/teams/webhook— parse-only Activity classification and continuation extraction. It does not verify Bot Framework JWTs.@chat-adapter/teams/format— runtime-free Teams HTML, mention, and emoji helpers.@chat-adapter/teams/cards— plain-object Adaptive Card helpers.@chat-adapter/teams/modals— plain-object Task Module helpers.
Primitive subpaths must not import chat, @chat-adapter/shared,
@microsoft/teams.apps, or the main adapter entry. Keep boundary tests
updated whenever a new primitive file is added.
Thread ID format
Teams conversation IDs contain colons (e.g.
19:abc@thread.tacv2;messageid=…), so the adapter base64url-encodes
them before assembling the Chat SDK identifier:
teams:{conversationId_base64url}:{serviceUrl_base64url} # legacy
teams:{conversationId_base64url}:{serviceUrl_base64url}:{conversationType} # classification overrideencodeThreadId / decodeThreadId are the only sanctioned way to
construct these — never string.replace(":", …) your way around the
encoding. The optional conversation type is added only when personal,
groupChat, or channel disagrees with the legacy conversation-ID
prefix heuristic, so existing IDs stay stable unless that heuristic
would route them incorrectly.
isDM(threadId) returns true when the underlying conversation type
is personal (1:1 with the bot) — useful inside handlers that need to
branch on private vs channel context.
Webhook flow
TeamsAdapter.handleWebhook(request, options) is the entry point.
It performs:
- JWT validation — Bot Framework signs every activity with a
tenant-aware JWT. Validation uses the
microsoftAppCredentialsFactoryconfigured withappId,appPassword, andtenantId. - Activity routing
message→chat.handleIncomingMessage(oronNewMention/onSubscribedMessagedepending on @mention detection).messageReaction→chat.handleReaction.messageUpdate/messageDelete→ optional update/delete hooks.invoke(task/fetch,task/submit,adaptiveCard/action) → modal lifecycle and action callbacks.
- Outbound
Activity—postMessageconstructs an Activity with the Adaptive Card payload + fallback text, then sends it through the connector client. Sub-second roundtrips matter; long-running work goes throughwaitUntil.
Authentication
Teams uses Bot Framework + Microsoft Entra ID. Three modes:
- Single-tenant (
appType: "SingleTenant") — one app registration in your tenant. Simple, but cannot install into other tenants. - Multi-tenant (
appType: "MultiTenant") — public app, OAuth consent in each tenant. RequirestenantIdper webhook (looked up from the activity'sserviceUrl). - Managed Identity — set
appType: "ManagedIdentity"and rely on the Azure-side identity assigned to the host. NoappPasswordneeded.
Channel-and-DM tokens are issued by Microsoft on the inbound JWT and
re-used for outgoing requests. Outbound calls go through TeamsApp
(app.ts), which targets the service URL encoded in each thread ID
rather than the SDK's single app-wide URL. Applications can persist the
channelId from onInstalled in their own durable store and post to it
later with bot.channel(). Use onUninstalled for application-owned
cleanup; there are no adapter installation CRUD methods.
Microsoft Graph
graph-api.ts wraps the Graph client with:
- Lazy initialization — instantiated on first call so unit tests don't pull network credentials.
- Retry-aware request helper that maps
401toAuthenticationError,403toPermissionError,429toAdapterRateLimitError(with theRetry-Afterheader surfaced viaretryAfterMs), and5xxtoNetworkError. - Graph-only methods:
fetchChannelInfo,fetchTeamInfo,listChannelMessages,fetchSingleMessage,addReaction,removeReaction. The Bot Framework alone cannot serve these.
Format conversion
TeamsFormatConverter (in markdown.ts) maps:
- mdast → Teams HTML — Teams renders message text as HTML, not
markdown. Headings →
<h*>, lists →<ul>/<ol>, blockquotes, inline code, fenced code →<pre><code>, tables →<table>. Bold / italic / strike / link work via<strong>,<em>,<s>,<a href>. - Teams HTML → mdast — DOMParser-light walk that recognises the same
tags. Robust against the noisy markup Teams sometimes injects (extra
<div>wrappers,dir="ltr"attributes, OneNote-style namespaced spans). - Mentions —
<at>name</at>tags are paired withentitieson the Activity, sotoAstandfromAstkeep entities and inline text in sync.
renderPostable converts a PostableMessage into the HTML body shape
Teams expects. Use it through cards.ts; bypassing it is a code
smell.
Cards & modals
cardToAdaptiveCard walks a Chat SDK Card JSX tree and emits
Adaptive Card v1.5 JSON. Notable mappings:
<Section>→Container;<Header>→TextBlockwithsize: large weight: bolder.<Field>→FactSet.<Image>→Image(data URLs and http(s) URLs both supported).<Actions>/<Button>→Action.Submit(withdatacarrying the callback metadata).<LinkButton>→Action.OpenUrl.tooltipon either button → the actiontooltip(Adaptive Card 1.5+, which is why the emittedversionis1.5).<Card width="full">→msteams: { width: "full" }.<Select>→Input.ChoiceSet(single, multi, or compact based on options).<Divider>→Containerwith a top border.<Table>→Table(Adaptive Card 1.5+).
modals.ts handles Task Modules: Modal.title / submitLabel map to
title / value of the surrounding task/fetch response. Submit
events arrive as invoke activities and are dispatched through
chat.handleAction.
Streaming
postMessage accepts AsyncIterable<string | StreamChunk> and
implements the Bot Framework streaming pattern: post a placeholder
Adaptive Card, then update it as deltas arrive. The minimum interval
between edits avoids hitting the per-conversation rate limit (default
~1 RPS in Teams).
Teams quirks worth remembering
- JWT clock skew. Microsoft tokens have a hard 5-minute window — containers running with skewed clocks fail validation. Surface clock drift as a deployment-level alert.
- Conversation IDs leak channel ↔ DM context. Use
isDMrather than parsing the encoded blob. - Adaptive Card 1.6 is not universally available. Stay on 1.5 primitives unless the rendering host is known to support newer features.
- Threaded replies require a root
messageId. When you reply, encode the root into the thread id (seethread-id.ts). - Graph fetches need delegated permissions for cross-team reads.
fetchChannelMessageswill return 403 in some tenants until a Graph-API admin consent is granted. messageReactionevents are coalesced — the Activity describes the delta (added vs removed) rather than the current state. Keep reaction handlers idempotent.
Testing approach
- Unit tests colocated with each module (
*.test.ts). Use the fixtures insample-messages.mdrather than fabricating Bot Framework payloads. - Replay tests at
packages/integration-tests/src/replay-teams*.test.tsfeed recorded webhook traffic through the full adapter. - Graph API tests stub the HTTP transport with
vi.fn()(seegraph-api.test.ts) — never call the real Graph API in unit tests.
When you add support for a new Activity type, capture a fresh fixture
in sample-messages.md so the parser tests stay grounded. The
installationUpdate tests use a synthetic payload modeled on Microsoft's
documented schema because no captured traffic exists yet; replace it with
a real capture when one is available.
Coding conventions
- Use the named-export style throughout. No default exports.
- Keep
index.tsslim — push helper logic intocards.ts,markdown.ts,modals.ts,graph-api.ts, etc. - Wrap Microsoft Graph errors in the typed errors from
errors.ts; never let rawRestErrorinstances escape. - Avoid
process.envoutside the factory. Pass config explicitly. - Top-level regex literals; reuse the helpers in
thread-id.tsinstead of writing your own colon-splitter.
Releases
Behavioural changes need a changeset (pnpm changeset, choose
@chat-adapter/teams plus chat if a public type changed). Internal
refactors and AGENTS.md edits don't.
Where to look next
- User-facing docs:
apps/docs/content/adapters/official/teams.mdx - README:
packages/adapter-teams/README.md - Shared error/utility helpers:
packages/adapter-shared/src/index.ts - Core Adapter contract:
packages/chat/src/adapter.ts - Sample webhook payloads:
packages/adapter-teams/sample-messages.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

