Sunday, April 26, 2020

Telegram Chat Group and Bot Creation Steps

Hi Friends,

As we know Telegram is getting much popularity and it is being used world wide. Some people are confused about the creation of new chat bot and chat group. Then i thought to write a blog with simple steps. We can have our own telegram bot and chat group which can be used for marketing/advertisement messages, In IT sector we can use it as a monitoring tool to publish the messages/alerts to large audience/participants list. 

We can create our own bot and chat groups by following some simple steps.

For Example we want to create a group and want to add a personal bot in the group that bot will send messages in the group as a dummy user.

First, Let's create a group.

open https://web.telegram.org/# and register with your mobile number.

First Create a group by clicking on the left side menu. As given in below screen shot.


Now Select members which you want to add in the group.




Provide Name of your chat group.



Your Chat Group is ready.

Let's create a bot using which we want to send messages from our 3rd party applications. Telegram provide us REST API to publish messages via bot.


Here we are discussing to create our own group and adding a dummy bot in the group. So group is created successfully in above step. Creating bot in below steps now.

Now Search BotFather from Search bar in telegram and chat with Botfather. Type /start in chat you will get below screen.







To create a new bot, type /newbot in chat. It will ask you to provide a name for your bot.  I am giving telgrambotcreationtutorials .Now it's asking us to pass a username which is ending with “bot”. I am giving tel_user_2020_bot.



When you will follow above step you will get unique access code to access your bot. Its very confidential key. So do not share it with anyone. Now we will be adding this bot in the group which we have created in above step.


Our Chat Group and bot are created successfully. Let's add our bot in the chat group Now.


Now go on the group and click on the add member.

Here you need to add the bot which you created in step 2 as a member of the group.



After adding the member run below API in browser to check the chat id of the bot for this group.

https://api.telegram.org/bot1<<your bot id>>/getUpdates

https://api.telegram.org/bot1142780056:AAHjsyi3S4Dt_wgUNgoYV5OUDJt-gkdMjuk/getUpdates

In browser you will get below outcome if your bot is created fine.

{
  • oktrue,
  • result: [ ]
}

If you are getting above output in your browser it means your bot has been created successfully. 

To send messages in this group from your third party application you need chat id of your bot else you will not be able to send messages in this group. "To get chat id, remove the bot from the group and add it again."

After removing and adding..again run the rest api in browser. Now you will see different output in json format. Copy the chat id from browser it will be like (-41253654).

https://api.telegram.org/bot1<<your bot id>>/getUpdates


Sending Messages in the group via third party application. 

Now you have your botID and chatId to send message from any third application in telegram group.

Invoke below rest api format to send message. Replace chatid and bot id in below URL to send message from your bot.

https://api.telegram.org/bot<botID>/sendMessage?chat_id=-478546987&text=Hi new guest enrolled success fully with id UGI87452l

Now you will see message will come in your chat group.


Please write in comments in case you are facing any issue.

Thanks. 

3 comments:

Telegram API to send Contact Number And Share Location via bot

Hi Friends, If you are working on any application and looking for an API to share location of any particular place in Telegram Group via bot...