A highly optimized, serverless Telegram bot built on Cloudflare Workers. It utilizes Cloudflare's Browser Rendering API (Puppeteer) to perform deep technical SEO audits and Workers AI (Llama 3.1) to generate actionable optimization insights.
Built with TypeScript, Hono, and native Cloudflare Workers APIs.
- Deep DOM Evaluation: Uses headless Chrome via
@cloudflare/puppeteerto execute JavaScript, measure performance (TTFB, DOM Ready, Total Load), and extract real structural data. - AI-Powered Insights: Automatically analyzes extracted metrics with
@cf/meta/llama-3.1-8b-instructto provide 3 prioritized, human-readable recommendations. - Edge Caching: Caches expensive audit results in Cloudflare KV for 1 hour to ensure lightning-fast subsequent requests and save compute resources.
- Spam Protection: Implements Cloudflare Rate Limiting to strictly limit users (e.g., 3 requests per minute per Chat ID).
- Asynchronous Execution: Uses
ctx.waitUntil()to process background scraping tasks without keeping the Telegram webhook connection hanging. - Rich Telegram Formatting: Outputs robust HTML-formatted Telegram messages that beautifully organize Data, Security Headers, Links, and Media.
- Cloudflare Workers - Serverless execution environment
- Hono - Lightweight web framework for Edge
- Cloudflare Browser Rendering - Puppeteer integration
- Cloudflare Workers AI - Llama 3.1 for insights
- Cloudflare KV - Low-latency edge caching
- TypeScript - Targeting ES2024 / Workers runtime
- A Cloudflare Account.
- Node.js installed.
- A Telegram Bot Token from @BotFather.
Clone the repository and install dependencies:
npm installCreate the necessary KV Namespace and update your wrangler.jsonc file with your specific IDs.
# Create a KV Namespace for caching
npx wrangler kv:namespace create KVUpdate the kv_namespaces id in wrangler.jsonc with the returned ID.
Securely add your Telegram bot token as an encrypted secret to your Worker environment:
npx wrangler secret put TELEGRAM_BOT_TOKEN(Paste your BotFather token when prompted)
Deploy the worker:
npm run deployRegister your deployed Cloudflare Worker URL with Telegram so it can receive messages. Run this in your browser or terminal (replace YOUR_BOT_TOKEN and YOUR_WORKER_URL):
curl "https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook?url=https://YOUR_WORKER_URL/webhook"- Open your bot in Telegram.
- Send
/startto see the welcome message. - Send any valid URL (e.g.,
example.comorhttps://cloudflare.com). - Wait 10-25 seconds. The bot will launch a headless browser, evaluate the target page, run the AI model, and return a comprehensive report.
- Rate Limiting: Modify the
ratelimitsarray to adjust spam protection (currently set to 3 requests per 60 seconds). - Browser Binding: Ensure
browser: { binding: "BROWSER" }remains active to utilize Cloudflare's hosted Chrome instances. - AI: Requires the
ai: { binding: "AI" }configuration.
Due to the use of Edge native features like Browser Rendering and AI, it is recommended to use wrangler dev --remote or test against your deployed staging worker.
npm run devTo run Vitest unit tests:
npm run test