@went.tf/discord-bot-framework 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -480,6 +480,73 @@ process is never restarted. Fall back to a real restart for those, and for
480
480
  anything that needs `beforeSpawn`'s one-time setup (e.g. slash command
481
481
  registration) to re-run.
482
482
 
483
+ ### `@went.tf/discord-bot-framework/webhook` (experimental)
484
+
485
+ > **Experimental, unvalidated against a real bot.** Unlike every other
486
+ > subpath in this package, `./webhook` hasn't yet been proven against a real
487
+ > migration — see the scope note at the end of this section and CLAUDE.md's
488
+ > `./webhook` design-decision entry. The API may change in a minor/patch
489
+ > release until that validation happens, despite semver-major otherwise being
490
+ > reserved for breaking changes in this package.
491
+
492
+ An alternate, independent transport alongside `./client`'s gateway-based
493
+ `createBotClient`/`createShardManager`, for bots that want to receive
494
+ interactions over an HTTP Interactions Endpoint instead of holding a
495
+ WebSocket open. As with `createBotClient`/`createShardManager`, this doesn't
496
+ unify with the gateway path behind one entry point — pick one transport per
497
+ bot and use its functions directly.
498
+
499
+ `verifyInteractionRequest` checks a request's `X-Signature-Ed25519`/
500
+ `X-Signature-Timestamp` headers against your application's public key, using
501
+ Node's native `crypto` module (no `tweetnacl`/`discord-interactions`
502
+ dependency needed). `handleWebhookInteractionRequest` wraps that plus
503
+ Discord's PING→PONG endpoint-validation handshake around your own handler,
504
+ taking/returning plain data so it can be wired into any HTTP framework (or
505
+ none):
506
+
507
+ ```ts
508
+ import { handleWebhookInteractionRequest } from '@went.tf/discord-bot-framework/webhook';
509
+ import { createServer } from 'node:http';
510
+
511
+ createServer(async (req, res) => {
512
+ const chunks: Buffer[] = [];
513
+ for await (const chunk of req) chunks.push(chunk);
514
+ const rawBody = Buffer.concat(chunks);
515
+
516
+ const { status, body } = await handleWebhookInteractionRequest(
517
+ {
518
+ signature: req.headers['x-signature-ed25519'] as string,
519
+ timestamp: req.headers['x-signature-timestamp'] as string,
520
+ rawBody,
521
+ },
522
+ {
523
+ publicKey: env.DISCORD_PUBLIC_KEY,
524
+ logger,
525
+ onInteraction: (interaction) => handleInteraction(interaction), // bot-side: build an APIInteractionResponse
526
+ },
527
+ );
528
+ res.writeHead(status, { 'Content-Type': 'application/json' }).end(JSON.stringify(body));
529
+ }).listen(3000);
530
+ ```
531
+
532
+ `createWebhookInteractionResponder` gives you the REST calls needed *after*
533
+ that initial response — editing a deferred reply, sending a follow-up, or
534
+ deleting the reply — built on `@discordjs/rest` (already a peer dependency):
535
+
536
+ ```ts
537
+ import { createWebhookInteractionResponder } from '@went.tf/discord-bot-framework/webhook';
538
+
539
+ const responder = createWebhookInteractionResponder({ rest, applicationId, interactionToken: interaction.token });
540
+ await responder.editReply({ content: 'Done!' });
541
+ ```
542
+
543
+ **This is not a drop-in replacement for discord.js's `Interaction#reply()`/
544
+ `editReply()`/`options.get*()` surface.** It's intentionally the thinner,
545
+ already-validated half of that problem (signature verification, the PING
546
+ handshake, and the plain REST calls) — see CLAUDE.md's `./webhook`
547
+ design-decision entry for why a discord.js-`Interaction`-shaped compatibility
548
+ adapter isn't built here yet.
549
+
483
550
  ### `@went.tf/discord-bot-framework/dev`
484
551
 
485
552
  Live-reloads compiled command/interaction handler *implementations* during