TDM

How to Build a Telegram Bot with Claude Code or Codex (Beginner’s Guide)

Never coded a bot before, but want to automate messages on Telegram? Claude Code, Codex, or other AI coding assistants can handle most of the technical work for you, as long as you guide them properly. In just a few steps, you go from an idea to a bot that actually works. Here’s how to do it.

  1. Create your bot on Telegram

Open Telegram and chat with @BotFather, the official bot that creates bots. Type /newbot, pick a name and a username (which must end in “bot”). BotFather gives you a token : a long string of characters that acts as a secret key to control your bot. Keep it safe and never share it publicly — and if it ever leaks (accidentally published on GitHub, for example), go back to BotFather to revoke it and generate a new one.

  1. Open your AI assistant in a project folder

Create an empty folder on your computer, then launch the assistant in a terminal from that location. It always works in the current folder: that’s where it reads and writes your files.

  1. Give it a clear starting prompt

You don’t need technical vocabulary, but the more precise your request, the better the result. Here’s a prompt you can copy and paste as is (replacing the values in brackets):

Build a Telegram bot in Python using the python-telegram-bot library.
The bot should send the weather every morning for [CITY] at [TIME].

Constraints:
- Store the Telegram token in a .env file, never hardcoded.
- Create a .gitignore file that excludes .env.
- Don't invent any secret values (token, API key): clearly tell me
  where and how to enter them myself.
- Explain each step to me before running it.
- Test the bot before considering the project finished.

For a message sent every day without you having to write to the bot, you also need to know your chat ID (the identifier for your conversation with the bot). Just ask the AI to explain how to retrieve it — usually by sending a first message to the bot and then reading the Telegram API’s response.

  1. Secure the token from the start

The AI should create a .env file to store the token.

  1. Let the AI run the commands, carefully

The AI can run the installation commands itself (pip install, npm install, etc.) and start the bot to test it. It will ask for your permission before each important action. That’s normal — it’s a safety feature. When a beginner doesn’t have the reference points to judge “what makes sense,” one simple rule is enough: if a command asks for your password, modifies files you don’t recognize, or installs software you’ve never heard of, first ask the AI to explain what it’s going to do and why, before accepting.

  1. Test your bot

Once the bot is running, open Telegram and send it a message. If it doesn’t respond as expected, just describe the problem to the AI (“the bot doesn’t respond to /start” or ‘I’m getting error XYZ’): it will read the error messages and fix the code.

  1. Add features little by little

Once the basic version works, build it up bot gradually: automatic replies, scheduled reminders, integration with an external API… Ask for one feature at a time, test it, then move on to the next. If your bot needs to remember users, their preferences or reminders, ask the AI to set up persistent storage: a simple local file may be enough for a prototype, but it won’t always survive a restart on a hosting service, so a small database becomes necessary.

  1. Host your bot continuously

For the bot to work even when your computer is off, you need to host it on a server. Ask the AI to explain the current options (a small cloud server, platforms like Railway or Fly.io, serverless functions like Cloudflare Workers) and to prepare the deployment. Always check the terms and prices in effect when you read this: the free tiers on these platforms change regularly.

  1. Troubleshoot and maintain your bot

A bot that works today may stop working tomorrow: a dependency gets updated, the host changes its rules, a token expires… Keep a record of what the AI set up (ask it to document claude.md) so you can easily give it the context again. If something breaks, just copy and paste the error message to the AI: that’s often enough for it to identify and fix the problem.

Replying, scheduling or broadcasting: three different things

A Telegram bot can do three very different things: reply to a message it receives, send a scheduled message at a fixed time, or broadcast a notification to several users. The last case is more demanding: you have to manage the list of people who have started a conversation with the bot, their preferences, and respect the sending limits imposed by Telegram. A bot can’t spontaneously message just any Telegram account; each user must first have started the conversation.

What’s free, what’s paid

Creating a bot with BotFather is free, and the Telegram Bot API is generally not charged per call, but Telegram imposes rate limits, and some features may have their own conditions. On the AI assistant side, usage depends on your plan: a subscription like Claude Pro or Max or ChatGPT Pro includes some usage of the tool.

On the hosting side, several platforms (Cloudflare Workers, Railway, Fly.io…) usually offer a free tier suited to a small personal bot with low traffic. But these offers change regularly and vary depending on your actual usage bot : always check the current terms before committing. In short: it’s entirely possible to run a first Telegram bot without spending a cent.

A few ideas for Telegram bots

Price tracking & shopping

  • Price drop alert: track a product and get notified as soon as it falls below a set threshold.
  • Fuel price comparison: get an alert when a nearby station drops below a certain price per litre.
  • Availability tracking: get notified as soon as an out-of-stock item is back in stock.

Finance & markets

  • Stock / crypto prices: get the price of Bitcoin, a stock or an ETF sent to you, or an alert when there’s a big swing.
  • Portfolio tracking: work out the total value of your investments every day.
  • Exchange rates: get an alert when a currency pair hits an interesting threshold.

Weather & environment

  • Daily weather for your city, sent every morning.
  • Weather alerts for storms, heavy rain or forecast frost.
  • Air quality / pollen.

Productivity & personal life

  • Personal task bot: add, delete and get reminders for tasks straight from Telegram.
  • RSS feed bot: monitors several sites and only sends you new articles.
  • Summary bot: send an article or a piece of text to the bot and get a summary back.
  • Notification bot for your own site: new order, new form submission, server error.
  • Smart home bot: get an alert when a device or sensor changes state.
  • Personal journal bot: quickly jot down notes and find them again by searching.
  • Parcel tracking: bring the status of all your deliveries together in a single bot.

Key takeaways

You don’t need to know how to code to create a working Telegram bot. The AI’s job is to turn your ideas into code, run the technical commands and fix any errors. Your job is to describe clearly what the bot should do, secure your access, ask questions, check whether the AI has any questions and test the result. It’s a real team effort between your vision and the AI’s technical execution.

Comments Off on How to Build a Telegram Bot with Claude Code or Codex (Beginner’s Guide)