howtocodeai.com
Tutorials / Intermediate

Build a Telegram Bot With Claude (Free, No Server)

A bot that lives in your pocket: commands, replies, daily scheduled messages — running free on a Cloudflare Worker. The gentlest possible introduction to 'backend' code.

DifficultyIntermediate
Time2–3 hours
You'll needClaude · Telegram (free) · Cloudflare account (free)
You'll buildYour own Telegram bot: responds to commands, fetches live info on demand, and sends you scheduled daily messages — hosted on a free Worker with zero servers to maintain.

Bots sound like infrastructure; Telegram bots are a webhook and an if-statement. Telegram delivers each message to a URL you control; your code at that URL replies. Cloudflare Workers provide the URL free, including scheduled triggers — meaning a bot that messages YOU every morning, costs nothing, and never needs a server restarted. It's also the friendliest on-ramp to backend concepts you'll find.

Step 1 — Birth the bot (5 minutes, no code)

In Telegram, message @BotFather — Telegram's official bot for making bots. Send /newbot, pick a name and username, and it hands you a token. That token IS your bot's identity: treat it like a password (it goes in a Worker secret later, never in code). Message your new bot once — it can't reply yet, but the conversation now exists.

Step 2 — Decide its one job

Good first bots are personal utilities: /weather for your saturday tee time, /add milk → a shopping list, /expense 14.50 lunch → a running log, a /roll dice for game night, or a quote-keeper. Resist the everything-bot; one job ships today.

Step 3 — Generate the Worker

Write a Cloudflare Worker (JavaScript, free tier) that runs a Telegram bot via webhook. Commands: /start explains the bot; /weather replies with current weather for [lat, lng] from the Open-Meteo API; /note [text] saves a note and /notes lists them (use Workers KV — include the binding setup); unknown messages get a short help reply. The bot token comes from an environment secret named TG_TOKEN. Also include: (1) the exact one-time URL I visit to register the webhook with Telegram, (2) step-by-step beginner deployment in the Cloudflare dashboard including creating the KV namespace and the secret, (3) how to restrict the bot to only respond to my Telegram user ID. Comment the code generously.

Deploy, register the webhook, send /weather, and your phone buzzes with an answer from code you deployed. The feedback loop from here on is: edit Worker → save → message the bot.

Step 4 — The morning message (scheduled triggers)

The killer feature: Workers support cron triggers, so the bot can speak first. Ask Claude to 'add a scheduled handler that runs at 7:00 AM my timezone and sends me a message with today's weather and my saved notes — include the dashboard steps to add the cron trigger and explain how the Worker sends a message without an incoming webhook (the Telegram sendMessage API).' Now it's not a bot you query; it's a briefing that finds you.

Worth knowingLock it down before adding anything sensitive: the user-ID restriction from step 3 means strangers who discover the bot get silence. Anything storing personal data — notes, expenses, locations — should refuse everyone but you, and the check is three lines.

Step 5 — Stack your other skills onto it

Every pattern on this site plugs in: the scraping tutorial → '/price replies with the current price of [thing] from [site]'; the Claude-API tutorial → '/ask [question] forwards to Claude and replies with the answer' (the key sits safely in a Worker secret — this is the proxy pattern you already know); the self-updating-site tutorial → your daily cron pipeline finishes by messaging you 'site rebuilt, 2 price changes detected.' A bot is just a chat-shaped front door to everything else you build.

What you actually learned

Webhooks, environment secrets, key-value storage, scheduled jobs, API auth — that's a real backend curriculum, smuggled in through a chat app, on a free tier, with no server to break. When a future project says 'requires a webhook endpoint,' you'll shrug. That shrug was the point.

Keep going

Need somewhere to put it live? See where to host AI-built sites. Compare tool costs on the pricing tracker (or stick to the free options), then pick your next build.