In this Tutorial we will learn about how to make a Telegram Bot and send message using Telegram Bot API from beginning.
Later on we will also cover other advance topics such as making downloading bots,auto message sender and other bots so stay tuned for our blog updates.
For sending message through Telegram Bot API we first need to create a Telegram Bot
How to make a Telegram Bot
For making a telegram bot you need to start a conversation with @Botfather which an official Telegram Bot that can make other bots.
- Start a conversation with Bot father by sending a “/start” message.
- Then you will see the startup dialog with all the commands used to control the Botfather.
- Make a new telegram bot using the command “/newbot”.
- After writing the /newbot command bot father will ask you to give your bot a new name send a name to botfather.
- Then after giving a name botfather will ask you to assign a new username for your telegram bot make sure the username you are choosing is completely unique.
If everything is successful and done in a right way you will get a message with you bot token API on it. like this given below.
How to send message through Telegram Bot API
Now lets start to send message through telegram bot API
Telegram bot can’t find all the users who all have subscribed to your bot. So people generally saved the userid of the person who visits our bot and starts it. These userid’s are then collected and can be used to broadcast message make others useful telegram bots.
There are many ways to get the user id like using some other telegram bot that can do it by forwarding any message like userinfobot(To get your own userid), get_id_bot(To get user id of any person by forwaring any message),GetChannelIdPlus_bot(To get channel Id by forwarding a message from any channel).
There are also few 3rd party apps which give access to all this but we will use the original and most easy way that is login via Telegram web.
Now lets get started and send our first message through Telegram Bot API follow the following step :-
- Add your bot to the group you want to send message. Here i will make my own group for testing i added the bot which i created to that group.
- Now after adding the bot we need to send the group chat id you can use the above mention bot for that or the chat id is mentioned directly on the telegram web url when you open the group. Make sure to add “-” in front of your chatid if you are sending message to a group and if you are sending it to a user write the chat id directly without “-“.
- After getting the Chatid the last work is to send a message using API for that you need to send a API request which you can simply perform by pasting the request in the web browsers URL.