How do bots work on telegram
Be Careful Using Bots on Telegram
While the Forcepoint researchers used the Telegram API to snoop on the hacker's bot communications as part of well-meaning defense analysis, they emphasize that someone else could use the same technique for ill and look back at a whole conversation a bot is present in. And even someone who doesn't have a chat's bot API token and Chat ID from a malware sample could still potentially extract them in other ways. Both pieces of information are embedded in every Telegram communication, so bots can know which data or service to send to which chat.
The idea that a secure messaging service's own feature could downgrade its encryption scheme—without giving any visual cue to the user—is concerning. "You can create your own burner Telegram account and tell the bot to forward you these messages," Somerville says. "It's relatively trivial to do, and you can forward all the messages in that channel that the bot has had access to. You’ll be able to read all the messages they’ve exchanged. "
Forcepoint has been in touch with Telegram about the findings, but wouldn't comment on its interactions with the company. "That bot traffic goes over HTTPS is not something to be 'discovered'—it's a documented property of the system," Markus Ra, Telegram's head of support, said in a statement. "This is an industry standard. Note that by default, Telegram bots only receive messages that are specifically meant for them." Telegram also argues that grabbing the bot API token and Chat ID is akin to stealing someone's password to an account—at that point an attacker would have full access anyway. The company did not offer an explanation for why bot communications are secured only with HTTPS and not MTProto.
Taking advantage of the lesser protection on Telegram chats and channels that include bots would still require an attacker to be able to decrypt HTTPS Telegram traffic. In Forcepoint's case, the researchers got around it by essentially obtaining the keys to the kingdom in the malware sample they were working on. In general, a relatively sophisticated adversary would have to be targeting you to become a "man in the middle" of your HTTPS communication. But the reason secure communication platforms require more-advanced encryption in the first place is precisely that it can sometimes be possible to skirt HTTPS.
"In a situation where certain chats only use TLS because of bot functionality, a bot would dramatically undercut the security properties of a chat," says Kenn White, director of the Open Crypto Audit Project. "Using a protocol that’s not part of the core protocol for a convenience integration would provide none of the integrity or benefit of that main protocol. That would be an intentional design trade-off that dramatically undermines security guarantees."
To keep your Telegram communications safe, don't add bots to your chats, and be aware when you're in chats and channels that include them. And to keep messages really secret, always minimize the number of people in a chat to reduce exposure. Many cryptographers and security engineers, though, including White, say that the safest way to use Telegram is just not to use it at all. They doubt whether Telegram is fully end-to-end encrypted (a protection that isn't on by default anyway) and worry that the custom MTProto protocol is difficult to fully vet. But for the app's 200 million adherents, the security differences between chats that include bots and chats that don't are important.
"For bot developers there’s not an awful lot they can do about this themselves other than warning people that the potential for this sort of attack exists," Forcepoint's Somerville says. "It’s unfortunate—it’s a design decision."
Updated January 17, 2019, 8:50am ET and 11:50am ET to include comments from Telegram.
More Great WIRED Stories
- One couple’s tireless crusade to stop a genetic killer
- Virtual reality’s latest use? Diagnosing mental illness
- Nike's new self-lacing basketball shoe is actually smart
- As tech invades cycling, are bike activists selling out?
- The rise of the Swiss Army gadget
- 👀 Looking for the latest gadgets? Check out our picks, gift guides, and best deals all year round
- 📩 Get even more of our inside scoops with our weekly Backchannel newsletter
Ultimate Guide (+ How-To Tutorial)
By Joren Wouters • Updated on
This is the ultimate guide to Telegram chatbots in 2022.
I will cover:
- What Telegram Chatbots are
- Why you should use Telegram chatbots
- How you can create your own Telegram bot
And even more.
So if you are a looking to create a Telegram chatbot, you'll love this guide.
Contents
Chapter 1
Intro to Telegram Chatbots
Chapter 2
How to Create a Telegram Chatbot
Chapter 3
Chatbot platforms for Telegram
Chapter 1: Intro to Telegram ChatbotsIn this first chapter, I will provide an intro to Telegram Chatbots. So:
Let's dive in.
What is a Telegram Chatbot?
A Telegram chatbot is an automated conversation partner on Telegram.
It facilitates a conversation between a person and a computer.
Where you would normally talk with another person on Telegram, you are now talking with a computer. And based on the things you say or the questions you ask, the chatbot will automatically give an answer back to you.
Telegram Chatbot Example
Now a real-life example of a Telegram chatbot: the Eddy Travel chatbot.
With this chatbot you can:
- Search for flights
- Get travel inspiration
- Find accomodations, such as hotels
- Explore tours
- And plan group travels
You can try it out yourself by talking to Eddie Travels using this link:
Why use Telegram Chatbots?
Telegram is one of the biggest messaging apps in the world, with 400 million active monthly users:
Also, the platform is growing fast. Every day, 1.5 million new users sign up for Telegram:
This means that a lot of people are already on Telegram and that the number of users is expanding rapidly.
With so many people on the platform, it is likely that your customers will also be there. And where your customers, you need to be.
So now you understand why you should use Telegram, why should you use a chatbot?
Actually, I created an extensive post about this, but here are some of the main reasons:
- You can save time and money on customer service
- It can boost your sales
- With a chatbot, you can reply in seconds, instead of days
- Your chatbot is 24/7 available, all over the world
- People are open to using chatbots, as long as they get good help
Besides this, Telegram also has some advantages over other channels, such as Facebook Messenger and WhatsApp.
Facebook Messenger and WhatsApp have strict rules regarding their chatbot, such as the 24-hour window. But with Telegram, we have no such rules (yet), which is a huge advantage!
Also, with Telegram you can use chatbots in groups, which is not possible with Facebook Messenger and WhatsApp.
How does a Telegram Chatbot work?
A chatbot on Telegram works pretty simple.
When someone sends a message to your Telegram chatbot, the chatbot tries to understand that message and answer it, just like any normal person would do.
Here is an example:
- A user starts a conversation with a Telegram chatbot of an eCommerce company. The user asks “What are your top products?”
- The chatbot understand this message and recognizes the words “top products”
- Based on those words, it searches the product database for their best selling products
- Ultimately, the chatbot will send a message back with the best selling products of their company.
Pretty simple, right?
Chapter 2: How To Create a Chatbot on TelegramNow we know what Telegram chatbots are and why you should use one, it is time to create one ourselves.
So I will show you how you can create your own Telegram bot, step-by-step.
And I am going to do that by using Xenioo.
Let's dive in.
Create your chatbot in Xenioo
Before, we start, I also created a video showing how you can create your own Telegram chatbot:
Let’s start by creating our chatbot. I will show you how you can:
- Setup a greeting message when somebody starts a conversation on Telegram
- Automatically reply to questions on Telegram
- Send the chat to a human when the chatbot does not understand a question
The first thing that you need to do is create your free Xenioo account by clicking the button below:
Create free Xenioo account
Xenioo is the chatbot builder I am going to use for this tutorial.
And with Xenioo you can create one chatbot and put it on more than 10 channels, such as WhatsApp, Facebook, Instagram, but most important: Telegram.
Once you’ve created your Xenioo account and are logged in, you can just click on Create new bot:
And now you see that Xenioo automatically creates a bot with an example flow in it:
Let’s move on with creating the greeting message.
Set up the greeting message
The next step is to setup the greeting message of your chatbot. This is also called the welcome message.
The greeting message is the message that appears when somebody starts a conversation with your chatbot.
What we are going to do, is that we are first going to delete a message from the Start Interaction in Xenioo:
Then, you can just click on the first message and change it to the following:
Hey {{first_name}}! I’m the chatbot of Company XYZ. Do you want to talk to Sales or Support?
And under this message we will show two buttons: One for Sales and one for Support.
So just click on the first button (First Option) and change the button title to “Sales”, remove the Alternate Text and set the Trigger Text Expression also to “Sales”:
And then you can do the same thing for the second button:
Then we will click on the “First Button Clicked” block and change the name to “Sales”:
And we can do the same thing for Support, so that it looks like this:
Inside the “Sales” block, we can change the message to:
Allright, I will connect you to someone at Sales.
And remove the rest of the elements in this block, and add a new action:
Choose for the Set Chat Operator State:
Set the mode to “Operator Take Over”, assign a “Less Busy” operator and select only online operators:
What this will do is that Xenioo will let a human take over the chat and send a notification to a less busy operator that is currently online.
By the way, it is also possible to choose an operator from a certain group (in this case: Sales group). You can assign groups to team members in Xenioo under Settings –> Team. I also show this in the video above 😉
Now, we can basically do the same thing for Support. Just copy the message from Sales and copy the Chat Operator State element to the Message block and change it a bit, so that it looks like this:
So we created our greeting message, but we also need to send this message when somebody starts a conversation with your chatbot.
And to do that, we need to set up a Global Bot Operation in Xenioo.
Just click on the Art icon on the top that says View Global Bot Operations:
Aadd a new bot operation:
And choose for the Text Parse:
Then you need to:
- Set the Control expression to “hey|hi|hello”
- Set the Target Variable to “last_user_message”
- Check the “Can Bypass Input State”
- Set the Behavior to “Your Main Bot Behavior”
- And the interaction to “Start Interaction”
What this will do is that when a user says hey or hi or hello (the “|” means or), it will automatically respond with the flow we just created!
So basically, when a user starts a conversation, the greeting message will be sent.
Automatically reply to questions
The next step is to automatically reply to questions. And we will start by adding a new flow to our chatbot by clicking on the + icon:
By the way, in Xenioo a chatbot flow is called a “behavior”. Just so you know 😉
When you click on the settings on the right side of the builder, we can change the name of the flow:
And we change the name to “Opening times”:
This flow will give an answer to a pretty simple question: What are your opening times?
So, we can just change the text inside the Start Interaction to:
We are open every day from 09:00 to 17:00.
Basically, that’s it. But to let this respond to certain questions we actually need to use the AI feature of Xenioo.
In the top bar, click on AI:
And then we can add a new intent by clicking on Add intent:
Set the name to “Opening times” and set the language to “English”:
And also Enable Automatic Training on the Auto-Train tab:
And this is a great feature. Because now every time your chatbot thinks someone is asking about opening times, it will use that question to improve itself.
By doing this, your chatbot will get smarter and smarter and you don’t have to do anything yourself.
Next, we need to add training phrases so that your chatbot can actually understand questions of the user.
For this intent, we will add three training phrases:
- When are you open?
- What are your opening times?
- Are you open in the weekend?
Then, you need to go “Train & Test” and fill in one of those sentences to check whether the chatbot has been trained correctly:
As you can see, when you type in “What are your opening times”, the chatbot recognizes the Opening Times intent (we just created).
If we go back to our chatbot, we can add a new global bot operation. But instead of going for the Text Parse, we should choose NLP Processing:
And set the:
- Intent to “Opening times”
- Check the “Can Bypass Input State”
- Set the behavior to “Opening times”
- And the interaction to “Start Interaction”
Now if anyone is asking about your opening times, your chatbot will automatically reply to it.
Send the chat to a human
The last thing we are going to do is send the chat to a human when the chatbot doesn’t understand a question.
And in Xenioo, this is called the Fallback Interaction, the message that will appear when the chatbot doesn’t understand question.
So that is the message we need to edit.
If you go to your Main Bot Behavior, we can change the text of the fallback interaction to:
Sorry, I didn’t understand you. Do you want me to forward this to a human?
Then, we can clone the Fallback interaction twice by clicking on the tools icon and choosing Clone:
And change the name of the blocks to “Yes” and “No”, just as we did before:
Now, we need to add a new action to the Fallback interaction and choose the Quick Reply button:
And we will set the Button Title and Trigger Text expression to “yes”, and connect it with the “Yes” interaction:
Then you can clone this button and set it for the “No” option, so the eventual flow looks like this:
If someone clicks on the “Yes” button, then we want the chatbot to say:
Okay, I am sending you to one of my human friends 🙂
And then we can clone the Operator Take Over Chat that we set up before and drag it to this block:
And for the “No” option, we just are going to add the following text:
No worries 🙂
So now when the chatbot doesn’t understand a question, it will ask “Do you want me to forward this to a human?” And then when the user says “Yes”, he is being connected to a live chat agent. And when the user says “No”, the chatbot will say “No worries”.
But when you go to the Opening Times flow, you will see that there is also a Fallback interaction there.
With Xenioo, you can have a seperate fallback interaction per chatbot flow. But this is not something that we want, we want one fallback interaction for the complete chatbot.
So you just need to delete the text from the Fallback Interaction, add a new action and choose the Include Behavior Interaction (Under Flow):
Then, you need to set the behavior to “Your Main Bot Behavior” and the interaction to “Fallback Interaction”:
What this does, is that you are basically telling Xenioo that we want to use the Fallback interaction from the Main Bot Behavior flow (the one we just created).
And now your chatbot will automatically respond when it doesn’t understand a question!
Connect your chatbot to Telegram
Now that we’ve created our chatbot, it’s time to connect it to Telegram.
In Xenioo, you can click on Publish in the top-bar of the flow builder:
Choose for Telegram:
And then you will see that you need to fill in a Telegram API Token, which you need to get from Telegram itself.
Now, we need to go to Telegram and talk with the BotFather (this sounds almost like a joke, but I am serious).
Go to Telegram, search for BotFather, start a chat and click on “Start” at the bottom.
Then, BotFather will automatically respond with a list of commands you can use to create a Telegram bot using the Telegram Bot API:
So, now you need to say “/newbot” to create your chatbot.
The BotFather will ask for the name and the username of the bot and will automatically create a Telegram API Token for us:
NOTE: Don’t share this API token with anyone else besides yourself!
Just copy and paste that API token into Xenioo:
And now you chatbot is connected to Telegram!
If you click on the link given by the BotFather (in my case: https://t. me/Chatimize_Telegram_Bot), you can talk with your chatbot:
And that’s it! That’s how you create your own Telegram chatbot without using a single line of code.
P.S. If you also want to add your Telegram chatbot to a Telegram Group, you need to check out this post.
Chapter 3: Which chatbot builders for Telegram?I showed you how to create your own Telegram chatbot with ActiveChat.
But ActiveChat is not the only chatbot builder out there.
So, which chatbot builders can you use to build your Telegram chatbot?
And how much does a Telegram chatbot cost?
Let's check it out.
How much does a Telegram chatbot cost?
The pricing of your Telegram chatbot depends on the chatbot platform that you use.
So let’s look at the chatbot builders that offer Telegram chatbots. I will look at whether there is a free plan and how much it will cost to send 1000 messages with a chatbot on each of the platforms:
Chatbot builder | Free plan available? | Price per 1000 messages |
---|---|---|
ActiveChat | No | $33 per month |
Botmother | Yes | $17 per month |
Engati | Yes | Free |
Flow XO | Yes | $19 per month |
Flow. ai | No | Custom price |
Snatchbot | Yes | $30 per month |
Trengo | Yes | $28,50 per month |
Ubisend | No | $417,16 per month |
Xenioo | Yes | $36,39 per month |
Of course, these chatbot builders differ a lot in the features they provide and the type of customers they serve, but it provides some insight into how much a Telegram chatbot costs.
Let’s have a look at the various chatbot builders.
Telegram Chatbot Builders
ActiveChat
Pros
- Support multiple channels: Website, Facebook Messenger, Telegram and SMS
- Advanced website widget: widget in your own corporate identity and you can send messages based on the page the user is on
- One of the best eCommerce integrations I have ever seen in a chatbot builder (with Shopify & WooCommerce)
- Built-in live chat
- Dialogflow integration
Cons
- The interface has a little higher learning curve than other chatbot builders
- Minimal analytics
- No Zapier/Integromat integration
- You would expect more channels for the price they ask
Go to ActiveChatRead full ActiveChat review
Botmother
Pros
- Easy-to-use interface
- Many chatbot elements
- Put chatbot on 6 channels
- Built-in live chat
- Accept payments inside your chatbot
Cons
- Hard to set up a chatbot
- Cannot set welcome message
- Cannot determine default reply
- Keyword recognition does not work
- Minimal marketing possibilities
- Minimal analytics
Go to BotmotherRead full Botmother review
Botpress
Pros
- Free open-source platform
- Easy-to-use visual flow builder
- Host your chatbot in-house
- Built-in, advanced AI & NLP
- Put your chatbot on 8 channels
- Built-in live chat
Cons
- Hard to set up a chatbot in the beginning
- No Zapier/Integromat integration
- Limited marketing possibilities
- Minimal analytics
Go to BotpressRead full Botpress review
Crisp
Pros
- Easy-to-use visual flow builder
- Built-in AI
- Can easily translate chatbot to multiple languages
- Put your chatbot on 6 channels
- Built-in live chat + iOS/Android app
- Zapier integration
- Advanced native website widget
Cons
- Takes some time to fully understand interface
- Minimal chatbot elements
- Cannot send broadcasts and sequences
- Limited marketing possibilities
Go to CrispRead full Crisp review
Dialogflow
Pros
- Easy-to-use interface
- One of the best AI & NLP
- Put your chatbot on 14 channels
- Free until 180 requests per minute
Cons
- Not possible to store contact information
- Cannot use conditions in chatbot flows
- Doesn’t have a live chat integration
- Limited marketing possibilities
Go to DialogflowRead full Dialogflow review
Engati
Pros
- Easy-to-use Visual Flow Builder
- Many chatbot elements
- Add custom fields to users and segment them
- Built-in AI & NLP
- Supports 11 different channels to put your chatbot on
- Built-in live chat
- Direct integration with Zapier, Google Calendar & Google Sheets
- Good analytics
Cons
- Limited marketing tools
- Could become expensive if you want all the features
- No eCommerce integrations
Go to EngatiRead full Engati review
Flow XO
Pros
- Easy to build conversations for your chatbot
- Offer many channels: Website, Facebook, SMS, Slack and Telegram.
- Integration with WooCommerce and it is possible to buy something within the chatbot
- Has a built-in live chat
Cons
- Not possible to add tags to users and make user segments
- No integration with Zapier or Integromat
- Minimal analytics
Go to Flow XORead full Flow XO review
Flow.ai
Pros
- Easy-to-use visual flow builder
- A lot of chatbot elements
- Add custom fields/tags and create user segments
- Send broadcasts & sequences
- Easily translate your chatbot to multiple languages
- Built-in AI Engine
- Put your chatbot on 10 channels
- Built-in live chat
- Zapier integration
Cons
- No eCommerce integrations
- Could be a bit expensive for smaller companies
- Not possible to automatically reply to Facebook comments
Go to Flow.aiRead full Flow. ai review
Pandorabots
Pros
- Easy-to-use interface
- Open source chatbot builder
- Built-in AI
- Put chatbot on 8 channels
- Built-in live chat
- Easily copy and share chatbot flows
Cons
- Need to code to build a good chatbot
- Cannot store custom fields
- Livechat only available on web chat and landing page
- Need to manually activate live chat per conversation
- Limited marketing possibilities
- Minimal analytics
Go to PandorabotsRead full Pandorabots review
SnatchBot
Pros
- You can add custom fields to your users
- Possible to send broadcasts
- Use conditions in your chatbot flows
- Built-in AI & NLP
- You can put your chatbot on 10 different channels
- Built-in live chat
- Zapier integration
- You can receive payments within your chatbot
- Low pricing
Cons
- Interface is hard to use and takes some time to understand it
- Cannot send sequences to your users
- Limited marketing possibilities
- Minimal analytics
Go to SnatchBotRead full SnatchBot review
Trengo
Pros
- Easy-to-use interface
- Add custom fields and tags
- Easily translatable to multiple languages
- Dialogflow integration
- Supports 10 different channels
- Built-in live chat
- One of the best native website widgets ever seen
Cons
- Limited marketing possibilities
- Minimal analytics
- No templates
Go to TrengoRead full Trengo review
Ubisend
Pros
- Easy-to-use visual flow builder
- Lots of validation options
- AI integrations with DialogFlow, Wit. ai & IBM
- Supports 5 channels
- Built-in live chat
- Advanced analytics
Cons
- Cannot send a broadcast to part of your audience
- No sequences
- Limited marketing possibilities
- No templates
Go to UbisendRead full Ubisend review
UChat
Pros
- Visual flow builder
- Lots of chatbot elements
- Store user info and condition on that info
- Built-in live chat
- Keyword recognition
- Dialogflow integration
- Put chatbot on 13 channels
- Easily translate to different languages
- Extensive eCommerce feature
Cons
- It can feel a bit overwhelming, because the platform has so many features
- Could be hard to optimize your chatbot, because UChat only provides basic analytics
Go to UChatRead full UChat review
Xenioo
Pros
- Easy-to-use interface
- Many advanced chatbot elements
- You can add custom fields and tags
- Advanced AI & NLP
- Put your chatbot on 14 different channels
- Native website widget
- Built-in live chat
- Decent pricing
Cons
- Can take some time before you understand the interface
- Minimal analytics
Go to XeniooRead full Xenioo review
Now It's Your Turn
So that’s how you can use Telegram chatbots in your marketing.
Now I want to turn it over to you: Are you going to create a Telegram Chatbot?
Or do you already use a Telegram chatbot?
Let me know by leaving a comment below!
Telegram Documentation: Bots
Bots are special Telegram accounts created to automatically process and send messages. Users can interact with bots using messages sent through regular or group chats. Bot logic is controlled by HTTPS requests to our Bot API. nine0009
General information
What can bots do?
Here are some examples of how bots are used:
- Integration with other services. For example, a bot can send comments or control a smart home. Or, for example, send you notifications when an action or event occurs (Examples: GitHub Bot, Image Bot).
- Utilities and tools. The bot can display the weather, translate texts, or alert you to upcoming events at your request (Example: poll bot). nine0004
- Single and multiplayer games. The bot can play checkers or chess with you, hold quizzes, and so on. (Example: Trivia bot).
- Social services. The bot can find you a companion based on your common interests and hobbies. (Example: HotOrBot).
- Anything you want. Bot can be programmed for anything. Unless they can wash the dishes.
How do bots work?
nine0008 As mentioned earlier, robots are special accounts that do not require a phone number when creating. In fact, these accounts play the role of an interface to your service that runs on a remote server.The most interesting thing about robots is that you don't need to learn low-level methods of working with MTProto and encryption to create them - communication with the robot is organized using the usual HTTPS interface with simplified Telegram API methods. We called it Bot API.
NoteWe also recommend that you read the detailed description of the Bot API.
How to create a bot?
There is a... Bot for this. Just email the user @BotFather and follow their instructions. Once you have created a bot and received your authorization key (token), go to the Bot API documentation section to start configuring your bot.
How is a bot different from a regular account?
- Robots do not have "online" and "was online" statuses, instead "bot" is displayed. nine0004
- Bots have limited space on servers - all messages will be deleted after a certain period of time after processing.
- Bots cannot initiate communication with the user themselves. The user must either add the robot to the group or be the first to start a dialogue with it. To do this, you can use links like
t.me/
or search by username. - Robot username must end with "bot" (e.g. @controllerbot). nine0004
- When added to a conference, by default the robot does not receive all messages (see privacy mode).
- Robots never sleep, eat or complain (unless you program them otherwise).
Super powers
Telegram bots have many unique features, such as customized keyboards, additional interfaces for default commands, external linking, and special privacy modes for groups.
Inline mode nine0013
Users can communicate with your bot directly from the message input field - from any chat or group. To do this, you just need to type your bot's username and search query. After receiving a request, the bot can return any results. As soon as the user clicks on one of them, he will immediately go to the chat. In this way, you can request content from the bot in chats, groups, or channels.
Read more about embedded mode on the blog »
Games nine0013
Bots allow users to play HTML5 games in groups or private chats. The Telegram gaming platform will help to compile a table of records and notify users about rating changes.
Games have HTML5 under the hood, so you can create games of any complexity. At the moment, the Telegram team has created several demo games:
- Math Battle
- Lumberjack
- Corsairs
More about games in Telegram »
Keyboards
One of the most unusual Bot API features is custom keyboards . When the server sends a response, it is possible to send a command to display a special keyboard with predefined response options (see ReplyKeyboardMarkup). The Telegram client, upon receiving the message, will display your keyboard to the user. Pressing the key will immediately send the corresponding command to the server. Thus, the interaction of the robot with the user can be greatly simplified. Currently, emoji and text can be used to display on the key. Here are some examples of such keyboards:
For more information, see the description of the sendMessage method.
Teams
Commands are a more flexible way to communicate with a bot. The following syntax is recommended:
/command [optional] [argument]
The command must begin with a forward slash "/" and cannot be longer than 32 characters. Commands can consist of letters of the Latin alphabet, numbers and underscores. A few examples:
/get_messages_stats /set_timer 10min Alarm! /get_timezone London, UK
Messages starting with a slash will always be delivered to the bot (just like when replying to bot messages and @mentions in chat). Telegram apps will be:
- Offer a list of supported commands with their description when the user enters the forward slash character "/" (you need to set the command description to @BotFather for this to work). Clicking on the description will send that command.
- Show button (/) in the text input field in all chats with bots. Clicking this button will display a list of available commands.
- Highlight /commands in messages. When you click on such a highlighted command, it will be immediately sent to the bot.
If there are several bots in the group, you can add the name of the bot after the command to avoid collisions in common commands:
/start@TriviaBot /start@ApocalypseBot
This happens automatically if you select a command from the list of available commands. nine0009
Global commands
To make it easier for users to work with bots, we ask all developers to implement support for a few simple commands. In the Telegram application interface there will be shortcuts (quick links) for these commands.
- /start - Starts a conversation with the user (for example, sends a welcome message). You can also pass additional arguments to this command (see external binding).
- /help - displays a message with help on commands. It can be a short message about your bot and a list of available commands.
- /settings - (if possible) returns a list of possible settings and commands to change them.
When trying to start communication with the robot, the user will see the button START . Links Help and Settings will also be available on the bot profile page.
Privacy mode nine0013
Bots are often added to groups to receive various information - news, notifications, etc. However, when adding a bot, you probably asked yourself: “What if this little asshole forwards all group correspondence somewhere “to the left”?” That is why robots have privacy modes .
A robot with privacy enabled will not receive all messages, but only messages that meet these conditions:
- Messages starting with a forward slash "/" (see section Commands)
- Messages containing @mention bot
- Replies to bot messages
- Service messages (about adding a user, changing a group image, etc. )
This is good in every way: firstly, some people will sleep soundly (in their tinfoil hats) without fear of being bugged. Secondly, the privacy mode saves developers from having to process hundreds of unnecessary messages from group chats.
nine0008 Privacy mode is enabled by default in all bots. It can be turned off - then the bot will start receiving all messages, just like a regular user. All participants in the conference can see the current status of the privacy mode in the list of group members.We recommend disabling privacy mode only when absolutely necessary. In the vast majority of cases, requesting a forced reply to a bot message will be sufficient.
External binding
Bots have an external binding mechanism that allows you to pass additional parameters at startup. For example, to transfer the user's authorization token in order to connect his account with some external service. nine0009
Each robot has a link with which you can start a dialogue with it - https://t. me/
. You can add parameters * start or startgroup to this link with a value up to 64 characters. Example:
https://t.me/triviabot?startgroup=test
Valid characters are A-Z
, a-z
, 0-9
, _
and -
. We recommend using base64url to encode parameters. nine0009
Following the link with the parameter start will start a chat with the bot, while the START button will be displayed in the text input field. When clicking on the link with parameter startgroup , the user will be prompted to add the bot to one of the available groups. As soon as the user confirms his action (presses the START button or selects a group), the bot will receive a message in the following format:
/start PAYLOAD
PAYLOAD
will be parameter value start
or startgroup
which was passed in the reference.
External binding example
Let's say example.com wants to send notifications to a user using a Telegram bot. Below is a description of the sequence of actions to implement sending notifications to a user with ID 123
.
- Create a bot with any name like @ExampleComBot
- Set up a webhook for incoming messages nine0017 Generate a key of sufficient length, e.g.
- Write the value
123
with key$memcache_key
to Memcache for 3600 seconds (one hour) - Send the user a link
https://t.me/ExampleComBot?start=TESTKEY
- Set up the webhook handler to query Memcached for the value of the incoming parameter each time a message arrives that begins with
/start
. If the key exists, write the chat_id passed to the webhook totelegram_chat_id
for user123
. Delete the key from Memcache. - Now if we want to send a message to user
123
, we first checktelegram_chat_id
. If it exists, we use the sendMessage method to send a message to the user.
$memcache_key = 'TESTKEY'
BotFather
BotFather - one bot to rule them all. With it, the settings of existing bots are changed and new ones are created.
Create a bot nine0013
Write the command /newbot
to create a new robot. BotFather will ask you for the name of the new bot and offer to come up with a username.
Name (name) will be displayed in contacts and chats.
Username is a short name in Latin that is used for bot mentions and in profile links in telegram.me. Username must consist of Latin letters, underscores and numbers and be from 5 to 32 characters long. Also, the username must end with "bot", for example: "tetris_bot" or "TetrisBot". nine0009
The key (token) is a character set of the form 110201543:AAHdqTcvCh2vGWJxfSeofSAs0K5PALDsaw
, which is needed to receive and send messages using the Bot API.
Creating a token
If you have lost or lost access to the token, send the command /token
to generate a new one.
Settings
- /setname - Change the name of the robot.
- /setdescription - Edit description of the robot, which is a short text describing the bot. Users will see it at the very beginning, under the heading "What can this robot do?".
- /setabouttext - Change bot info, even shorter text displayed in the bot profile. Also, if someone shares your bot, then this text will be sent along with a link to it.
- / setuserpic - Change the bot's avatar. Pictures are always good.
- / setcommands - Change the list of bot commands. Each command consists of its own command word, beginning with a forward slash ("/") and a short description. Users will see a list of commands when they type the "/" character.
- /setjoingroups - Determines if your bot can be added to groups.
- /setprivacy - Determines if your bot sees all messages in groups. In the off state, all messages will be sent to the robot.
- /deletebot - Delete the bot and its username.
Please be aware that it may take some time for the settings to take effect on the server.
How Telegram bots work
You probably already heard about the Telegram messenger or even use it. But what kind of bots live there, you may not be entirely clear. We will try to cover this issue in a simple and accessible language for inexperienced users. nine0009
Bots in Telegram are software "robots" that interact with real people and perform their functions. For example, they report the weather forecast, the exchange rate, search for information through search engines, or tell jokes.
Conditional classification of bots in Telegram
All bots in this messenger can be conditionally divided into 5 categories:
- Informants.
They are faced with the task of informing their subscribers about any events, activities, new publications, etc.
- Assistants.
Developed to assist with template issues. For example, to prevent a manager from answering the same questions 100 times asked by different people, a bot assistant is created that advises on these topics.
- Chatbots.
Mainly created to simulate live communication. Let's say someone is bored and wants to chat with someone, "kill" time. This person can write “Hi” to the bot, ask how he is doing and stuff like that. The program will respond to him as a live interlocutor. Of course, provided that these questions are provided by the developer. Otherwise, the bot will respond with something like "Sorry, I didn't understand you." nine0009
Business uses such bots to automate interaction with customers on typical issues and reduce the burden on employees. We will talk about this below.
- Play.
The meaning of such bots can be understood from the name. These are "robots" that give users the opportunity to play one or more games.
- Universal.
Combine many different functions. They can inform users, answer their questions, conduct a dialogue, and much more. Such bots are not often seen, since they are not so easy to create and debug. nine0009
How to interact with bots in Telegram
First, you need to find the bot in the messenger itself. This can be done in 2 ways: either follow a ready-made link if you saw it on some site or it was sent to you, or enter the name of the bot into the Telegram search. For example @RubBot.
After that, click on the found result and click on the "Start" button in the chat.
Immediately after that, the bot will start its work and offer you to perform the target action: ask a question, select the desired menu item, write a specific word, etc.
In our case, we must click on one of the three menu items to find out the exchange rate of the dollar, euro or Brent oil.
After clicking on the button, the bot will send the relevant information directly to the chat.
Many bots have a menu, as this is the most convenient option for users. However, there are such "robots", the interaction with which is a little more difficult, since there is no visual menu. To use the bot, you need to enter certain commands. For a complete list, type the slash / in the chat. nine0009
When the list of commands appears, click on any of them with the left mouse button or enter manually via chat and send by pressing Enter. Thus, you will begin to interact with the bot, and it will perform those functions that correspond to the commands.
There are several standard commands that can be used almost everywhere:
-
/start - starts the bot.
-
/settings - opens the bot settings. nine0009
-
/help - activates instructions for using the bot.
It is not uncommon for a bot to not respond to any commands at all. This means that it does not work due to a bug in the code, on the server side, or it was simply abandoned.
Can Telegram bots be used in business
Telegram bots are gradually moving into the big leagues and becoming part of e-commerce. Already now there are services that allow you to create bots that perform the functions of an online store or consultant. nine0009
With the help of such a bot, you can win a large part of the mobile audience. Agree that it is much more convenient and faster to order a product or service through a messenger by clicking on a few buttons in the menu than to surf the site and fill out forms.
For business, bots can be useful not only as alternative points of sale. For example, you have your own online store and a staff of consultants. Every day they have to answer hundreds of questions, 80% of which are the same. The maintenance of all these specialists takes a lot of money. How to optimize costs and automate consulting? Develop a "smart" bot in Telegram, which will be programmed to answer all template questions, and if it suddenly encounters non-standard wording, it will connect a live operator to the chat. nine0009
Thus, you can leave only one consultant, reducing the load and saving with the help of a "robot" created for Telegram.
Where to find ready-made bots for Telegram
There are many directories in which links and brief descriptions of bots for Telegram are published. Let's consider some of them.
- Telegram Store.
A collection of bots sorted into categories.
- Tgram.
Catalog of "robots" by categories and with search function.
- TelegramBots.
Single list of bots.