Have you ever wanted your scripts, servers, or side projects to send you a quick text message when something happens? Building a Telegram bot sounds like it requires heavy coding, but if you just want a simple notifier, it is surprisingly easy.
Here is how to get your very own Telegram notifier bot up and running in minutes.
Step 1: Meet the BotFather
To create a bot on Telegram, you have to talk to the boss: the BotFather.
- Open Telegram and message @botfather.
- Send the command
/start. - Next, send the command
/newbot. - Follow the prompts by giving it a name, and then a unique username that ends in "bot".
- Copy the token the BotFather gives you.
Step 2: Get Your User ID
Your bot needs to know exactly who to send the message to.
- Search for @userinfobot in Telegram.
- Send it a message to get your account details.
- Copy your user ID from the response.
Step 3: The curl Command
Now you have everything you need to send a message. Prepare this command in your terminal (swap in your token and user ID):
curl -s -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage" \
-d "chat_id=<YOUR_USER_ID>" \
-d "text=Hello from my new bot!"
Step 4: The "Gotcha" Moment
But, if you hit it in this state, it will give you an error message: Bad Request: chat not found.
Telegram bots cannot initiate conversations with users to prevent spam. You have to open the door first.
To fix this, message your bot by its username (e.g., @bot_username) in Telegram and hit Start (or send /start).
Step 5: Success!
Now that you have opened the chat, hit the curl command in your terminal again. Congrats, your bot will successfully send you the message!