How to make a Telegram bot

In this post, we’re going to learn how to set up a bot for Telegram. It just takes a few easy steps!

Just like Facebook Messenger, Telegram allows you to run chatbots to automate conversational flows with subscribed users. And unlike other platforms, Telegram can even manage conversations between a group of users. 

How to set up a Telegram bot

Telegram uses an interesting approach to bot API key creation: to create a bot, you need to talk to a bot which is appropriately called “The Botfather”.

In order to chat with BotFather, just add him to your Telegram contacts list and start chatting.

After this initial greeting, you will be presented with a list of commands: the first command that we are looking for is, of course: /newbot.

As soon as you send this command, BotFather will ask you for a full display name (the name that other users will see), and a bot user name (an internal name that will mostly just be of interest to you).

The creation is almost immediate: once BotFather has finished, he will present the link to you so you can use it to share to your new bot account with the API key. Copy this key as you will need it later.

To finish off your bot, you can go ahead and specify the avatar picture you would like. This is also done through chat commands: type /setuserpic, and then follow BotFather’s instructions for uploading your bot avatar image.

All the information you give to BotFather is saved and kept throughout the chat session. If you later wish to change your picture, create a new bot, or change the API key, just go back to  BotFather, as he will know all about your bots.

How to publish your chatbot on Telegram

Now that Telegram has created your new API key, it is time to make your chatbot live.

As you normally do on Facebook, Slack and Web Site, just click on the publish button to open up the channels configurations. But this time of course, you’re going on Telegram.

Now go to the Telegram settings dialogue and paste the API key that you’ve been given by BotFather, and save to confirm.

Click on the publish button, and within a second, your chatbot will be online!

If your new chatbot is not already in your Telegram contacts, all you need to do is to search for it using the Telegram search functionality, and start talking to it to see it running.

Much like Facebook’s first contact, Telegram also uses a Get Started button that will initiate a bot conversation.

Groups, Text and Privacy

 

Once your chatbot is online, you can interact with it in exactly the same way you interact with other people in a communication channels.

What you write is sent to the host you are using, and the text you send can be used to activate complex commands or dialogues.

An interesting feature of Telegram is the ability to create conversation groups in which you can invite multiple users. Within these groups, multiple users (up to 100,000!) can simultaneously discuss and interact with each other.

A group can also have bots within it, and your bot you created can be simply added by searching for it in the Telegram interface.

Once you have added your chatbot to the group, you will notice a particular behaviour: what you write in the group is not interpreted by the chatbot unless it is preceded by a slash (/). This is a default setting implemented by the Telegram bot, and is strategically designed to avoid traffic: generally speaking, a bot within a group is thought to participate as an external helper, and is not set up to intervene on what users may say.

In some cases, however, you may want to ensure that your chatbot activates whenever any person in the group says a particular word or phrase. In this case, the settings of your bot must be changed through BotFather.

To connect to BotFather again, use the /setprivacy command for your bot. Follow the instructions in chat so you can configure your bot to only respond to slash commands, or to receive any conversation.


Post a Comment

0 Comments