Skip to content

feat: Discord chat integration (alongside Slack and Teams) #2

Closed

Description

@scttfrdmn

Summary

Add Discord as a third chat platform for instance control and lifecycle notifications, alongside the existing Slack and Microsoft Teams integrations.

Motivation

Many research groups and indie/OSS communities coordinate on Discord rather than Slack or Teams. Supporting Discord would let those users control spawn instances and receive lifecycle notifications (idle warnings, TTL expiry, spot interruptions, completion) without leaving their existing workflow.

What exists today

Chat integration lives in the spawn repo:

  • cmd/bot.go — spawn notify / spawn bot command tree (register, deregister, enable, disable, list, workspace-add/remove/list)
  • Platform routing keyed on a --platform flag (currently slack, teams)
  • Workspace credentials stored per platform (workspace/tenant ID, bot token, signing secret)
  • spored sends lifecycle notifications to the configured platform via the notifier

Docs: docs/guides/slack-setup.md, docs/guides/teams-setup.md, docs/spore-bot-self-hosting.md.

Proposed scope

1. Platform support

  • Add discord as a valid --platform value in spawn notify commands
  • spawn notify workspace-add --platform discord --workspace-id <GUILD_ID> --bot-token <BOT_TOKEN> (Discord uses a bot token; no separate signing secret — interactions use a public key for signature verification instead)
  • spawn notify register --platform discord --platform-id <DISCORD_USER_ID> --workspace-id <GUILD_ID> --nickname <NAME> --instance-id <ID>

2. Slash commands

Mirror the existing Slack/Teams slash commands as Discord application commands:

  • /spore list — registered instances
  • /spore status <name> — state, URL, TTL countdown
  • /spore extend <name> <duration> — extend TTL
  • /spore stop <name> — stop without SSH

Discord slash commands are registered via the application command API and dispatched through an Interactions endpoint (HTTP webhook with Ed25519 signature verification) — analogous to the Slack events endpoint and Teams bot messaging endpoint already handled in the rest-api Lambda.

3. Notifications

  • spored's notifier gains a Discord sender: POST to a Discord webhook URL (or bot DM via the REST API) for idle/TTL/spot/completion events
  • Format messages with Discord embeds (title, color-coded by event severity, fields for cost/TTL)

4. Interactions endpoint

  • The hosted rest-api Lambda (now in spore-host/spore-host) handles the inbound Slack/Teams webhooks. A Discord interactions handler would be added there with Ed25519 signature verification (Discord's required PING/PONG handshake + request signing).

Implementation notes

  • Discord auth model differs from Slack/Teams: bot token for outbound, Ed25519 public-key signature verification for inbound interactions (not HMAC). The platform abstraction in cmd/bot.go and the notifier interface should accommodate this.
  • Library: github.com/bwmarrin/discordgo is the de-facto Go Discord library, or call the REST/Gateway API directly to avoid a heavy dependency.
  • Self-hosting guide will need a Discord section (create application, add bot, register slash commands, set interactions endpoint URL).

Acceptance criteria

  • spawn notify workspace-add --platform discord ... works
  • spawn notify register --platform discord ... works
  • /spore list|status|extend|stop slash commands work in a Discord server
  • Lifecycle notifications (idle/TTL/spot/completion) delivered to Discord
  • Discord interactions endpoint with Ed25519 signature verification in the rest-api Lambda
  • docs/guides/discord-setup.md written, mirroring the Slack/Teams setup guides

Related

  • Slack integration: docs/guides/slack-setup.md
  • Teams integration: docs/guides/teams-setup.md
  • spore-bot self-hosting: docs/spore-bot-self-hosting.md

Activity

  1. added
    enhancement
    on May 29, 2026
  2. scttfrdmn commented on May 29, 2026

    @scttfrdmn
    ContributorAuthor

    Note on where the webhook backend lives: The chat webhook backend (spore-bot Lambda — Slack/Teams interactions, slash-command dispatch) has been moved to the infrastructure monorepo at spore-host/spore-host under lambda/spore-bot/. It's a hosted service with no spawn/truffle coupling.

    So this feature spans two repos:

    • spore-host/spawn — cmd/bot.go: add discord as a --platform value for the spawn notify CLI commands
    • spore-host/spore-host — lambda/spore-bot/: add the Discord interactions handler (Ed25519 signature verification) and Discord notification sender

    The Discord setup guide goes in spore-host/spore-host under docs/guides/discord-setup.md.

  3. scttfrdmn commented on Jun 14, 2026

    @scttfrdmn
    ContributorAuthor

    Implementation plan (traced against current code, 2026-06-14)

    Confirmed the architecture and the exact seams. Key finding: spored never talks to chat platforms — its notifier (spawn/pkg/agent/notifier.go) POSTs a generic event (platform, workspace_id, event type, PKCS7 identity) to the spore-bot Lambda's /notify, and the Lambda owns all platform-specific formatting + delivery. So the spawn side is thin; the bulk is the umbrella spore-host/spore-host lambda/spore-bot/.

    The feature splits cleanly into outbound notifications and inbound slash commands, with different difficulty, so I recommend phasing.

    Phase 1 — Outbound Discord notifications (self-contained, high value)

    spawn repo:

    • pkg/agent/notifier.go: platform is currently hardcoded "slack" (line ~76). Add a NotifyPlatform to pkg/provider config, read from a new spawn:notify-platform tag (pkg/provider/ec2.go, alongside the existing notify-command/slack-workspace-id cases) and a --notify-platform launch flag; thread it into the notifier instead of the constant.
    • cmd/bot.go: accept discord in workspace-add — Discord has no signing secret, so make --signing-secret not-required for discord and add --public-key (Ed25519, used in Phase 2) + reuse --webhook-url for the channel webhook. --platform help text → slack, teams, or discord.

    umbrella lambda/spore-bot/:

    • registry.go: add PublicKey field to WorkspaceConfig (Discord interactions key). IncomingWebhookURL and BotToken already exist and are reused as-is.
    • notify.go: branch on nr.Platform == "discord" → post a Discord embed to the workspace's webhook URL (mirror postIncomingWebhook; embed with color-by-severity + cost/TTL fields). DM path via the bot REST API optional/later.
    • New discord.go: formatDiscordNotification / embed builder.
    • Doc: spore-host/spore-host docs/guides/discord-setup.md (create a Discord app, bot token, channel webhook).

    Phase 2 — Inbound slash commands (the harder half)

    umbrella lambda/spore-bot/ only:

    • handler.go: add a /discord route case (mirrors /slack, /teams).
    • discord.go: Ed25519 signature verification (Discord's scheme — distinct from Slack's HMAC in slack.go:verifySlackSignature and the PKCS7/RSA in signature.go); the required PING (type 1) → PONG handshake; parse an application-command interaction → the existing SlashCommand struct; map /spore list|status|extend|stop. Discord requires a response within 3s → use a deferred-response (type 5) + follow-up via the interaction token, analogous to Slack's response_url async path (handleAsyncAction).
    • registry.go: GetWorkspaceForSlash handle discord (key by guild ID; Discord doesn't send an app-id header, like Teams).
    • One-time application-command registration with Discord's API (a scripts/ helper or a spawn notify register-commands --platform discord subcommand).

    Notes / decisions to make

    • Verification differs per platform: Slack HMAC-SHA256, Teams bearer/JWT, Discord Ed25519 over (timestamp+body). Phase 2 adds the third verifier alongside the existing two.
    • 3-second interaction deadline is the one Discord-specific gotcha vs Slack — defer + follow-up is required for status/extend/stop (anything doing AWS calls).
    • Registry schema change (PublicKey) is additive/back-compat.

    Suggested order: Phase 1 first (notifications work end-to-end, no interactions endpoint needed), Phase 2 after. Happy to start on Phase 1 when prioritized.

  4. scttfrdmn commented on Jun 14, 2026

    @scttfrdmn
    ContributorAuthor

    Phase 1 shipped — Discord lifecycle notifications

    Merged across both repos:

    What works now:

    # one-time: register the Discord server + channel webhook
    spawn notify workspace-add --platform discord --workspace-id <GUILD_ID> \
      --webhook-url https://discord.com/api/webhooks/<id>/<token>
    
    # launch with Discord notifications
    spawn launch rstudio --slack-workspace <GUILD_ID> --notify-platform discord

    Lifecycle events (TTL warn, idle stop/hibernate, spot interrupt, completion) post as color-coded Discord embeds to the channel webhook. Default platform stays slack, so existing launches are unchanged. Discord uses an Ed25519 public key (no signing secret) — --public-key is accepted now and used by Phase 2. Setup guide: docs/guides/discord-setup.md in the umbrella repo.

    Phase 2 — remaining (inbound slash commands)

    Still to do, all in lambda/spore-bot/:

    • /discord route in handler.go + Ed25519 interaction verification (vs Slack HMAC / Teams JWT)
    • Discord's PING (type 1) → PONG handshake
    • Parse application-command interaction → existing SlashCommand; map /spore list|status|extend|stop
    • 3-second-deadline deferred response (type 5) + follow-up via interaction token (analogous to Slack's response_url async path)
    • One-time application-command registration with Discord's API

    Leaving this issue open for Phase 2.

  5. scttfrdmn commented on Jun 14, 2026

    @scttfrdmn
    ContributorAuthor

    Phase 2 merged — Discord slash commands (multi-tenant)

    spore-host/spore-host#362 is in. The /spore Discord commands are now implemented as a multi-tenant app: any user installs the published spore-bot application into their own guild and controls their own instances — separate from the community spore.host server.

    What's implemented:

    • /discord interactions endpoint on the existing Lambda Function URL (beside /slack, /teams).
    • Ed25519 request verification using the per-application public key (Discord has no signing secret), PING/PONG endpoint handshake.
    • /spore list|status|start|stop|hibernate|url|extend|connect dispatched through the same BotAction/executeAction machinery as Slack/Teams, with a deferred ack (type 5) + follow-up edit to meet Discord's 3-second deadline.
    • scripts/register-discord-commands.sh for one-time global command registration; docs/guides/discord-setup.md covers the full install/registration flow.
    • Reuses the existing guild-keyed registry; spawn notify workspace-add --platform discord --public-key … (Phase 1) is how each guild onboards.

    Tests: Ed25519 verify (valid/tampered/wrong-key/bad-input), interaction parse, follow-up URL — all green.

    Remaining: live verification (post-deploy)

    Two things need a real deployed endpoint + a Discord application, the same way Phase 1 was validated against a live webhook:

    1. Discord's endpoint-verification PING succeeds when saving the Interactions Endpoint URL (proves Ed25519 + PONG).
    2. A real /spore status <name> round-trips (deferred ack → follow-up result) in a test guild.

    Both code paths are unit-tested; this is the deploy-time smoke test. Leaving #2 open until that's confirmed, then it closes as fully shipped (notifications + commands).

  6. scttfrdmn commented on Jun 14, 2026

    @scttfrdmn
    ContributorAuthor

    ✅ Phase 2 verified live — #2 complete

    Both phases of Discord support are now confirmed working in production:

    • Endpoint verification: the Discord developer portal verified the Interactions Endpoint URL (signed PING → PONG against the application's Ed25519 key).
    • Full slash-command round-trip: /spore in a registered guild returns the deferred "spore.host is thinking…" ack, then edits in the real result via the interaction follow-up — exercising Ed25519 verify → guild authorization → deferred response → async executeAction → postDiscordResponse.

    Verified with the app displaying as spore.host (with the mascot avatar), a guild-scoped command registration, and the empty-state list response rendering correctly.

    Bug found + fixed during live setup

    The first endpoint-save failed ("interactions_endpoint_url could not be verified") because the handler verified against a per-guild workspace key and 401'd the guild-less PING. Fixed (#364): verification now uses the application public key (DISCORD_PUBLIC_KEY, one per app) before any workspace lookup; the per-guild lookup only authorizes commands afterward.

    Shipped

    • Phase 1 (notifications): spawn v0.52.0 + spore-bot Lambda — live-validated against a real channel webhook earlier.
    • Phase 2 (slash commands): spore-bot /discord interactions endpoint, scripts/register-discord-commands.sh, docs/guides/discord-setup.md.
    • Multi-tenant by design: any user installs the app into their own guild and registers via spawn notify workspace-add --platform discord.

    Closing as done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions