A French Initiative for Digital Resiliency — Breaking vendor lock-in. Protecting data privacy. Empowering organizations.

Croom Contact Form - Cloudflare Worker

This Cloudflare Worker handles contact form submissions from the Croom website and sends notifications to Telegram.

Features

Setup Instructions

1. Create a Telegram Bot

  1. Open Telegram and search for @BotFather
  2. Send /newbot and follow the instructions
  3. Save the Bot Token (format: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz)
  4. Send a message to your bot to start it

2. Get Your Chat ID

  1. Send a message to your bot
  2. Visit: https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
  3. Look for "chat":{"id":123456789} in the response
  4. Save the Chat ID (it’s a number, can be negative for groups)

Alternatively, you can:

3. Install Wrangler CLI

npm install -g wrangler
# or
pnpm add -g wrangler

4. Login to Cloudflare

wrangler login

5. Deploy the Worker

cd docs/cfworkers
wrangler deploy

6. Set Secrets

Set your Telegram credentials as secrets (never commit these!):

# Set the Bot Token
wrangler secret put TELEGRAM_BOT_TOKEN
# When prompted, paste your bot token

# Set the Chat ID
wrangler secret put TELEGRAM_CHAT_ID
# When prompted, paste your chat ID

7. Configure Custom Domain (Optional)

Option A: Via Cloudflare Dashboard

  1. Go to your Cloudflare Dashboard
  2. Navigate to Workers & Pages → your worker
  3. Go to Settings → Triggers
  4. Add a Custom Domain: contact.croom.to

Option B: Via wrangler.toml

Uncomment and update the routes in wrangler.toml:

routes = [
  { pattern = "contact.croom.to/*", zone_name = "croom.to" }
]

Then redeploy:

wrangler deploy

8. Update Website Configuration

Update the contact form endpoint in docs/contact/index.html:

const WORKER_URL = 'https://contact.croom.to/submit';

Or use the workers.dev URL during development:

const WORKER_URL = 'https://croom-contact-handler.<your-account>.workers.dev/submit';

Testing

Test with curl

curl -X POST https://contact.croom.to/submit \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test User",
    "email": "[email protected]",
    "subject": "Test Subject",
    "message": "This is a test message",
    "timestamp": "2024-01-01T00:00:00Z",
    "userAgent": "Test Agent"
  }'

Expected Response

Success:

{
  "success": true,
  "message": "Message sent successfully"
}

Error:

{
  "success": false,
  "message": "Error description"
}

Telegram Message Format

You’ll receive messages in this format:

🔔 New Contact Form Submission

From: John Doe
Email: [email protected]
Subject: Question about pricing

Message:
Hello, I have a question about your pricing...

───────────────────────
Time: Mon, 01 Jan 2024 12:00:00 GMT
User Agent: Mozilla/5.0...

Security Features

Rate Limiting (Optional)

To add rate limiting, you can use Cloudflare’s Rate Limiting or add custom logic:

// In the worker code
const RATE_LIMIT = 5; // 5 submissions per IP per hour
const RATE_WINDOW = 3600; // 1 hour in seconds

// Use KV or Durable Objects to track submissions per IP

Monitoring

View worker logs:

wrangler tail

Or check the Cloudflare Dashboard:

Updating the Worker

After making changes to contact-handler.js:

wrangler deploy

Environment Variables

The worker uses these secrets (set via wrangler secret put):

Secret Description Example
TELEGRAM_BOT_TOKEN Your Telegram Bot Token 123456789:ABCdef...
TELEGRAM_CHAT_ID Your Telegram Chat ID 123456789

Troubleshooting

“Server configuration error”

“Failed to send notification”

CORS errors

Messages not arriving

Development

To test locally with Wrangler:

wrangler dev

This will start a local server at http://localhost:8787

Cost

Cloudflare Workers Free Tier includes:

This should be more than enough for a contact form!