Telegram notifications, why use them and how to create your bot step by step
Why Telegram works so well as an alert channel for a team, which systems it connects to, and a tutorial to create a bot and send your first message in ten minutes.
By Javier Tenjo, Full stack developer
On this page
A new order in the shop, a contact form, a declined payment, a website that stopped responding. All of that is information someone on the team needs to see soon, and it nearly always ends up in the same place: an inbox where it competes with newsletters, invoices and auto-replies.
Telegram solves that with very little effort. A bot of your own can message you or the team group every time something important happens, and setting it up takes about ten minutes. This article covers why it is worth doing, what you can connect it to and how to build it step by step.
Why get notifications on Telegram?
The underlying idea is simple: an alert is useful if it is seen in time. Email is a good archive but a poor doorbell. A notification on your phone, in a chat used for nothing else, gets read in seconds.
Some alerts that usually justify the channel:
- Sales and enquiries. A new order, a submitted form, a confirmed booking. Replying in minutes instead of hours changes the outcome.
- Technical problems. The site is down, a certificate is about to expire, a backup failed, the server keeps logging the same error.
- Day-to-day operations. Low stock, a declined payment, a scheduled job that finished (or did not).
- Summaries. The day’s sales at six in the evening, or the weekly report every Monday.
What are the advantages over other channels?
It is free. Telegram’s bot platform charges neither users nor developers. SMS costs per message, and the WhatsApp Business API requires a verified account and approved templates, and charges for messages the business initiates.
There is no paperwork. No business verification and no approval queue. You create the bot from the app itself and it is ready straight away.
It is simple under the hood. Sending a message is a single web request to one address. Any system that can call a URL can send a Telegram alert, with nothing to install.
It works for groups. The bot can post in a group with the whole team, and groups with topics let you separate alerts: sales in one thread, errors in another.
It reaches every device. Phone, desktop and web get the same message, with history and search.
Messages can be rich. Bold text, links, buttons, images and files of up to 50 MB. There are also silent messages, which arrive without sound: handy for things worth recording that should not interrupt anyone.
What to know beforehand
Telegram is not the answer to everything, and it helps to be clear about that from the start:
- The recipient needs Telegram, and has to make the first move. A bot cannot start a conversation: the person must message it first or add it to a group. That makes it a better fit for internal team alerts than for writing to customers, many of whom prefer other apps.
- It is not a channel for sensitive data. Chats with bots are stored on Telegram’s servers and are not end-to-end encrypted. “New order #1042” is fine; passwords, card numbers or medical records are not.
- There are sending limits. They exist to prevent abuse, and a normal alerting setup does not come close to them. We list them further down.
Which systems can it connect to?
Nearly any, in one of two ways.
Tools with Telegram built in. They only ask for the bot token and the chat identifier:
- No-code automation: n8n, Make and Zapier each have a Telegram module. Use them to link the alert to a shop, a CRM, a spreadsheet or a form.
- Monitoring: Uptime Kuma, Grafana, Prometheus (through Alertmanager) and Zabbix can send their alerts to a chat.
- Home and office: Home Assistant can tell you when a door opens or a sensor trips.
Everything else, with a web request. If the system can run a script or call a webhook, it can write to Telegram:
- Your website’s contact form, from the server that processes it.
- A WooCommerce or Shopify shop, through its order webhooks.
- Google Sheets with Apps Script, for example when someone fills in a new row.
- GitHub Actions or any other deployment system, to know whether a release went out.
- A scheduled job on the server: the nightly backup or the daily sales summary. If the scheduling syntax is unfamiliar, we cover it in cron expressions explained.
How to create a Telegram bot step by step
All you need is a Telegram account. The first three steps can be done from your phone and require no programming.
1. Talk to @BotFather
BotFather is Telegram’s official bot for creating and managing bots. Search for its username, @BotFather, in the app and check that it has the blue verification mark. Open the chat and send:
/newbot
It will ask for two things:
- A name. This is what shows in the chat and in contacts, for example “My Shop Alerts”. You can change it later.
- A username. This is the bot’s unique address. It must be 5 to 32 characters long, may only use Latin letters, numbers and underscores, and has to end in
bot: for examplemyshop_alerts_bot. This one cannot be changed later.
BotFather also offers a mini app with the same features in a more visual interface. The result is the same either way.
2. Store the token
When you finish, BotFather gives you the bot’s token, a string that looks like this:
110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw
The token is the bot’s password: anyone who has it can send messages as the bot. Three basic precautions:
- Keep it in a password manager or in the server’s environment variables.
- Do not put it in the code of a web page or commit it to a repository.
- If it leaks or you lose it, ask BotFather for a new one with
/token. The old one stops working.
3. Message your bot
Open the chat with your bot (BotFather gives you the link, in the form t.me/myshop_alerts_bot) and press Start. This step is mandatory: as mentioned above, a bot can only write to someone who has written to it first.
4. Find the chat identifier
To send a message, Telegram needs to know which chat it goes to. That value is the chat_id, and the most direct way to get it is to ask the API which messages the bot has received. Open this address in your browser, with your token in place of <TOKEN>:
https://api.telegram.org/bot<TOKEN>/getUpdates
Note that the word bot sits right against the token. The response is JSON text; look for the chat block:
{
"ok": true,
"result": [
{
"update_id": 123456789,
"message": {
"chat": { "id": 987654321, "first_name": "Ana", "type": "private" },
"text": "/start"
}
}
]
}
That id is your chat_id. If result comes back empty, send the bot another message and reload the page: Telegram keeps these updates for 24 hours at most.
5. Send your first message
With the token and the chat_id you are ready to send. From a terminal:
curl -s "https://api.telegram.org/bot<TOKEN>/sendMessage" \
-d chat_id=987654321 \
--data-urlencode "text=Hello, I am working. New order #1042"
If all went well, the message arrives on your phone and the API replies with "ok": true. That is all it takes: one request to sendMessage with two values, the chat and the text.
The same call from JavaScript, as it would look on the server that processes a form:
async function notify(text) {
const response = await fetch(
`https://api.telegram.org/bot${process.env.TELEGRAM_TOKEN}/sendMessage`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
chat_id: process.env.TELEGRAM_CHAT_ID,
text,
parse_mode: 'HTML',
}),
},
);
return response.json();
}
await notify('<b>New order</b> #1042 for $120');
A few optional parameters worth knowing:
| Parameter | What it does |
|---|---|
parse_mode |
Formats the text. With HTML you can use <b>, <i>, <a> and <code>; with MarkdownV2, Markdown syntax. |
disable_notification |
With true, the message arrives without sound. |
message_thread_id |
Sends the message to a specific topic in a group with topics. |
protect_content |
Prevents the message from being forwarded or saved. |
link_preview_options |
Controls the link preview, or turns it off. |
One detail about HTML formatting: if the text contains <, > or & and they are not part of a tag, write them as <, > and &, or Telegram will reject the message.
6. Send alerts to a group or a channel
To get the alerts to the whole team:
- Group. Add the bot as a regular member and send a command in the group that mentions it, for example
/start@myshop_alerts_bot. OpengetUpdatesagain and you will find the group’schat_id, which is a negative number. The mention is needed because bots run in privacy mode by default, and in groups they only see commands and replies addressed to them. You do not need to change that to send alerts. - Channel. Add the bot as an administrator. If the channel is public, you can use its username as the
chat_id, in the form@channelname.
What are the limits and the common errors?
The limits Telegram publishes for bots:
- Around one message per second in a single chat.
- 20 messages per minute in a single group.
- About 30 messages per second overall when sending to many different chats.
- Each text message holds up to 4096 characters.
If a system goes over them, the API responds with a 429 error and says how many seconds to wait before retrying. For an alert channel, the practical takeaway is to batch: one summary with twenty lines beats twenty messages in a row.
The errors that come up most often when starting out:
| Error | Usual cause |
|---|---|
401 Unauthorized |
The token was copied wrong or has been replaced by a new one. |
400 Bad Request: chat not found |
The chat_id is wrong, or that person has not messaged the bot yet. |
403 Forbidden: bot was blocked by the user |
The person blocked the bot. |
429 Too Many Requests |
The sending limit was exceeded. The response says how long to wait. |
One last note on getUpdates: it stops working if the bot has a webhook configured, which is Telegram’s other mechanism for delivering incoming messages. For a bot that only sends alerts you need neither once you have the chat_id.
Which alerts are worth sending?
An alert channel works for as long as people trust it. If it goes off fifty times a day, the team mutes it and it stops being useful. A few guidelines that help:
- Only alert on what needs action. Everything else goes in a daily summary or in silent messages.
- Separate by urgency. One group or topic for critical alerts, with sound, and another for informational ones.
- Write messages that stand on their own. What happened, where, and a link to act on it: “Payment declined on order #1042” with a link to the order beats “Payment error”.
- Do not rely on a single channel for critical alerts. If the alert is vital, make sure it also lands in email or in the system log.
With the bot running, the next step is deciding which processes to connect to it. If the list of candidates is long, what to automate first offers a method for ranking it.