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.
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
- Open the App Store or Play Store.
- Search
Telegram, install it, and sign up. - Enter your phone number, verification code, and name.
- Done. It is just a normal messenger.
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.
- In Telegram, tap search.
- Search
@BotFatherand choose the account with the blue verification mark. - Send
/newbot. - Enter a bot display name such as
My Home AI Helper. - Enter a username such as
MyHomeAI123Bot. It must be unique and must end withbot. - When it succeeds, Telegram sends a token:
1234567890:ABCdefGHIjklMNOpqrsTUVwxyzThis 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.
- Search
@userinfobotin Telegram. - Send
/start. - Copy the number after
Id:.
That number goes into YOUR_CHAT_ID in server.py.
4. Test the Bot
- Search your new bot by the username you made.
- Send
/start. - If it responds, the bot is ready.
Terms
| Term | Meaning |
|---|---|
| BotFather | Telegram’s official bot for creating bots. |
| Bot token | Your bot’s password. Never publish it. |
| Chat ID | Your Telegram account or chat number. The bot sends messages to this number. |
When It Does Not Work
| Problem | Fix |
|---|---|
| Cannot find BotFather | Search exactly @BotFather and check the blue verification mark. |
| Username rejected | Someone already uses it. Add numbers or _; it must end with bot. |
Bot does not answer /start | Later, make sure server.py is running. |
| Cannot find Chat ID | Search @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
- Check the bot token.
- Check whether the user started the bot.
- Verify the Chat ID.
- Inspect Telegram API response codes.
- Check for rate limits from too many messages.