This project is now a webhook-driven Telegram bot for Cloudflare Workers.
The original bot had one core job:
- Accept rough outbound-email notes in Telegram.
- Extract
TO:if present, and otherwise let OpenAI infer a recipient email when the text includes one. - Ask OpenAI to reshape the notes into a structured JSON object that fits the Stackfuse email template.
- Render that JSON into a fixed dark HTML template.
- Build a multipart
.emldraft with both plain-text and HTML parts. - Send that
.emlback to the Telegram user asstackfuse-email.eml.
The Cloudflare rewrite preserves that flow, but changes the runtime model:
- No polling process.
- No Python runtime.
- No local lock files.
- Telegram now delivers updates to a Worker webhook.
- The Worker returns
200immediately and finishes the email generation in background work.
- src/worker.mjs: Cloudflare Worker entrypoint and all runtime logic.
- wrangler.jsonc: Worker configuration.
- tests/worker.test.mjs: smoke tests for parsing, templating, and
.emlgeneration.
GET /: status payload describing the service.GET /health: lightweight health check.POST /webhook/telegram: Telegram webhook endpoint protected byX-Telegram-Bot-Api-Secret-Token.
Supported Telegram interactions:
/start: explains how to use the bot.- Plain text message: generates and returns an
.emldraft.
Not carried over:
- The old optional
Send nowflow. The previous implementation relied on SMTP or Gmail OAuth from a long-running Python process. That is not portable to Cloudflare Workers without a different mail-delivery integration.
Configure these in Cloudflare as Worker secrets:
OPENAI_API_KEYTELEGRAM_BOT_TOKENTELEGRAM_WEBHOOK_SECRET
Optional plain-text vars:
OPENAI_MODELDEFAULT_FROM
For local development, copy .dev.vars.example to .dev.vars.
node --testThe Worker is intended to run on workers.dev and receive Telegram webhooks directly. After deployment, Telegram should point to:
https://<worker-name>.<workers-subdomain>.workers.dev/webhook/telegram
with the configured secret token.