akilesh_him/disc-deploy-bot
Public
wasmer run akilesh_him/disc-deploy-bot

disc-deploy-bot

A Discord slash-command bot that publishes a static site and replies with its live URL. It deploys to Cloudflare Pages, Surge.sh, and Wasmer Edge, and is built to run as a stateless HTTP service on Wasmer Edge.

/deploy provider:cloudflare  file:site.zip  project_name:my-portfolio
→ ✅ Deployed to Cloudflare Pages
  https://my-portfolio.pages.dev

Why it works on Wasmer Edge

  • No gateway / WebSocket. There is no discord.js client. Discord sends signed HTTP POSTs to /interactions; the bot verifies them with discord-interactions' verifyKey().
  • No shell subprocesses. No wrangler or surge binaries. Every provider is called through its documented REST API with fetch(), and Wasmer deployments use @wasmer/sdk.
  • Deferred responses. Deployments take longer than Discord's 3-second limit. The bot immediately answers type: 5 (DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE), uploads in the background, then edits the original message via PATCH /webhooks/{application_id}/{token}/messages/@original.
  • Everything in memory. Attachments are downloaded with fetch(), ZIPs are expanded with JSZip, and Surge's tarball is created in memory. Nothing is written to disk, so read-only sandboxes are fine.
  • One small HTTP server. src/index.js uses Node's built-in http module, listens on PORT, and exposes POST /interactions plus GET /healthz.
Discord ──POST /interactions──▶ verify Ed25519 signature ──▶ allowlist
                                     │
                                     ├─ type 5 (deferred) ──▶ Discord
                                     │
                                     └─ background: download ─▶ unzip ─▶ provider REST API
                                                                         │
                       PATCH @original ◀── live URL / error ◀────────────┘

Requirements

  • Node.js 20+ (Node 24 recommended; the Wasmer provider needs WebAssembly support).
  • A Discord application with a bot token.
  • Credentials for at least one provider.
  • For Wasmer Edge: the Wasmer CLI.

1. Create the Discord application

  1. Open https://discord.com/developers/applications → New Application.
  2. General Information: copy Application ID and Public Key.
  3. Bot: reset and copy the Bot Token. No privileged intents are required.
  4. OAuth2 → URL Generator: select scopes bot and applications.commands, then the Send Messages permission. Open the generated URL to invite the bot.
  5. Leave Interactions Endpoint URL empty until the bot is reachable over HTTPS.

Discord requires the interaction endpoint to be public HTTPS with a valid certificate. Localhost only works through a tunnel such as cloudflared or ngrok.


2. Configure

npm install
cp .env.example .env

Edit .env. ALLOWED_USER_IDS is mandatory: it lists the Discord user IDs allowed to deploy.

ALLOWED_USER_IDS=123456789012345678

It is comma-separated. If it is empty, every /deploy is denied — this is intentional, so a misconfigured bot can never publish sites under your provider credentials.

Environment variables

VariableRequiredPurpose
DISCORD_APP_IDYesApplication ID; also used in the follow-up webhook URL.
DISCORD_PUBLIC_KEYYesVerifies every interaction signature.
DISCORD_BOT_TOKENFor npm run registerRegisters slash commands.
DISCORD_GUILD_IDNoRegister commands in one guild (instant) instead of globally.
ALLOWED_USER_IDSYesComma-separated user IDs allowed to deploy.
CLOUDFLARE_API_TOKENFor CloudflareNeeds Cloudflare Pages: Edit.
CLOUDFLARE_ACCOUNT_IDFor CloudflareAccount that owns the Pages projects.
SURGE_TOKENFor SurgeOutput of surge token.
WASMER_TOKENFor WasmerWasmer access token with app/package write access.
WASMER_OWNERNoYour Wasmer username; auto-detected from the token if omitted.
SITE_SOURCE_URLNoLive site mirrored for Surge/Wasmer deploys. Default https://abyss-cc.web.app.
WASMER_DEPLOY_HOURSNoUTC hour(s) that include Wasmer in an hourly run. Default 0 (once a day).
SITE_STATE_PATHNo/deploy-now daily-limit state file. Default ./.build/site-links-state.json.
SITE_HOURLY_STATE_PATHNoPersisted hourly schedule. Default ./.build/site-links-hourly.json.
PORTNoHTTP port. Default 3000; Wasmer Edge injects its own value.
MAX_UPLOAD_BYTESNoAttachment cap. Default 10 MB, hard-capped at 25 MB.

3. Provider credentials

Cloudflare Pages

  1. Copy your Account ID from the Cloudflare dashboard (Workers & Pages overview, right-hand sidebar).
  2. Create a token at https://dash.cloudflare.com/profile/api-tokens → Create Token → Custom token.
  3. Permission: Account → Cloudflare Pages → Edit. Limit it to your account.
  4. Set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID.

The bot creates the Pages project on first use (production_branch: main) and returns https://<project_name>.pages.dev. Uploads use the same Direct Upload flow as wrangler, including Cloudflare's BLAKE3 asset keys — plain SHA-256 hashes would make every asset 404.

Use a Direct Upload project or let the bot create one. A Pages project connected to a Git repository cannot accept direct uploads; Cloudflare rejects those deployments.

Surge.sh

npm install -g surge
surge login
surge token

Set SURGE_TOKEN. Sites are published to https://<project_name>.surge.sh using Surge's gzipped-tar deploy API. Surge subdomains are first-come, first-served: if someone else owns the name you will get a 403. Surge also rate-limits deployments per domain and per account.

Wasmer Edge

  1. Create a token at https://wasmer.io/settings/access-tokens.
  2. Set WASMER_TOKEN; WASMER_OWNER is optional (the bot looks up the username from the token).

Each site is packaged with wasmer/static-web-server and deployed as its own Wasmer app, returning the app's *.wasmer.app URL.


4. Register the slash command

npm run register

This sends PUT /applications/{id}/commands (or /guilds/{guild_id}/commands) with:

OptionTypeNotes
providerString, requiredcloudflare, surge, wasmer
fileAttachment, required.html / .htm or .zip, max 10 MB
project_nameString, optionalSanitized to lowercase a-z, 0-9 and hyphens; max 48 chars

/deploy-now takes a required provider picked from an autocomplete list (cloudflare, surge, wasmer): it deploys exactly one saved link and is capped at one deployment per link per UTC day. Run npm run register after changing the option, then wait for (or bypass with DISCORD_GUILD_ID) command propagation.

PUT replaces the application's command set. The bot registers /deploy, /deploy-now, and /deploy-hourly. Global commands can take up to an hour to appear everywhere; set DISCORD_GUILD_ID for instant guild commands while testing.


5. Run locally

npm start

In another terminal, expose port 3000:

cloudflared tunnel --url http://localhost:3000
# or: ngrok http 3000

Put the tunnel's HTTPS URL plus /interactions into Discord Developer Portal → General Information → Interactions Endpoint URL, and save. Discord immediately sends a PING; the bot answers with {"type":1}.

Then run /deploy in your server.


6. Deploy the bot to Wasmer Edge

  1. Edit app.yaml:
    owner: your-wasmer-username
    name: disc-deploy-bot
    
  2. Edit wasmer.toml and replace your-wasmer-username in [package].name.
  3. Install production dependencies (the manifest mounts ./node_modules):
    npm install --omit=dev
    
  4. Log in and deploy:
    wasmer login
    wasmer deploy
    
  5. Copy the printed URL. It is usually https://disc-deploy-bot-<owner>.wasmer.app (Wasmer may use <name>.wasmer.app when available).
  6. In the Wasmer dashboard for the app, open Settings → Environment variables and add every value from .env.example. Never commit .env.
  7. In the Discord Developer Portal, set:
    https://<your-app>.wasmer.app/interactions
    
  8. Save (Discord sends PING), then run /deploy.

The health endpoint is GET https://<your-app>.wasmer.app/healthz.

If the package build rejects the mounted node_modules, delete wasmer.toml and run wasmer deploy again. Wasmer then auto-detects the Node app from package.json (npm start) and installs dependencies on its builder. Keep app.yaml.

Wasmer provider limitation

The Wasmer deployer is pinned to @wasmer/sdk@0.7.1, which exposes Wasmer.createPackage() / Wasmer.deployApp(); newer 0.19 releases replaced that API with a sandbox-only one. That SDK instantiates WebAssembly inside the process. Wasmer Edge's own Node runtime is itself WebAssembly-based and may not support nested instantiation. If provider: wasmer fails on Wasmer Edge, run this bot on a regular Node host — the Cloudflare and Surge deployers work anywhere Node runs. The error message will say so; nothing crashes or silently succeeds.


How a /deploy works

  1. Discord POSTs the interaction; the bot verifies X-Signature-Ed25519 against DISCORD_PUBLIC_KEY and rejects timestamps older than 5 minutes.
  2. The user allowlist is checked. Unauthorized users get an ephemeral refusal.
  3. Provider, attachment type, attachment size, credentials and project_name are validated before deferring.
  4. The bot replies type: 5 with the ephemeral flag, then starts the upload in the background.
  5. The attachment is downloaded (with a second size check), expanded in memory, stripped of a single wrapper folder if present, and required to have a root index.html. A lone .html upload becomes index.html.
  6. The chosen deployer uploads the files via fetch() and returns a URL.
  7. The original response is edited with the live link, or with a clear error message.

Everything is ephemeral by default. To post results publicly, remove flags: EPHEMERAL from deferredResponse() in src/interactions.js.


Owner deployment commands

/deploy-now and /deploy-hourly are restricted to the Discord server owner, not the allowlist. The bot resolves the owner with GET /guilds/{id} using DISCORD_BOT_TOKEN; DMs and non-owners are denied.

  • /deploy-now provider:<link> is mandatory to pick what to publish: cloudflare, surge, or wasmer. Each link accepts one deployment per UTC day; the counter lives in SITE_STATE_PATH (default ./.build/site-links-state.json) and resets at 00:00 UTC. A deployment that fails hands its slot back.
    • Cloudflare reuses the saved asset manifest, so already-uploaded assets are not sent again. The compiled Functions bundle is attached as _worker.bundle, so /api/* routes keep working.
    • Surge and Wasmer mirror SITE_SOURCE_URL, then upload the mirrored files.
  • /deploy-hourly action:start enables the hourly run, action:stop disables it, and action:status shows the next run and which links it will publish. Enabling it deploys Cloudflare Pages + Surge immediately. After that, each run starts a couple of minutes before the top of the hour — the head start is sized from the previous run's duration, so the published site is live on the hour rather than a few minutes late. Wasmer joins only at the UTC hour(s) in WASMER_DEPLOY_HOURS (default 0, so once a day), judged by the hour a run is aimed at, so a 23:58 start still publishes the 00:00 Wasmer release. Cloudflare Pages and Surge are published in parallel, so a run takes about as long as the slower link.

These commands do not rebuild the GitHub repository. Cloudflare publishes the build that produced the manifest; Surge and Wasmer publish the live source. After changing the site, rebuild it and refresh the manifest:

npm run site:manifest -- /path/to/the/built/dist
# Rebuild the Pages Functions bundle when functions/ changes:
(cd /path/to/the/repo && npx wrangler pages functions build --outfile /path/to/disc-bot/data/abyss-cc-functions.bundle)

/deploy-hourly is a convenience scheduler inside the bot. Its enabled flag and due time are persisted in SITE_HOURLY_STATE_PATH, so a restart no longer silently disables it, and a slot that came due while the process was down runs as a catch-up — at startup, and on the next incoming interaction for hosts that sleep between requests. Set DEPLOY_HOURLY_ON_START=true to force it on at every boot. The relevant settings are SITE_PROJECT_NAME, SITE_URL, SITE_BRANCH, SITE_MANIFEST_PATH, SITE_WORKER_BUNDLE_PATH, SITE_SOURCE_URL, SITE_SEED_PATHS_PATH, SITE_STATE_PATH, SITE_HOURLY_STATE_PATH, WASMER_DEPLOY_HOURS, and DEPLOY_HOURLY_ON_START in .env.example.

For a durable hourly deployment that does not depend on the bot process, use the GitHub Actions workflow described below.


Hourly all-provider deployment

.github/workflows/abyss-hourly.yml runs at minute 55 of every UTC hour, so the mirror-and-publish finishes as the hour turns over rather than minutes into it. Each run:

  1. Mirrors https://abyss-cc.web.app into a temporary build directory, following HTML, CSS, JS, JSON and asset references.
  2. Deploys the complete snapshot to Cloudflare Pages and Surge every hour.
  3. Deploys Wasmer Edge only at 00:00 UTC by default (WASMER_DEPLOY_HOURS=0), so Wasmer receives one release a day while Cloudflare and Surge update hourly. A 23:55 run counts as the 00:00 slot, so the daily release is live on the hour.
  4. Refreshes data/abyss-cc-manifest.json and data/abyss-cc-seed-paths.json; the workflow commits them only when their content actually changes.

The current links are:

  • Cloudflare: https://abyss-cc-4v6.pages.dev
  • Surge: https://abyss-cc.surge.sh
  • Wasmer: https://abyss-cc.wasmer.app

The workflow also supports workflow_dispatch (manually run it, optionally with force_wasmer) and a repository_dispatch event named abyss-source-updated.

Required repository secrets

Add these under Settings → Secrets and variables → Actions in the repository that hosts this workflow:

SecretPurpose
CLOUDFLARE_API_TOKENPages: Edit permission
CLOUDFLARE_ACCOUNT_IDCloudflare account ID
SURGE_TOKENSurge access token for abyss-cc.surge.sh
WASMER_TOKENWasmer access token
WASMER_OWNERakilesh_him

Trigger an immediate source deploy

GitHub only runs the hourly schedule once the workflow is pushed and enabled. Add this workflow to the source repository if you want a push to notify the deploy repository immediately instead of waiting for the next top-of-hour run:

name: Notify Abyss deploy
on:
  push:
    branches: [main]
jobs:
  notify:
    runs-on: ubuntu-latest
    steps:
      - uses: peter-evans/repository-dispatch@v3
        with:
          token: ${{ secrets.ABYSS_DISPATCH_TOKEN }}
          repository: akilesh-him/disc-bot
          event-type: abyss-source-updated

The token needs permission to dispatch events to the deploy repository. The source workflow should run after the source has published abyss-cc.web.app; the deploy action mirrors that live site, not a private GitHub checkout.


Security model

  • Deny by default. No allowlist entries means no deployments. A listed user ID must match.
  • Signature verification on every request, with a freshness window to limit replay.
  • Attachment limits. Discord's declared size is checked before download, and the real byte count is checked after. Uncompressed ZIP content is capped at 40 MB and 1,000 files.
  • Archive hardening. Absolute paths, .. segments, symlinks and macOS metadata are skipped; files are never written to disk. Path lengths are bounded.
  • Slug sanitization. project_name is lowercased, reduced to [a-z0-9-], collapsed, trimmed and capped at 48 characters, satisfying all three providers.
  • No secret logging. Provider tokens live in headers only; errors are truncated and never include credentials.
  • Daily link limit. /deploy-now allows one manual deployment per link per UTC day; the counter is file-backed so a restart does not reset it.
  • Deployed sites are public. Anyone on the allowlist can publish content under your provider account. Treat the allowlist as a publishing permission.

Project layout

src/
  index.js                 HTTP server: POST /interactions, GET /healthz
  interactions.js          Signature check, allowlist, deferred response, follow-up
  config.js                Environment loading and validation
  register-commands.js     Slash-command registration (npm run register)
  site-deploy.js           Cloudflare deployment from the saved asset manifest
  site-links.js            Link orchestration, daily-eligible hourly plan, scheduler
  refresh-site-manifest.js Regenerates data/abyss-cc-manifest.json
  lib/
    owner.js               Cached guild-owner authorization
    daily-quota.js         File-backed per-link daily deployment limit
    site-mirror.js         In-memory source crawl used by Surge/Wasmer deploys
    archive.js             In-memory ZIP/HTML extraction and safety limits
    discord.js             Attachment download and @original message edit
    errors.js              User-safe DeployError
    hash.js                Cloudflare BLAKE3 asset keys + MIME types
    http.js                Fetch timeouts and provider error parsing
    slug.js                project_name sanitization
    tar.js                 Minimal in-memory ustar + gzip writer for Surge
  deployers/
    cloudflare.js          Pages Direct Upload (manifest + BLAKE3 assets)
    surge.js               surge.surge.sh gzipped-tar deploys
    wasmer.js              @wasmer/sdk createPackage + publishPackage + deployApp
scripts/
  sync-abyss.mjs           Mirror abyss-cc.web.app and deploy all three providers
.github/workflows/
  abyss-hourly.yml         Scheduled top-of-hour deployment + source dispatch
wasmer.toml                Wasmer package manifest (edgejs-quickjs)
app.yaml                   Wasmer Edge app configuration
data/abyss-cc-manifest.json  Saved Cloudflare Pages asset manifest
data/abyss-cc-seed-paths.json  Known source paths used to seed each mirror run
data/abyss-cc-functions.bundle  Optional compiled Pages Functions bundle for /deploy-now
.env.example               All configuration variables

Provider limits worth knowing

ProviderReturned URLNotes
Cloudflare Pageshttps://<slug>.pages.devProject auto-created; asset keys use BLAKE3(base64 + extension).
Surgehttps://<slug>.surge.shGlobal subdomain namespace; 30 deploys/15 min per domain, 60 per account.
Wasmer Edgehttps://<app>.wasmer.appOne Wasmer app per site; requires the Wasmer SDK (see limitation above).

Deployment messages can take from a few seconds to about a minute. Discord's interaction token is valid for 15 minutes; failures after that cannot be reported back to the message, but they are logged.


Troubleshooting

SymptomFix
401 invalid_request_signatureDISCORD_PUBLIC_KEY is wrong, or a proxy changed the raw body. Send the exact bytes to verifyKey.
Discord says "application did not respond"The endpoint must answer within 3 seconds. Check the URL, TLS certificate and that the process received the request.
/deploy is missingRun npm run register, re-invite with the applications.commands scope, and wait for global propagation (or use DISCORD_GUILD_ID).
Cloudflare 403 / error 8000010Token lacks Cloudflare Pages: Edit, or CLOUDFLARE_ACCOUNT_ID is wrong.
Cloudflare deploy succeeds but assets 404The BLAKE3 dependency (@noble/hashes) must be installed; do not replace the asset hash with SHA-256.
Surge 403The *.surge.sh subdomain belongs to another account, or the token is invalid.
Wasmer "Could not determine the Wasmer account"Set WASMER_OWNER to your Wasmer username.
Wasmer provider fails on Wasmer EdgeNested WebAssembly is unavailable there; run the bot on a standard Node host.
project_name rejected by DiscordUse 1–48 characters; it is sanitized to a-z0-9- before reaching any provider.

Discord slash-command bot that deploys static sites to Cloudflare Pages, Surge, and Wasmer Edge