Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ For example, `npx giget@latest gh:hookdeck/hookdeck-demos/deepgram/stt-tts my-de
|---------|-------------|
| [ds](_shared/ds/) | Hookdeck design system: tokens, styles and brand assets (copied into demos, see Shared code) |
| [flow-drawer](_shared/flow-drawer/) | Bottom drawer that shows each message moving through Event Gateway to the app, live (client JS and CSS, plus a server module that reads the Hookdeck API) |
| [hookdeck](_shared/hookdeck/) | Hookdeck CLI helper and `hookdeck listen` wrapper (TypeScript) |
| [hookdeck](_shared/hookdeck/) | Hookdeck API helper for setup, and the Hookdeck CLI helper and `hookdeck listen` wrapper (TypeScript) |
| [scenes](_shared/scenes/) | Scene kit: animated topology diagrams for a demo's live view, hookdeck.com guides and MP4 captures (TypeScript, SVG, GSAP) |
| [theme](_shared/theme/) | Light/dark/system theme switch for the design system, with an optional demo theme and wording (`theme.js`) |
| [tmux-presenter](_shared/tmux-presenter/) | Tmux-based live demo presenter for running scripted terminal demos |
| [topology-pane](_shared/topology-pane/) | Bottom "Data flow" pane that shows the scene kit's live topology and scripted scenes |

## Shared code

Some code is the same in several demos: the Hookdeck design system (`ds/`), the Hookdeck CLI helpers (`scripts/hookdeck-cli.ts`, `scripts/hookdeck-listen.ts`), the data-flow drawer (`flow-drawer/`), the scene kit (`scenes/`), the topology pane (`topology-pane/`) and the theme switch (`theme.js`). So a demo still works when downloaded alone, each demo holds a real copy of what it uses. The source of truth is `_shared/`.
Some code is the same in several demos: the Hookdeck design system (`ds/`), the Hookdeck API and CLI helpers (`scripts/hookdeck-api.ts`, `scripts/hookdeck-cli.ts`, `scripts/hookdeck-listen.ts`), the data-flow drawer (`flow-drawer/`), the scene kit (`scenes/`), the topology pane (`topology-pane/`) and the theme switch (`theme.js`). So a demo still works when downloaded alone, each demo holds a real copy of what it uses. The source of truth is `_shared/`.

- **Edit in `_shared/` only.** Copies carry a "Generated from" header (directories also have a `GENERATED.md`), so an edit in the wrong place is easy to spot in review.
- **`_shared/manifest.json`** lists which demo takes which piece and where it goes inside the demo. A demo not listed for a piece may own its own copy.
Expand Down
44 changes: 44 additions & 0 deletions _shared/hookdeck/hookdeck-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Hookdeck REST API helper for demo setup and probe scripts.
*
* Calls the API with the project API key in HOOKDECK_API_KEY (loaded from .env), so it
* works on the project that key belongs to. Setup creates the Event Gateway source,
* destination and connection with it; the Hookdeck CLI is only used by `npm run listen`.
*
* Needs Node 22+ (global fetch) and `dotenv` in the demo.
*
* const connection = await hookdeck('PUT', '/connections', {
* name: 'my-connection',
* source: { name: 'my-source', type: 'WEBHOOK' },
* destination: { name: 'local-my-app', type: 'CLI', config: { path: '/webhooks' } },
* });
* console.log(connection.source.url);
*
* API reference: https://hookdeck.com/docs/api
*/
import 'dotenv/config';

export const HOOKDECK_API_BASE = 'https://api.hookdeck.com/2026-09-01';

/** The project API key from HOOKDECK_API_KEY. Exits with a hint when it isn't set. */
export function requireHookdeckApiKey(): string {
const key = process.env.HOOKDECK_API_KEY;
if (!key || key.startsWith('your_')) {
console.error('❌ HOOKDECK_API_KEY is not set. Add a project API key to .env');
console.error(' (Hookdeck dashboard: Project settings -> Secrets, https://dashboard.hookdeck.com/settings/project/secrets).');
process.exit(1);
}
return key;
}

/** Calls the Hookdeck API and returns the parsed JSON response. Throws on a non-2xx status. */
export async function hookdeck<T = any>(method: string, route: string, body?: unknown): Promise<T> {
const response = await fetch(`${HOOKDECK_API_BASE}${route}`, {
method,
headers: { authorization: `Bearer ${requireHookdeckApiKey()}`, 'content-type': 'application/json' },
body: body === undefined ? undefined : JSON.stringify(body),
});
const text = await response.text();
if (!response.ok) throw new Error(`Hookdeck API ${method} ${route} -> ${response.status}: ${text.slice(0, 300)}`);
return text ? JSON.parse(text) : (undefined as T);
}
4 changes: 2 additions & 2 deletions _shared/hookdeck/hookdeck-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function createHookdeckCli(options: HookdeckCliOptions = {}) {
const key = process.env.HOOKDECK_API_KEY;
if (!key || key.startsWith('your_')) {
console.error('❌ HOOKDECK_API_KEY is not set. Add a project API key to .env');
console.error(' (Hookdeck dashboard: Project settings -> API keys).');
console.error(' (Hookdeck dashboard: Project settings -> Secrets, https://dashboard.hookdeck.com/settings/project/secrets).');
process.exit(1);
}
return key;
Expand Down Expand Up @@ -200,7 +200,7 @@ export function createHookdeckCli(options: HookdeckCliOptions = {}) {
return withPrivateJson(`rules-${spec.name}.json`, spec.rules, (file) => json([...args, '--rules-file', file]));
}

/** Reads from the Hookdeck API with the project API key. The demos' probe scripts use it to find a source and list its requests; setup goes through the CLI only. */
/** Calls the Hookdeck API with the project API key. Demos that set up through the API use hookdeck-api.ts instead. */
async function api<T = any>(method: string, route: string, body?: unknown): Promise<T> {
const response = await fetch(`${api_base}${route}`, {
method,
Expand Down
54 changes: 54 additions & 0 deletions _shared/hookdeck/hookdeck-signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Verifies the `x-hookdeck-signature` header Event Gateway adds to every delivery.
*
* The signature is the base64 HMAC-SHA256 of the raw request body, keyed with the project
* signing secret (HOOKDECK_SIGNING_SECRET, copied from the dashboard into .env). It has no
* timestamp on purpose: Event Gateway verified the sender's own signature when it accepted
* the request, so a retry or replay hours later is legitimate and must still pass.
*
* While a rolled secret is still active, Hookdeck also sends `x-hookdeck-signature-2`.
*
* Reference: https://hookdeck.com/docs/authentication#hookdeck-webhook-signature-verification
*/
import 'dotenv/config';
import { createHmac, timingSafeEqual } from 'crypto';

export const HOOKDECK_SECRETS_URL = 'https://dashboard.hookdeck.com/settings/project/secrets';

/** The project signing secret from HOOKDECK_SIGNING_SECRET. Exits with a hint when it isn't set. */
export function requireHookdeckSigningSecret(): string {
const secret = process.env.HOOKDECK_SIGNING_SECRET;
if (!secret || secret.startsWith('your_')) {
console.error('❌ HOOKDECK_SIGNING_SECRET is not set. Add the project signing secret to .env');
console.error(` (Hookdeck dashboard: Project settings -> Secrets, ${HOOKDECK_SECRETS_URL}).`);
process.exit(1);
}
return secret;
}

/** The signature Hookdeck sends for a body: base64 HMAC-SHA256 of the raw bytes. */
export function signHookdeckBody(raw_body: Buffer | string, secret: string): string {
return createHmac('sha256', secret).update(raw_body).digest('base64');
}

function sameSignature(expected: string, received: string): boolean {
const expected_bytes = Buffer.from(expected, 'utf8');
const received_bytes = Buffer.from(received, 'utf8');
// timingSafeEqual throws on different lengths, so check the length first
return expected_bytes.length === received_bytes.length && timingSafeEqual(expected_bytes, received_bytes);
}

/**
* True when `signature_header` (x-hookdeck-signature) matches the raw body signed with `secret`.
* Pass `signature_header_2` (x-hookdeck-signature-2) to also accept the previous secret's signature.
*/
export function verifyHookdeckSignature(
raw_body: Buffer | string,
signature_header: string | undefined,
secret: string | undefined,
signature_header_2?: string,
): boolean {
if (!secret) return false;
const expected = signHookdeckBody(raw_body, secret);
return [signature_header, signature_header_2].some((header) => Boolean(header) && sameSignature(expected, header as string));
}
12 changes: 11 additions & 1 deletion _shared/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"pieces": {
"ds": "_shared/ds",
"hookdeck-cli": "_shared/hookdeck/hookdeck-cli.ts",
"hookdeck-api": "_shared/hookdeck/hookdeck-api.ts",
"hookdeck-listen": "_shared/hookdeck/hookdeck-listen.ts",
"flow-drawer": "_shared/flow-drawer/client",
"flow-drawer-server": "_shared/flow-drawer/server.ts",
"scenes": "_shared/scenes",
"topology-pane": "_shared/topology-pane",
"theme": "_shared/theme/theme.js"
"theme": "_shared/theme/theme.js",
"hookdeck-signature": "_shared/hookdeck/hookdeck-signature.ts"
},
"demos": {
"deepgram/stt-tts": {
Expand All @@ -26,35 +28,43 @@
},
"vapi/agency-routing": {
"ds": "public/ds",
"hookdeck-api": "scripts/hookdeck-api.ts",
"hookdeck-cli": "scripts/hookdeck-cli.ts",
"hookdeck-listen": "scripts/hookdeck-listen.ts",
"hookdeck-signature": "src/hookdeck-signature.ts",
"flow-drawer-server": "src/flow-drawer-server.ts",
"scenes": "scenes/kit",
"topology-pane": "public/topology-pane",
"theme": "public/theme.js"
},
"elevenlabs/post-call-transcripts": {
"ds": "public/ds",
"hookdeck-api": "scripts/hookdeck-api.ts",
"hookdeck-cli": "scripts/hookdeck-cli.ts",
"hookdeck-listen": "scripts/hookdeck-listen.ts",
"hookdeck-signature": "src/hookdeck-signature.ts",
"flow-drawer-server": "src/flow-drawer-server.ts",
"scenes": "scenes/kit",
"topology-pane": "public/topology-pane",
"theme": "public/theme.js"
},
"retell/outbound-lead-calling": {
"ds": "public/ds",
"hookdeck-api": "scripts/hookdeck-api.ts",
"hookdeck-cli": "scripts/hookdeck-cli.ts",
"hookdeck-listen": "scripts/hookdeck-listen.ts",
"hookdeck-signature": "src/hookdeck-signature.ts",
"flow-drawer-server": "src/flow-drawer-server.ts",
"scenes": "scenes/kit",
"topology-pane": "public/topology-pane",
"theme": "public/theme.js"
},
"livekit/voice-adventure": {
"ds": "public/ds",
"hookdeck-api": "scripts/hookdeck-api.ts",
"hookdeck-cli": "scripts/hookdeck-cli.ts",
"hookdeck-listen": "scripts/hookdeck-listen.ts",
"hookdeck-signature": "src/hookdeck-signature.ts",
"flow-drawer-server": "src/flow-drawer-server.ts",
"scenes": "scenes/kit",
"topology-pane": "public/topology-pane",
Expand Down
2 changes: 1 addition & 1 deletion deepgram/stt-tts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DEEPGRAM_API_KEY=your_deepgram_api_key_here

# Hookdeck project API key (REQUIRED)
# Hookdeck dashboard: Project settings -> API keys. `npm run setup` creates the
# Hookdeck dashboard: Project settings -> Secrets (https://dashboard.hookdeck.com/settings/project/secrets). `npm run setup` creates the
# connections in this project and `npm run listen` forwards its two sources, using
# a CLI config file of their own, so your interactive `hookdeck login` is untouched.
HOOKDECK_API_KEY=your_hookdeck_api_key_here
Expand Down
2 changes: 1 addition & 1 deletion deepgram/stt-tts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cp .env.example .env
Add two keys to `.env`:

- `DEEPGRAM_API_KEY`: from the [Deepgram Console](https://console.deepgram.com/)
- `HOOKDECK_API_KEY`: a Hookdeck project API key (Project settings -> API keys)
- `HOOKDECK_API_KEY`: a Hookdeck project API key (Project settings -> [Secrets](https://dashboard.hookdeck.com/settings/project/secrets))

```env
DEEPGRAM_API_KEY=your_deepgram_api_key_here
Expand Down
4 changes: 2 additions & 2 deletions deepgram/stt-tts/scripts/hookdeck-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function createHookdeckCli(options: HookdeckCliOptions = {}) {
const key = process.env.HOOKDECK_API_KEY;
if (!key || key.startsWith('your_')) {
console.error('❌ HOOKDECK_API_KEY is not set. Add a project API key to .env');
console.error(' (Hookdeck dashboard: Project settings -> API keys).');
console.error(' (Hookdeck dashboard: Project settings -> Secrets, https://dashboard.hookdeck.com/settings/project/secrets).');
process.exit(1);
}
return key;
Expand Down Expand Up @@ -201,7 +201,7 @@ export function createHookdeckCli(options: HookdeckCliOptions = {}) {
return withPrivateJson(`rules-${spec.name}.json`, spec.rules, (file) => json([...args, '--rules-file', file]));
}

/** Reads from the Hookdeck API with the project API key. The demos' probe scripts use it to find a source and list its requests; setup goes through the CLI only. */
/** Calls the Hookdeck API with the project API key. Demos that set up through the API use hookdeck-api.ts instead. */
async function api<T = any>(method: string, route: string, body?: unknown): Promise<T> {
const response = await fetch(`${api_base}${route}`, {
method,
Expand Down
17 changes: 12 additions & 5 deletions elevenlabs/post-call-transcripts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
ELEVENLABS_AGENT_ID=

# Hookdeck project API key (REQUIRED)
# Hookdeck dashboard: Project settings -> API keys. `npm run setup` creates the
# connection in this project and `npm run listen` forwards its source, using a CLI
# config file of its own, so your interactive `hookdeck login` is untouched.
# Hookdeck dashboard: Project settings -> Secrets (https://dashboard.hookdeck.com/settings/project/secrets). `npm run setup` creates the
# connection in this project with the Hookdeck API. `npm run listen` forwards its
# source with the Hookdeck CLI, using a config file of its own, so your interactive
# `hookdeck login` is untouched.
HOOKDECK_API_KEY=your_hookdeck_api_key_here

# Hookdeck project signing secret (REQUIRED)
# Hookdeck dashboard: Project settings -> Secrets, https://dashboard.hookdeck.com/settings/project/secrets.
# The app verifies the x-hookdeck-signature header on every delivery with it, and answers 401 when it
# is missing or wrong. The API key cannot read it, so copy it here by hand.
HOOKDECK_SIGNING_SECRET=your_hookdeck_signing_secret_here

# Server port (optional)
PORT=4000

Expand All @@ -29,8 +36,8 @@ PORT=4000
# Hookdeck source URL that ElevenLabs sends post-call webhooks to
ELEVENLABS_WEBHOOK_URL=
# Signing secret of the ElevenLabs workspace webhook (also set on the Hookdeck source).
# Hookdeck verifies the ElevenLabs-Signature with it; the app only uses it to show the
# result of the SDK's constructEvent next to each delivery.
# Hookdeck verifies the ElevenLabs-Signature with it. The app does not check that header; this
# secret is also used by `npm run send` and `npm run probe` to sign sample requests.
ELEVENLABS_WEBHOOK_SECRET=
# ID of the ElevenLabs workspace webhook
ELEVENLABS_WEBHOOK_ID=
Loading
Loading