Repository navigation
Webhooks get a docs page with a live card preview (GRYT-1187) - #111
Merged
Merged
Conversation
There was no page for webhooks, only six rows in the Server API table. The new one is under Build, next to bots. It covers making a webhook in the app, the URL, curl examples, the full payload, pictures, mentions, the fallback line older clients show, errors, rate limits and three recipes. The payload tables are read from a copy of the server's openapi/webhooks.json and drawn with fumadocs' TypeTable, so nothing about the fields is written by hand. The .md copy of the page gets the same tables as markdown. The preview is a JSON editor with four presets next to the real WebhookCard from @gryt/ui 0.34. It checks the payload as you type and shows the answer the server would give, and it can copy the payload as a curl command. The checks are a small copy of the server's rules rather than zod, to keep the page light. scripts/check-webhook-spec.mjs keeps both honest. It fetches server main and fails when the spec copy differs, when the limits differ, when a problem or warning code has no explanation, or when the preview and the server's own zod schema disagree about any of 3,000 generated payloads. It runs in CI as yarn test:webhook-spec. The preview loads through next/dynamic. Every docs page is one route, so a plain import put its 17 KB of gzipped JS on all of them. Now only this page loads it. About 12 KB of that is @gryt/ui's card, and 8.5 KB of the card is tailwind-merge. Two bugs found on the way have their own tasks: bad JSON and bodies over 2 MB get a 500 instead of a 4xx (GRYT-1198), and webhook rows overflow the server settings dialog (GRYT-1199). The page describes what happens today. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
GRYT-1187. Webhooks had no page of their own, only six rows in the Server API table. This adds Build → Bots and webhooks → Webhooks at
/docs/build/webhooks.What's on the page
text, with the[@name](mention:<id>)syntax and where to copy an IDThe preview
A JSON editor with four presets (Minimal, Rich, Lots of fields, Alert) and the real
WebhookCardfrom@gryt/ui/webhook-card0.34 beside it. It stacks on phones. As you type, it shows the answer the server would give: 200 with anyunknown_keywarnings, or the 400 body with each problem's path and code. Copy as curl copies the payload with a placeholder URL. Pictures load from the typed URLs in your own browser, and the page says Gryt fetches them server-side instead.The preview is compared with the real client. I posted the Rich preset to a throwaway server and screenshotted how the client drew it:
The screenshots live on a
pr-assets/GRYT-1187branch so they don't ship. Delete it whenever.Generated, and checked against the server
src/components/webhooks/openapi.json, a copy of the server'sopenapi/webhooks.json, and drawn with fumadocs'TypeTable. The.mdcopy of the page gets the same tables as markdown, throughsource.config.ts.validate.ts), not zod, to keep the page light.scripts/check-webhook-spec.mjs(yarn test:webhook-spec, now a CI step) fetches server main and fails when:WEBHOOK_LIMITSdiffercodes.tsI checked that it fails by changing one limit and one
maxLengthby hand.JS
Every docs page is one route, so a plain import put the preview on all of them. It now loads through
next/dynamic, and only this page fetches it: 17.3 KB gzipped. Shared JS on other pages is 267 KB gzipped, the same on/docs/build/botsas on this page. About 12.3 KB of the preview is@gryt/ui/webhook-cardand what it pulls in. 8.5 KB of that istailwind-merge(throughcn), 1.9 KB the Phosphor icon, and roughly 2 KB the card itself.global.cssscans onlydist/components/WebhookCardplus the one focus-ring class list, so the CSS doesn't pick up the rest of the library.What to look at
validate.tscopies some zod quirks on purpose, because the server really answers that way. A string wherecardsbelongs getswrong_typeand alsotoo_longwith limit 10. An array'stoo_manycomes after its items' problems.empty_cardis skipped when the card already has a type error. The fuzz check is what pins these.raw.githubusercontent.com. A server PR that changes the spec will turn this repo's CI red until the copy is updated here, which is the point, but it'll show up on an unrelated docs PR.500 internal_error. The spec promises 413 over 256 KB, but a globalexpress.json({ limit: "2mb" })runs before the route's own parser. That's GRYT-1198.https://docs.gryt.chat/webhooks/…, added in this PR. They're neutral placeholders copied from the ui repo, so they 404 until this deploys.@gryt/uigoes from ^0.32.0 to ^0.34.0, andzodis now a direct dev dependency for the check. It was already in the tree through fumadocs.🤖 Generated with Claude Code