Draft
Conversation
Implement the full Discord bot following the Vercel chat architecture pattern: - Gateway WebSocket listener (/api/discord/gateway) connects to Discord via discord.js, receives MESSAGE_CREATE events, and forwards them to the webhook handler for unified processing - Webhook handler (/discord/webhook) processes both Discord HTTP Interactions (PING, slash commands) and forwarded Gateway events - Bot processor reuses the platform-agnostic runBot() engine with spawn_cloud_agent tool support, conversation context, and GitHub repository context - All bot API calls use the DISCORD_BOT_TOKEN (Bot auth), not OAuth tokens - Message posting, reactions, and channel context fetching via Discord REST API v10 New dependencies: discord.js, discord-interactions, discord-api-types New env var: DISCORD_PUBLIC_KEY (Ed25519 verification for HTTP Interactions)
discord.js depends on optional native modules (zlib-sync, bufferutil, utf-8-validate) that webpack cannot bundle. Add them to serverExternalPackages so Next.js resolves them at runtime via Node.js instead of trying to bundle them.
3fd2bcf to
9ed1bed
Compare
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
runBot()engine, and replies with AI responsesspawn_cloud_agenttool support for coding tasks on GitHub reposDepends on: #558
Architecture: Gateway-to-Webhook Forwarding
Why Gateway is needed: Discord's HTTP Interactions API only delivers slash commands and component interactions -- not regular chat messages. To receive
@botmentions in channels, a Gateway WebSocket connection is required.How it works:
/api/discord/gatewayevery ~3 mindiscord.js, listens for raw eventsMESSAGE_CREATEevents are forwarded as HTTP POST to/discord/webhookwithx-discord-gateway-tokenheader for authNew files
src/app/api/discord/gateway/route.tssrc/app/discord/webhook/route.tssrc/lib/discord-bot.tsrunBot()engine)src/lib/discord/auth.tssrc/lib/discord/verify-request.tssrc/lib/discord-bot/discord-utils.tssrc/lib/discord-bot/discord-channel-context.tsModified files
src/lib/integrations/discord-service.tspostDiscordMessage,addDiscordReaction,removeDiscordReactionsrc/lib/bot-users/types.ts'discord-bot'toBotTypesrc/lib/feature-detection.ts'discord'toFEATURE_VALUESsrc/lib/config.server.tsDISCORD_PUBLIC_KEYenv varNew dependencies
discord.js,discord-interactions,discord-api-typesNew env var
DISCORD_PUBLIC_KEY-- from the Discord Developer Portal, used for Ed25519 verification of HTTP InteractionsCron setup (for Gateway)
{ "path": "/api/discord/gateway?cron_secret=...", "schedule": "*/3 * * * *" }