We will write a bot like this

Nowadays, anyone without programming skills can write a simple chatbot on their own. For example, to provide services via Telegram, organize a community's work, etc. Let's say, for tracking attendance in a classroom, for communicating in a building's group chat, for downloading movies and music. And for a technical specialist, writing such a bot is a trivial task. Why chatbots are needed, how businesses and individuals can use them, and how to write a bot yourself, whether you have programming skills or not, we will discuss in this article.

Definition and Purpose of Chatbots


In simple terms, a Telegram chatbot is a small application (program) within the messenger, capable of performing various tasks through interaction with the user. There are already quite a few existing bots, and their number continues to grow because any user can create these applications by spending a little time and effort.

Bots can be used for personal purposes; their range of application is wide. They can be used for reminders, ordering train, theater, or movie tickets, etc., for downloading movies and music, searching for information on the internet or other sources, and so on.

Bots are widely used in business. They display product and service catalogs, provide consultations, accept payments and arrange delivery, act as technical support, take requests from users and answer their questions, work as a secretary by reminding about meetings, creating schedule entries, scheduling interviews, etc.: there are many ways to use these applications in this sphere as well.

The principle of how a chatbot works is as follows: after launching, it greets the user and offers to ask a question or choose an action from the available options. The person presses one of the available buttons or writes a message. The application sees the response and reacts to it, fulfilling the request or sending the next message. This dialogue continues until the person's question is resolved or the bot transfers the conversation to a live employee if it decides it cannot handle the task.

If you need a bot for specific tasks, you can order one on specialized platforms. However, by understanding the principle of how a bot works, you can write one for your needs yourself. There are two ways:

  • Chatbot builders. Through them, you can create bots without any special skills. You register on such a platform and either create the application yourself by writing a script (each message and action performed by the bot) or use one of the many templates. Builders are easy to use, suitable for inexperienced users, and usually offer a series of lessons explaining how to use the available tools.
  • Programming. If you have the relevant skills, you can write a bot from scratch. This method is more complex and not suitable for everyone.

Below we will talk more about creating bots using both methods.

Option 1. Writing It Ourselves


If you have programming skills, writing your own bot is not difficult at all. Alternatively, a custom chatbot can be ordered from a freelance programmer for a modest sum.

Usually, chatbots are written in Python, but other languages can also be used: Java, C++, Ruby, etc. If you are not familiar with any of them, you can spend time learning them or do otherwise: create a technical specification and contact a programmer. You can find one on the internet, through social networks, freelance exchanges, specialized companies, or through acquaintances.

Instructions for writing a chatbot in Python:
To create a bot, you need to contact an existing bot in Telegram, BotFather. With it, we select the /newbot command and come up with a name and username (it must end with 'bot') for our bot. BotFather sends the token for our new bot, and we copy it. Here you can also immediately add an avatar, description, and much more using the interactive menu.



Now you need to install the necessary library telebot (pyTelegramBotAPI) on your computer. To do this, open the command line and type pip install pyTelegramBotAPI.

Then, go to any Python coding environment and import this library, and also, to create different objects, you need to include the types module. After that, we create the bot itself.



We add a welcome message after launch and one more command necessary for stable operation, after which the simplest bot is ready.



For example, let's create a simple bot for a beauty salon. Its functionality will include viewing necessary information about it, as well as booking an appointment. To do this, we create a keyboard template and several buttons using the types module and add these buttons to the template. We will also repeat the actions for the "Back" button.

For the user to see this keyboard, you need to add the reply_markup parameter to the line with the bot's message output.




When any of the buttons is pressed, the user automatically sends a message with the corresponding text. For the bot to react to such messages, you need to add a function in which the program simply performs comparisons and, based on them, outputs the required text. As the reply keyboard for all buttons except "Book an appointment", we display the already created "Back" button.



For orders to come to you personally after registration, you need to create a group and add your bot to it. After that, we create a new function forward, which will forward the user's message to your group and output some text. In the chat_id parameter, we insert the link to the group with orders.



After this, we write the register_next_step_handler method so that the bot waits for the user's next message and executes the forward function.



Here is the result we got:




API and Technical Details
When programming a bot, the API (Application Programming Interface) is of great importance, through which programs, web services, and applications exchange data. Telegram bots are controlled by programs that communicate with the messenger's servers to receive data (for example, about a message received by the bot) and send commands (for example, to send a reply to a message). The communication between the programs controlling the bots and the servers is done via an API.

The main API through which data is exchanged is the Telegram API (MTProto API). It is based on the MTProto protocol, created by the Telegram team, and is open so that developers can write their own programs for the messenger. In addition to it, there is the Bot API — this is an additionally developed API on top of the MTProto API, on which only bots operate. It was created so that programmers could write bots using standard HTML requests, without spending time getting acquainted with MTProto.

For bot development, you can use libraries for both the Telegram API and the Bot API. There are more libraries for the Bot API, but there are also more limitations: for example, it does not allow downloading large files or loading old messages from the chat history.

You can study the technical data of the MTProto protocol in the Telegram documentation.

What a Technical Specification for Bot Creation Should Include When Ordering from a Programmer


When contacting a programmer to write a bot, you need to prepare a technical specification. The more detailed and precise it is, the better the chatbot will perform its tasks and meet your expectations. Here is what should be specified in the technical specification:

  • Purpose of the bot. Why the application is being developed, what exactly you expect from it, what tasks it should perform.
  • Target audience with which the chatbot will interact. Here you specify who the chatbot will be talking to, what communication style is acceptable, how it should address people (formally or informally), whether it can make jokes, send entertaining content, etc. The more detailed this section is, the better the application will interact with its future audience.
  • Bot functionality. Here you explain what tools the application should have, what it will do: answer questions, take orders, etc.
  • Trigger words and risk topics. Here you specify the phrases at which the bot should transfer the conversation to a live specialist. This could be, for example, the phrase "I will stop working with you," profanity, etc.
  • Performance. Calculated based on the size of the potential audience. Here, pauses between responses, response duration, etc., should be taken into account. The faster the application works, the faster it will finish the conversation with a user and be able to move on to the next client: this is important during the so-called "peak hour," when the number of people needing its help is large.
  • Integrations. If the bot needs to work with payment and CRM systems or other external platforms, state this in this section.
  • Solution security. Here, requirements for confidentiality and protection of users' personal data are specified. If the application collects such information, the encryption and authentication mechanisms must be reliable.
  • Technologies used. Here, the software and technologies chosen for working with the application are specified.
  • Chatbot personality. The bot's name, description, character: everything that will help people establish interaction with it and perceive it as a personality.
  • Personalized communication. If the bot can address a person by name, it improves their interaction.
  • Use of neural networks and AI. If they are to be involved in the bot's development, you need to specify which platforms should be used, whether they should learn during interaction with the client, how data protection will be ensured while working with them, etc.
  • Success criteria. Here you specify what result you want to achieve, how you will evaluate it, by what parameters, how it will be interpreted, etc.

The more precise and detailed the technical specification is, the better the result you will get, and the less time you and the programmer will spend on potential revisions.

After the technical specification is created, write it down and discuss it with the developers. Make sure they can fulfill it according to your wishes and discuss the cost of the work.

Chatbot Builders


Another option for building a bot from scratch is to use a builder. Here you create blocks in which you write the bot's text and actions and connect them in a specific order. You can get acquainted with the three best builders below.

Botman
A builder for chatbots and sales funnels for Telegram and VK. In the free plan, you will get basic features that allow you to create simple chatbots and use them to solve your tasks. A series of video tutorials will clearly and simply explain how to work on the platform and teach you how to create applications of varying complexity.



Chatbots can be used in the following areas:
  • sales of goods and services (product consultation, handling customer objections);
  • infobusiness;
  • managing communities and groups on social networks, channels in messengers;
  • receiving payments and processing product pickup or delivery.

Advantages of Botman:

  • free basic functionality;
  • you can develop bots for use in different areas;
  • simple and informative video courses and text instructions;
  • analytical tools for collecting statistical data and tracking chatbot effectiveness;
  • a large selection of templates;
  • integrations with payment systems, Google services, CRM systems.

If you don't want to work on creating a bot yourself, you can order such an application on the platform. To do this, you need to submit a request and describe what exactly is required. After that, a specialist will contact you to discuss the details. A separate advantage of the platform is the free course on bot development without programming skills from the founder himself.

Botmother
A platform for creating chatbots of any complexity. Here you can build applications for Telegram, Viber, WhatsApp, Odnoklassniki, and VKontakte by simply dragging and dropping ready-made blocks in a visual editor.



There are ready-made templates that you can edit for yourself or use as they are. After registration, a free trial plan will be available, on which you can create up to ten bots with a limit on the number of users and sent messages. To remove them, you need to pay for one of the four paid plans.

Multy
Multy is a multi-builder for creating chatbots and websites. It has a simple and intuitive interface, many templates for different life situations, as well as free training to get acquainted with the platform's tools.



With Multy, you can create chatbots and automate business processes, set up newsletters in Telegram and VK, and build websites. Wide integration possibilities with payment systems, AI, CRM systems, and other services and platforms are available. There are no free plans, but you can explore Multy's features for 14 days and then choose one of the three tariff plans.

What to Consider When Creating a Chatbot


When developing chatbots, it is important to ensure the following is done:

  • the goal is defined and clearly formulated;
  • a builder site or programming language is chosen for creating the bot yourself, or a specialist/organization is selected to do the work;
  • the application's audience is defined and a communication style is chosen;
  • a script for the chatbot's operation is developed;
  • the design and interface are defined;
  • the bot is simple and understandable for the user, not overloaded with unnecessary functions without great need;
  • there are enough response options for the application to user questions so that the bot can likely help them on its own and end the dialogue: if it constantly resorts to employee assistance, this will reduce the feasibility of its use;
  • the bot is secure: if you collect users' personal data, pay due attention to their protection, and apply appropriate encryption protocols.

If all this is taken into account, you can proceed to creation.

Technical Characteristics of Chatbots


To create a bot, you need to understand its operating principle and know how scripts are written and what types they come in depending on the application's type.

Operating Principle
The bot's operating principle can be represented as follows:

  1. The user starts the bot.
  2. The application greets the person, explains what tasks it performs, and offers to enter a question or choose from available options (this could be several buttons with bot functions or phrase options to enter: "Prices," "Services," "Help," etc.).
  3. The person writes a message or makes a choice.
  4. The application analyzes the user's message and either provides a response or transfers the dialogue to an operator.

Steps 3-4 are repeated until the person's question is resolved or until the bot determines it cannot help the user and invites a specialist.

Developing Scripts for Specific Types of Chatbots


In the field of chatbots, the script, also known as the structure, is of key importance. It looks like a logical chain of message blocks, along which a person moves until their problem is solved. The more precisely the script is made, the better its chain and branches are thought out, the faster the user will get a result.

The script is created taking into account the type of bot, which, in turn, is determined by the goals, tasks the application performs, and its functionality.

Types
There are many classifications of bots based on various criteria. Here are some types of bots:

  • Intelligent and limited. The first category includes applications that involve machine learning and the gradual expansion and improvement of scripts. The second category works with a fixed script that does not allow for changes.
  • Platform. For which device and OS the bot is created: for PC, smartphones, for Android, iOS, and Windows, etc.
  • Area of application. Applications are created to work in messengers, social networks, and on websites.
  • Type of communication. Text or voice bots.
  • Tasks. The application only finds and sends data upon request or does something on its own.
  • Creation goals. Bots can be for consultations and sales, for organizational tech support, assistants, informational, for lead generation, accepting payments and arranging delivery, etc.
  • Button-based or text-input. To interact with the application, you need to send messages or press menu buttons.
  • Bots with or without smart suggestions. When typing a word, the user sees popular queries related to that word, which the application suggests.
  • Smart bots. Interaction with them is as close as possible to communicating with a person; they recognize speech and respond almost like real people. Voice assistants belong to this category of applications. Bright examples are Alice from Yandex or Google Assistant.

A specific script is selected for each type of bot to achieve maximum efficiency.

Developing a Script for Each Type of Bot
A script for a chatbot can be created using the following scheme:

  1. Define the purpose of creating the application and think through the tasks it should perform.
  2. Think through the flow of the script, from greeting to saying goodbye to the client.
  3. Break the script into steps, and for each step, determine the information that needs to be conveyed to the client, how to handle their possible objections, etc., i.e., everything that should be at this stage and what will lead to the next one.
  4. Design each step in the form of a dialogue with the client.
  5. Write in approvals of the user's actions to establish interaction and an emotional connection with them.
  6. Create a portrait of the chatbot, give it a personality: come up with a gender, name, avatar. Define its status: consultant, assistant, support employee, user's friend, etc.
  7. At each step, provide an option to transfer the conversation to a live operator.

Different types of scripts are suitable for different types of bots. Possible options:

  • "Time Cave" ("Pyramid"). A universal and simplest type of script, optimal for applications that provide consultations on services and products. The bot sends an initial message to find out the client's questions, and then, depending on the answer, offers a series of options. Can be used for online stores, business consultants, tech support.
  • "Glove". A type of script based on a central pillar. Branches extend from it, which end either with the bot stopping or by going back a few steps. Suitable for training courses. The bot sends materials, asks a final question, and, after analyzing the answer, decides whether to move on to a new task or go back to repeat. Can also be used for simulators and sales funnels.
  • "Glove 2.0" ("Branched Scheme," "Branches and Bottleneck"). Like the previous type of script, it has a central pillar and branches, but the latter can intersect at key points in certain places. Made for developing large-scale business applications with impressive functionality.
  • "Game Model". The script is implemented as a test, quest, or quiz, has many connecting branches, and allows for multiple endings. Suitable for learning: information is better remembered in a game format.
  • "Free Space". The script implies development in both directions. There is a central pillar, with branches extending from it, which in turn have blocks extending from them. A simple, visual, and understandable scheme.
  • "Open Map". The user can move freely between levels of interaction with the bot. Used for applications that include several simpler bots performing various functions.

The effectiveness of your application will depend on a well-thought-out choice of script.

Useful Recommendations for Creating Bots


A number of tips and recommendations that will help in writing an effective bot:

  1. Clearly define the tasks the application will solve: this will help you or the people working on your order to achieve the result you want.
  2. When greeting the user, the bot should explain what tasks it performs, how it works, and how it can help people. This will simplify the interaction between the person and the bot.
  3. When working on the bot, strive to ask questions that can be answered with a single word, or provide a choice of several options (with a separate button for each). Do not use an interaction method where the user can give a detailed answer to the application's question: this can confuse the bot, and it will not complete its task.
  4. To prevent the bot from deviating from the script, program its operation so that it can return to familiar conversation topics if the user steers the dialogue aside.
  5. The bot should ask clarifying questions to accurately determine the user's needs, and if it fails to do so, it should transfer the conversation to a live employee.
  6. When interacting with the application, users can send it messages or choose the desired response options from the provided buttons. Opt for the second option: this way, the bot won't get sidetracked from the script if the person starts writing detailed questions or asking about things not covered in the script.
  7. Define your potential audience and set the bot's communication style to match it as closely as possible.
  8. Don't offer too many functions at once: this will confuse users. It's better to start with a minimum of features and then gradually add new ones, notifying people about them and explaining how to use them.
  9. There should always be a person to whom the bot can transfer the dialogue. This is necessary for dealing with difficult clients or in cases where the application's capabilities are insufficient.
  10. If possible, use chatbot builders instead of programming: they are easy to use, and after spending a little time on training, you can create chatbots yourself and design them exactly as you need. If you don't have programming skills, learning it will be more difficult, and ordering an application from programmers will require additional funds.
  11. Test the chatbot before launch: make sure it works correctly and resolves users' issues.
  12. Promote the chatbot. If you have a website, talk about the application there. Write about it in your groups and communities on social networks and messengers. If you work with people directly, for example, providing any services, inform them that they can use the bot, for instance, to book a consultation with you or get information about products or services.

Follow these rules, and the resulting bot will interact well with users and help them solve their questions.

Questions and Answers about Chatbots (FAQ)


— What should I choose: create a chatbot with a builder or order one from a programmer?
— Both options are possible, but working on the application yourself in a visual builder will be cheaper than hiring programmers. In this case, you will control every step of the application's development and can achieve the exact result that best meets your needs.

— Where can chatbots be used, in which social networks or messengers?
— The scope of application for chatbots is very wide. They are usually used on Telegram, less often on VK, but you can create a chatbot for WhatsApp, Viber, "Odnoklassniki," Instagram* or Facebook, for your website. Applications can be developed for external communication with clients, partners, or other people, as well as for internal use, for example, within a company to check completed tasks or work with reports.

— What are bots and why are they called that?
— A bot (short for "robot") is a small application or program capable of performing specific tasks through interaction with a user. Bots can be used for personal purposes and in business; their range of application is very wide.

— Why have chatbots become so popular?
— Chatbots are popular because they can simplify a wide variety of tasks: with their help, you won't forget an important event, you can download videos or music, translate foreign words, etc. In business, chatbots help streamline the process of interacting with customers, improve sales, and significantly save on employees: today, such applications successfully work in tech support, act as personal assistants, process sales and product delivery, book appointments or consultations, and solve many other tasks. Even if you order their development from programmers or on sites with bot builders, it will pay off in the long run, as you will improve your work with clients and, consequently, sales, and you will also be able to save on the salaries of employees who will be replaced by the application.

— Can bots be connected to other services and platforms?
— Yes, bots today successfully integrate with other platforms. These can be payment or CRM systems, Google services (Google Sheets, etc.), educational platforms, telephony, advertising services, and much more.