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 Chatbots

In 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:

  1. You can save time and money on customer service
  2. It can boost your sales
  3. With a chatbot, you can reply in seconds, instead of days
  4. Your chatbot is 24/7 available, all over the world
  5. 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:

  1. A user starts a conversation with a Telegram chatbot of an eCommerce company. The user asks “What are your top products?”
  2. The chatbot understand this message and recognizes the words “top products”
  3. Based on those words, it searches the product database for their best selling products
  4. 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 Telegram

Now 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:

  1. Set the Control expression to “hey|hi|hello”
  2. Set the Target Variable to “last_user_message”
  3. Check the “Can Bypass Input State”
  4. Set the Behavior to “Your Main Bot Behavior”
  5. 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:

  1. When are you open?
  2. What are your opening times?
  3. 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:

  1. Intent to “Opening times”
  2. Check the “Can Bypass Input State”
  3. Set the behavior to “Opening times”
  4. 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:

NOTEDon’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