To get a notice on your phone whenever something happens on your site, Telegram is one of the simplest roads: you create a bot, find the number of your chat, and send messages with a single HTTP request. You do not need a server of your own, and it works from a PHP script, a cron job or n8n.
Setting up the bot, step by step
| 1 |
Create the bot. In Telegram, open the chat with @BotFather, send /newbot and choose a name and a username ending in “bot”. At the end you get the token, a long string of characters.
|
|
| 2 |
Talk to your bot. Search for the bot by username and send it any message. Without that it has no permission to write to you. For alerts in a group, add the bot to the group and write there.
|
|
| 3 |
Find the chat number. Open https://api.telegram.org/botTOKEN/getUpdates in a browser, with your token in place of TOKEN. In the reply look for chat and the id in it. For groups the number is negative.
|
|
| 4 |
Send the first message. In a terminal or a cron job: curl -s "https://api.telegram.org/botTOKEN/sendMessage" -d chat_id=NUMBER --data-urlencode "text=New enquiry on the site".
|
|
| 5 |
Put the token somewhere safe. In a file outside public_html, read by the script, with permissions that only your account can read.
|
|
Where to use it
| Situation |
Who sends it |
| A form on the site was filled in |
The form’s PHP, with curl, after validating the fields. |
| The site stopped answering |
A script that checks the site and warns you. See getting an alert when your site goes down. |
| A backup finished or failed |
The end of the backup script, in a cron job. |
| An order was paid |
The shop, through a plugin, or an n8n workflow with the Telegram node. |
For a team, use a group. Create a group, add the bot and use that group’s (negative) number: everyone sees the same alert. You can have one bot per purpose, one for the site and one for backups, so the name tells you at once where the notice comes from.
Whoever has the token controls the bot. Never put it in a repository, in a file inside public_html or in a chat. If you think it has left your hands, ask BotFather for a new one (/revoke) and update the script. See also keeping passwords out of your PHP code.
|
If the getUpdates reply is empty, you never wrote to the bot, or the bot already has a webhook set, which stops getUpdates from returning messages. If the message does not arrive, check the chat number and the token, with no stray spaces.
|
Keep alerts short and with context: what happened, where and when. “New enquiry from Ana, 14:32” will do. If everything raises an alert you stop reading them. Keep alerts for what needs action. For WhatsApp, see which WhatsApp suits your business.
|
|
Want to run your scripts on a plan with cron and PHP? See the hosting plans.
See the plans
|
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 321,75 MT/mo (3-year plan, with coupon) See plans |