chat / adapter-gchat
AGENTS.md2.4k starsChanged 59 days agoMITView on GitHub
Guidance for coding agents working inside the Google Chat 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/gchat connects a Chat SDK bot to Google Chat (the Workspace messaging product, not Hangouts/Meet). It covers: - HTTP webhook endpoint at /api/webhooks/gchat, validated with Google-issued JWTs. - Card v2 rendering for cards, fields, action buttons, image attachments, and dialog modals. - Workspace Events API…
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-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-teams/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
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 243
When you add a new event type, capture a fresh fixture in sample-messages.md and add an assertion to the parser tests.
- Very specific: line 248
All exports are export function / export class / export const — no default exports.
≈ “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/gchat
Guidance for coding agents working inside the Google Chat 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/gchat connects a Chat SDK bot to Google Chat (the
Workspace messaging product, not Hangouts/Meet). It covers:
- HTTP webhook endpoint at
/api/webhooks/gchat, validated with Google-issued JWTs. - Card v2 rendering for cards, fields, action buttons, image attachments, and dialog modals.
- Workspace Events API consumption for cross-space subscriptions (mentions in spaces the bot isn't a direct member of).
- Service-account credentials or Application Default Credentials (ADC), with optional impersonation of a domain user.
- Thread-or-flat space modes — Google Chat spaces can be configured for top-level posts only, threaded, or both.
The adapter follows the Google Chat API
v1 surface and
relies on google-auth-library for credential resolution.
Directory layout
packages/adapter-gchat/
├── src/
│ ├── index.ts # GoogleChatAdapter + createGoogleChatAdapter
│ ├── index.test.ts
│ ├── cards.ts # PostableMessage / Card → Card v2
│ ├── cards.test.ts
│ ├── markdown.ts # GoogleChatFormatConverter (mdast ↔ Chat formatting)
│ ├── markdown.test.ts
│ ├── thread-utils.ts # space/thread parsing + base64url helpers
│ ├── thread-utils.test.ts
│ ├── user-info.ts # users.get caching + display-name resolution
│ ├── user-info.test.ts
│ ├── workspace-events.ts # Workspace Events API push handler
│ └── workspace-events.test.ts
├── sample-messages.md # captured Chat API event payloads
├── package.json
├── tsconfig.json
├── tsup.config.ts
├── vitest.config.ts
└── README.mdBuild, test, typecheck
pnpm build
pnpm dev
pnpm test
pnpm test:watch
pnpm typecheck
pnpm clean
# from repo root
pnpm --filter @chat-adapter/gchat build
pnpm --filter @chat-adapter/gchat testReplay tests live in
packages/integration-tests/src/replay-gchat-*.test.ts and exercise
the full webhook → handler flow against fixtures.
Public surface
The package's main exports (see src/index.ts):
createGoogleChatAdapter(config?)— primary factory. Auto-detectsGOOGLE_CHAT_CREDENTIALS(inline JSON or a path), falls back to ADC whenGOOGLE_CHAT_USE_ADC=true, and recognisesGOOGLE_CHAT_SUBJECTfor domain-wide delegation.GoogleChatAdapterclass — implementsAdapter<GoogleChatThreadId, unknown>. Public methods:handleWebhook,postMessage,editMessage,deleteMessage,addReaction,removeReaction,startTyping,openModal,fetchThread,listThreads,fetchMessages,fetchSingleMessage,fetchChannelInfo,postChannelMessage,openDM,handleWorkspaceEvent.- Configuration types:
GoogleChatAdapterConfig,GoogleChatThreadId,GoogleChatCredentials. - Helpers:
cardToCardV2,cardToFallbackText,GoogleChatFormatConverter,decodeThreadId,encodeThreadId,isDM.
Thread ID format
Google Chat space and thread names contain forward slashes (e.g.
spaces/AAA…/threads/BBB…), so the adapter base64url-encodes them.
gchat:{space_base64url} # flat post in a space
gchat:{space_base64url}:{thread_base64url} # threaded replyencodeThreadId / decodeThreadId are the only sanctioned way to
construct these — never string.replace("/", …) your way around the
encoding. isDM returns true when the underlying space type is
DIRECT_MESSAGE.
Webhook flow
GoogleChatAdapter.handleWebhook(request, options) is the single
entry point. It dispatches based on the Chat event envelope:
- JWT validation — Google signs every webhook with a service
account. The adapter validates the
Authorization: Bearer …token against Google's public certs usinggoogle-auth-library. Audience defaults tohttps://chat.googleapis.com; override viawebhookAudience. - Event type
MESSAGE→chat.handleIncomingMessage. Mentions are detected by walkingmessage.annotations[].userMentionfor the bot's own resource name.ADDED_TO_SPACE→ bot becomes available in a new space; chained to optionalonSpaceJoinedhandlers.REMOVED_FROM_SPACE→ cleanup hook.CARD_CLICKED→chat.handleAction+ Card v2 button callback.DIALOG(request_type === "DIALOG") → modal lifecycle.WIDGET_UPDATED→ action loop for option-loading.
- Workspace Events —
handleWorkspaceEventreceives push notifications for spaces where the bot has a Workspace Events subscription (mentions, message updates, reactions). Subscriptions are managed externally; the adapter only consumes events.
Authentication
Three credential modes:
- Inline service account JSON — pass
credentials: { client_email, private_key, … }or setGOOGLE_CHAT_CREDENTIALSto the JSON or to a file path. The adapter detects each shape automatically. - Application Default Credentials — set
GOOGLE_CHAT_USE_ADC=trueto use the ambient credentials (e.g. the Workload Identity attached to a Cloud Run service). No explicit credentials required. - Domain-wide delegation — set
subject(orGOOGLE_CHAT_SUBJECT) to a user email to act on that user's behalf. Requires the service account to be granted thehttps://www.googleapis.com/auth/chat.botscope by a Workspace admin.
Auth tokens are cached with an automatic refresh ahead of expiry. The adapter never logs raw tokens.
Format conversion
GoogleChatFormatConverter (in markdown.ts) maps:
- mdast → Google Chat formatting — Google Chat uses a constrained
subset of markdown:
*bold*,_italic_,~strike~, single backticks for inline code, triple backticks for fenced code, and HTML-style links via<url|label>. The converter strips features Google Chat doesn't render (headings collapse to bold lines, lists emit as plain paragraphs with bullet prefixes). - Google Chat formatting → mdast — round-trips bold, italic, strike,
code, and links. User mentions arrive as separate annotation
entries; the converter folds them into the AST as
linknodes pointing atusers/{id}.
renderPostable is the entry point for outbound rendering — it always
sets the message text field even when sending Card v2 payloads,
because the Chat search index uses the plain-text form.
Cards & dialogs
cardToCardV2 walks a Chat SDK Card JSX tree and emits the
Card v2 payload:
<Section>/<Header>→cardsV2.card.header(only one), thensections[].headerandsections[].widgets[].<Field>→decoratedTextwidgets withtopLabeland primary text.<Image>→imagewidget with optionalonClick.openLink.<Actions>/<Button>→buttonList.buttons[].onClick.action, withfunctionset to the callback id.<LinkButton>→buttonList.buttons[].onClick.openLink.<Select>→selectionInput. Multi-select / dropdown variants follow the Card v2 spec.<Divider>→divider.<Table>is rendered as a fixed-width formatted code block.
Dialog modals are emitted as actionResponse.type: "DIALOG" with the
form widget tree. Submit events arrive via request_type: "DIALOG"
on the inbound webhook.
Workspace Events
workspace-events.ts consumes push notifications for Chat spaces the
bot is not a member of (e.g. mentions inside a space the user
keeps the bot out of). Two sub-flows:
- Subscription management — outside the adapter; create a subscription via the Workspace Events API targeting your webhook URL.
- Event handling —
handleWorkspaceEvent(request, options)verifies the JWT, validates theeventType, and forwards into the same handler pipeline as direct events. The two flows share the same parsers inindex.ts.
Streaming
postMessage accepts AsyncIterable<string | StreamChunk> and
implements the post-then-edit pattern: the adapter posts a placeholder
message and edits it with the accumulated stream content. Min edit
interval defaults to 800 ms to stay under Google Chat's per-message
edit rate limit.
Google Chat quirks worth remembering
- JWT audience. Misconfigured audiences are the most common cause
of webhook 401s. The default is correct for Workspace Events; for
bot apps published via the Marketplace, override
webhookAudience. - Service account email is the bot identity. Mentions of
@botresolve to the service account email, not a separate Chat user. - Threaded replies require the parent thread name, not the parent
message name — see
thread-utils.ts. message.textand Card v2 can both be present on a single outbound message; the Chat web UI shows the text above the card.- Reactions are limited to Unicode emoji. Custom emoji uploaded via Workspace admin cannot be addressed via the public API.
- Edit window. A message can only be edited within ~30 days of
posting; older edits return 403
PERMISSION_DENIED. - Space type is sticky. Switching a space from "Threaded" to "Flat" requires recreating the space — handlers should not assume thread IDs persist after such a change.
Testing approach
- Unit tests colocated with each module (
*.test.ts). Use theusers/{id}andspaces/{id}/messages/{id}fixtures fromsample-messages.md. - Replay tests in
packages/integration-tests/src/replay-gchat*.test.tsfeed recorded webhook traffic through the entire adapter. - Auth helpers are mocked at the
google-auth-libraryboundary; never make real auth calls in unit tests.
When you add a new event type, capture a fresh fixture in
sample-messages.md and add an assertion to the parser tests.
Coding conventions
- All exports are
export function/export class/export const— no default exports. - Service-account JSON should never appear in test fixtures. Use the
redacted templates in
index.test.ts. - Errors thrown to chat-sdk callers come from
@chat-adapter/shared(AuthenticationError,AdapterRateLimitError,NetworkError,ValidationError). - Top-level regex literals only (e.g.
SPACE_NAME_PATTERN,USER_RESOURCE_PATTERN). - Caching belongs in
user-info.ts— don't sprinkle ad-hoc caches through the codebase.
Releases
This package ships with the rest of the monorepo on the fixed
Changesets schedule. Behavioural changes need a changeset (pnpm
changeset, choose @chat-adapter/gchat plus chat if a public type
changed). README, sample-messages, and AGENTS.md edits are docs-only.
Where to look next
- User-facing docs:
apps/docs/content/adapters/official/gchat.mdx - README:
packages/adapter-gchat/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-gchat/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.

