Cloudflare Worker によるお問い合わせフォームバックエンド。Discord チケット連携 & メール通知。
contact-us is a contact form backend running on Cloudflare Workers.
It accepts form submissions, automatically creates Discord ticket channels, and sends email notifications via Resend.
Two-way communication with users is possible through Discord's /reply command and email replies.
reply+{channelId}@domain to the Discord channel| Component | Details |
|---|---|
| Runtime | Cloudflare Workers |
| KV | Stores ticket info (channel ID ↔ email address mapping) |
| External Services | Discord API, Resend API, Cloudflare Turnstile |
| Variable | Description |
|---|---|
DISCORD_BOT_TOKEN |
Discord Bot token |
DISCORD_GUILD_ID |
Server ID where tickets are created |
DISCORD_CATEGORY_ID |
Category ID for ticket channels |
DISCORD_PUBLIC_KEY |
Discord Interaction verification public key |
RESEND_API_KEY |
Resend API key |
RESEND_FROM_EMAIL |
Sender email address |
TURNSTILE_SECRET_KEY |
Cloudflare Turnstile secret key |
ALLOWED_ORIGIN |
CORS allowed origins (comma-separated for multiple) |
REPLY_TO_DOMAIN |
Domain for reply email addresses (defaults to RESEND_FROM_EMAIL domain if omitted) |
| Method | Path | Description |
|---|---|---|
POST |
/ |
Accept form submission |
GET |
/ |
Health check |
POST |
/discord-interactions |
Discord Interaction Webhook |
[User]
│ Submit form
▼
[Cloudflare Worker] ── Create Discord channel
│ Send confirmation email (Reply-To: reply+{channelId}@domain)
▼
[User replies to email]
│ Delivered to reply+{channelId}@domain
▼
[Cloudflare Email Routing] ── Invokes Worker's email() handler
│ Posts reply content to Discord channel
▼
[Discord staff reviews · replies with /reply]
│ Reply email (Reply-To: reply+{channelId}@domain)
▼
[User] → Can reply again via email (thread continues)
npm install
bot, applications.commandsManage Channels, Send Messages, Embed Linksnpx wrangler kv namespace create TICKET_KV
npx wrangler kv namespace create TICKET_KV --preview
Add the output id and preview_id to your wrangler.toml.
reply@yourdomain → Send to Workernpx wrangler secret put DISCORD_BOT_TOKEN
npx wrangler secret put DISCORD_GUILD_ID
npx wrangler secret put DISCORD_CATEGORY_ID
npx wrangler secret put DISCORD_PUBLIC_KEY
npx wrangler secret put RESEND_API_KEY
npx wrangler secret put RESEND_FROM_EMAIL
npx wrangler secret put TURNSTILE_SECRET_KEY
npx wrangler secret put ALLOWED_ORIGIN
npx wrangler deploy
After deploying, set the Worker URL in Discord Developer Portal under Interactions Endpoint URL as <Worker URL>/discord-interactions.
RESEND_FROM_EMAIL domainnoreply@send.example.com), set REPLY_TO_DOMAIN to the receiving domain