Bots get list_hooks, pause_hook and delete_hook, which act directly since they only take away. A new hook, or a new name, brief or filter, or switching a paused one back on, goes through propose_hook: it stores a hook_proposals row and puts a [hook-proposal:ID] card in the reply, which the user it was proposed to confirms or rejects. The card is read from what Confirm saves, with the bot's reason labelled as its own; confirming checks everything again and saves through the Hooks modal's helpers. A new hook's URL is shown on the card once, to the user only, never in the outcome the bot is told. What calls a hook, its computers and its signing are never proposed. Only chat replies propose, and a hook call's own run gets no hook tools, so a caller's payload can't reach them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
/**
|
|
* What calls a hook: an outside service at its URL, or the watcher on a
|
|
* computer forwarding that computer's browser notifications
|
|
* (`syncComputerNotifyWatch`).
|
|
*/
|
|
export const BotHookSources = [
|
|
{ title: "Calls to its URL", value: "url" },
|
|
{ title: "Browser notifications on a computer", value: "browser_notifications" },
|
|
] as const;
|
|
|
|
export type BotHookSource = (typeof BotHookSources)[number]["value"];
|
|
|
|
/**
|
|
* How a hook's sender writes its HMAC-SHA256 signature of the raw body in
|
|
* the signature header: plain hex, GitHub's `sha256=<hex>`, or base64
|
|
* (Shopify and others).
|
|
*/
|
|
export const BotHookSignatureFormats = [
|
|
{ title: "Hex", value: "hex" },
|
|
{ title: "sha256=hex (GitHub)", value: "sha256=hex" },
|
|
{ title: "Base64", value: "base64" },
|
|
] as const;
|
|
|
|
export type BotHookSignatureFormat = (typeof BotHookSignatureFormats)[number]["value"];
|
|
|
|
/**
|
|
* What became of one call to a hook: it queued a run, joined a run still
|
|
* waiting, was refused (a bad signature, a paused hook), repeated a call
|
|
* already taken, or was a notification the hook's filter left out.
|
|
*/
|
|
export const BotHookEventStatuses = [
|
|
{ title: "Queued", value: "queued" },
|
|
{ title: "Merged", value: "merged" },
|
|
{ title: "Rejected", value: "rejected" },
|
|
{ title: "Duplicate", value: "duplicate" },
|
|
{ title: "Ignored", value: "ignored" },
|
|
] as const;
|
|
|
|
export type BotHookEventStatus = (typeof BotHookEventStatuses)[number]["value"];
|
|
|
|
/**
|
|
* Every hook token starts with this, so a leaked one is easy to spot.
|
|
*/
|
|
export const BotHookTokenPrefix = "cbh_";
|
|
|
|
/**
|
|
* The public path a hook is called at: `<BotHookPath>/<token>`.
|
|
*/
|
|
export const BotHookPath = "/api/hooks";
|
|
|
|
/**
|
|
* Headers a sender may use to name a delivery, so a retried call isn't
|
|
* run twice. The first one present wins.
|
|
*/
|
|
export const BotHookIdempotencyHeaders = [
|
|
"idempotency-key",
|
|
"x-github-delivery",
|
|
"x-request-id",
|
|
"x-webhook-id",
|
|
] as const;
|
|
|
|
/**
|
|
* What a bot's hook proposal (`hook_proposals`) does once the user
|
|
* confirms it: make a hook in the conversation it was proposed in, or
|
|
* change one of theirs (its name, brief, filter, or switch it back on).
|
|
* Pausing and deleting need no proposal: they only take away.
|
|
*/
|
|
export const HookProposalActions = [
|
|
{ title: "Add", value: "create" },
|
|
{ title: "Change", value: "change" },
|
|
] as const;
|
|
|
|
export type HookProposalAction = (typeof HookProposalActions)[number]["value"];
|