Setup Telegram bot app
Register a bot
Chat with Telegram BotFather on Telegram app
Type this in your chat
/newbot
Then follow instruction from BotFather. When finished you will get bot_token which look like: [number]:[text]
Please keep it securely, if someone stole it, they can work like you.
Now, there are 2 common ways to work with your Bot.
- Register your webhook to receive chats from your users
Paste this url on your browser to register your webhook
https://api.telegram.org/bot{your_bot_token_above}/setWebhook?url=your_web_site_url
If Telegram responses with success, just go to your web and start code for your need. You can send message to user with a lot of useful formats.
2. Create group chat and send messages to group
Go to Telegram app, create new group chat and add your Bot (above) to the chat group.
Uhm, say ‘hi’ to your group.
Paste this url on your browser to receive group info
https://api.telegram.org/bot{your_bot_token_above}/getUpdates
You will have something as below
Find chat_id start with ‘-’, this is very important because you will send message to this chat_id.
Ok, let’s send message to group now.
From Terminal (MacOS, Linux)
curl -XPOST https://api.telegram.org/bot{your_bot_token_above}/sendMessage?chat_id={chat_id_above}&text=demo%20bot
Alternatively, you can use Postman to send message.
There are many message formats, follow Telegram document for more info.