IOTHUB SOFTWARE · 05

Telegram Bot Alerts for IoT

Telegram is a fast way to send IoT alerts to a phone, but token handling, Chat ID, and alert volume must be designed carefully.

Telegram Sign-up and Bot Setup hero image
Key TermsTelegram botBotFatherbot tokenChat ID

To let the AI helper send “door opened” or “CO2 is high” messages to your phone, you need a Telegram bot. Telegram is a messenger like KakaoTalk, but it makes bot accounts very easy. It is free.


1. Sign Up for Telegram

Why Telegram? KakaoTalk bots are harder for small personal projects. Telegram lets anyone create a bot in about one minute.

2. Create a Bot with BotFather

BotFather is the official bot that creates other bots.

code
1234567890:ABCdefGHIjklMNOpqrsTUVwxyz

This long string is the bot token. Put it into TELEGRAM_BOT_TOKEN in server.py. It is a password. Do not show it to anyone.


3. Find Your Chat ID

The bot needs to know who should receive the messages.

That number goes into YOUR_CHAT_ID in server.py.


4. Test the Bot


Terms

TermMeaning
BotFatherTelegram’s official bot for creating bots.
Bot tokenYour bot’s password. Never publish it.
Chat IDYour Telegram account or chat number. The bot sends messages to this number.

When It Does Not Work

ProblemFix
Cannot find BotFatherSearch exactly @BotFather and check the blue verification mark.
Username rejectedSomeone already uses it. Add numbers or _; it must end with bot.
Bot does not answer /startLater, make sure server.py is running.
Cannot find Chat IDSearch @userinfobot exactly. Avoid fake similar accounts.

Define an alert policy first

Do not send every event to the phone. Separate urgent alerts, daily summaries, and debug-only logs. Too many notifications make real warnings easier to ignore.

Use clear test messages

A useful alert includes device name, time, event, current value, threshold, and the action expected from the user.

Separate alert levels

Do not send every event as a phone notification. Separate urgent alerts, daily summaries, and debug-only logs so important messages stay visible.

Treat the bot token like a password

Store the token in environment variables or private configuration files. Never put it in public HTML, screenshots, or repositories.

When messages do not arrive

  1. Check the bot token.
  2. Check whether the user started the bot.
  3. Verify the Chat ID.
  4. Inspect Telegram API response codes.
  5. Check for rate limits from too many messages.