Repository navigation
feat(webhook): add generic webhook adapter for arbitrary HTTP platforms - #1033
Draft
roboeve[bot] wants to merge 7 commits into
Draft
roboeve[bot] wants to merge 7 commits into
roboeve[bot] wants to merge 7 commits into
Conversation
Add @chat-adapter/webhook for platforms without a dedicated adapter. A parse callback maps verified webhook requests to messages and a send callback delivers replies over HTTP, with optional edit, delete, and startTyping callbacks. Requests are verified with an HMAC-SHA256 signature (WEBHOOK_SECRET) or a custom verify function. Closes #96
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The custom verify example built its expected credential from process.env.BRIDGE_TOKEN without checking it, so an unset variable produced the guessable value "Bearer undefined" and let forged requests through. Throw at startup when the token is missing and call out the pattern for custom verify functions.
…dleWebhook had already dispatched the earlier ones and then threw, so a platform retry processed them again. Build all messages inside the parse error handler and return 500 before dispatching. Also add the required state adapter to the README example.
Contributor
Author
|
CI failed at Pushed 858a6f2, which regenerates |
…os and catalog so the adapter page header and listing cards show it. Move the WEBHOOK_SECRET note into the info callout used by other quick starts, add a Limitations section, and give the README the OG banner and Environment variables section other adapter READMEs have. Revert the README install line to the adapter package only, matching the other READMEs.
…cs section, bump to 4.43.0)
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
@chat-adapter/webhook, a generic adapter for platforms that have no dedicated adapter but can POST a webhook and accept replies over HTTP. Closes #96.You describe the platform with two functions, and the adapter handles everything that is the same across HTTP platforms:
Design
parsefunction instead of per-field getters. The issue sketchesgetText,getSenderId, andgetChannelId. A single function that returns{ channelId, threadId?, text, author, id?, isMention?, timestamp?, attachments? }covers the same ground, lets one request produce several messages (or none, for receipts and echoes), and keeps related mapping logic in one place.WEBHOOK_SECRET,x-webhook-signatureheader, optionalsha256=prefix, configurable withsignatureHeader). Averifycallback replaces this for other schemes.createWebhookAdapterthrows when neither a secret norverifyis set, so an endpoint never accepts unauthenticated messages by accident.edit,delete, andstartTypingenable the matching adapter methods. Withoutedit,streambuffers and sends once; with it,streamreturnsnullso core uses its post+edit fallback. Missing edit, delete, and reactions throwNotImplementedError.name(defaultwebhook) is the thread ID prefix and must match the key inadapters, because Chat SDK routes thread IDs by prefix. Thread IDs are{name}:{base64url(channel)}[:{base64url(thread)}], so any platform ID round-trips.persistThreadHistoryistrue, since HTTP platforms rarely expose history;fetchMessagesreturns nothing and core serves history from the state adapter.WebhookAdapterConfig, soparse: (event: MyPayload) => ...type-checks without casts, andsendmay return nothing.The adapter is registered like other official adapters: catalog entry (
beta: true), docs page at/adapters/official/webhook,create-chat-sdkscaffold spec (placeholderparse/send), root Vitest project,turbo.jsonenv, and a changeset.Out of scope for this first version: GET verification handshakes (handle them in the route before calling
bot.webhooks.<name>), non-JSON bodies (override the protectedparseBody), reactions, actions, and DM detection.Test plan
pnpm --filter @chat-adapter/webhook test: 43 tests, including signature verification (valid, missing, wrong secret, tampered body, custom header, unprefixed digest),verifyoverride and throwingverify, 405/400/500 paths, array and emptyparseresults, outboundsend/edit/delete/startTyping, buffered vs. deferred streaming, the sharedthreadIdContract, and an end-to-end run through a realChatinstance that routes a signed webhook toonNewMentionand replies throughsend.types.test-d.ts: typedparsepayloads and void-returning callbacks compile; protected members stay accessible to subclasses.pnpm --filter @chat-adapter/catalog test,pnpm --filter create-chat-sdk test, andpnpm --filter @chat-adapter/integration-tests test(docs/catalog parity, package metadata, README discoverability) pass.pnpm knip,pnpm check,pnpm konsistent,turbo typecheck(all 49 tasks),turbo test --filter='!docs'(all 58 tasks), andturbo build --filter='!docs'pass. The docs app build ran out of memory in my sandbox, so CI is the first full check of the new MDX page.create-chat-sdkoutput type-check against the package.Checklist
git commit -s): the signed commit has noSigned-off-bytrailer, so a maintainer may need to add onepnpm validatesteps pass, except the docs app build (see test plan)