How to make a chatbot for a VKontakte group: step-by-step instructions


Chatbots are a great time saver: you don’t have to log into social networks every five minutes, but simply check conversations once a day and place orders. I’ll tell you how to create a chatbot on VKontakte, even if you don’t understand code.

There are special services for creating bots: Robochat, BotVK, Chatgun and others. I will show the process of creating a free chatbot on VKontakte using Chatgun as an example - the interface of all services is approximately the same, so you can easily do the same on another platform.

What can a VK chatbot do?

Involve your subscriber in an event or newsletter. Using the “Community Subscription Reaction” function, invite a newcomer to subscribe to your newsletter, tell him about a new promotion or giveaway.

Keep the subscriber from leaving the community. When the user clicks on the “Unsubscribe” button, the chatbot will send a letter with words of regret or offer a discount.

Help the client resolve the issue. The chatbot will select the right product, tell you about discounts, or simplify navigation through the community. Using certain commands, a subscriber can request information of interest, and the chatbot will provide it.

Conduct games, surveys, competitions. The chatbot will entertain the user with a game or collect the necessary information about the target audience using a survey.

Provide answers to frequently asked questions. The user may write because he is simply bored, or wants to know more about the product. The chatbot will answer the buyer and ask clarifying questions.

Next, we will show how to create and configure a chatbot using the Robochat.io constructor and the Senler mailing service.

You need to send a newsletter on VK, create a chat bot or set up a target - contact us! We have extensive experience promoting business on VKontakteRead more

How to invite the bot Kai to a conversation on VK: install

How to invite the bot Kai to a conversation on VK? First of all, we need to create a VKontakte conversation, and then we need to:

Go to the official public page of the bot Kai on VK and subscribe;

Then, in the quick links tab, select “Add to conversation”;

Then you will need to select the conversation in which you want to install the Kai bot and click on the “Invite” button;

After this, Kai will appear in the conversation, but you will need to click on the list of participants under the name of your conversation and then make the Kai bot the chat administrator;

Then write a message to the conversation with the text “Kai update” to activate the bot;

After which Kai will be activated and will begin to execute commands and answer questions in conversation.

To install the Kai bot into a conversation on VK from an Android phone or iPhone, you need to follow the same procedure as on a computer: that is, just join Kai’s group and invite him to a conversation on VK.

What can Kai do in VK? Bot Kai can do a lot, for example, he can remove participants from a conversation, issue a warning, temporarily block a participant, and can also simply communicate and answer questions.

What questions can you ask Kai on VK? Yes, in general, any, you can see for yourself and see what the bot Kai answers to various questions:

How to set up the Kai bot on VK?

How to set up the Kai bot on VK? Actually, you don’t need to configure Kai, all the settings have already been made, you just need to give the bot the necessary commands, and it will carry them out.

A list of all available commands for the Kai bot is available at this link. In addition, you can ask the meaning of a particular command directly from Kai himself.

Now you know how to use Kai in VK.

Group registration in Robochat.io

After registering with the service, link the community to your personal account.

  1. Select from the list the group where the chatbot will work.

  1. Give the service access to the community.

  1. Connect the starter template to get started with your chatbot.

The service will link a group to the template and open a work account. You need to immediately set the settings so that the bot turns off if the administrator enters into a dialogue with a subscriber.

  1. In the left column, click the “Manage Bot” button.
  1. Specify the time during which the bot will not be able to intervene in the dialogue → save.

On the right side there are reaction sections that you can use to configure the chatbot.

In the screenshot you will see the points by which you can configure the bot. In the article, the chain of reactions will be set up according to the sales funnel.

#2. Service bot-vk

If the functionality of Robochat is not enough for you, you can try the bot-vk.ru service. In general, the instructions for creating a bot for your VKontakte group using this site will be very similar to the previous one.

  • To get started, go to the website bot-vk.ru.
  • Click on the “Create a bot right now” button and log in to the system.
  • Like any other application, VK Bot will ask you to allow access to your data. If you are not ready to provide them, then it is better for you to use another method of creating an assistant.

  • After that, use the “Connect group” button and in the list provided, select exactly the community into which you want to embed the bot.
  • Don't forget to confirm the action using the "Allow" button.
  • After that, in the “List of bots” section you will be able to edit and customize the assistant according to your requirements.

There you can also disable the bot when you no longer need it.

Reaction to subscription

A person decides to subscribe to your community - this is a chance to involve him in your newsletter.

  1. Go to “Reaction to subscription”.

  1. Greet the subscriber in the letter, offer assistance in navigating the content through the newsletter.

As a result, when a person subscribes to the group, he will receive a message from the chatbot.

Welcome message using Senler

In RoboChat, the welcome message is sent only once. This is not very convenient, because a subscriber can unsubscribe and subscribe to the newsletter several times. Therefore, it is better to connect a greeting message through a mailing service. I use Senler.

Log into your personal account for your mailing service.

  1. Newsletters → new mailing list.

  1. Write a welcome message and add keywords that the chatbot will respond to.
  2. Auto-message → count clicks on links → save.

The subscriber will receive such a letter.

The letter contains 4 commands - we will register them in Robochat.io.

Setting up commands

Return to the Robochat.io service.

  1. Scripts → create a command.

  1. Enter your keyword in the first field.
  2. In the “Bot response” field, write a response option. Be sure to indicate that you can return to the beginning of the menu using a command (otherwise the chatbot will respond to other commands as an error).

This is what the message will look like.

We do the same with the other teams: “1-3”, “3-6”. For the game team “Let’s go” the chain will be a little more complicated.

Deploying functionality

First of all, let's create a manage.py file.
Let's create a prototype of the built-in keyboard (all using the VkBotAPI documentation).

main_keyboard = { "one_time": False, "buttons": [ [{ "action": { "type": "text", "payload": "{\\"button\\": \\"1\\" }", "label": "About us" }, "color": "positive" }], [{ "action": { "type": "text", "payload": "{\\"button\\ ": \\"2\\"}", "label": "Events" }, "color": "positive" }, { "action": { "type": "text", "payload": "{ \\"button\\": \\"3\\"}", "label": "Applications" }, "color": "positive" } ], [{ "action": { "type": "text "", "payload": "{\\"button\\": \\"4\\"}", "label": "Contacts" }, "color": "primary" }] ] } Then we transfer it to json format, as required in the documentation: main_keyboard = json.dumps(main_keyboard, ensure_ascii=False).encode('utf-8') main_keyboard = str(main_keyboard.decode('utf-8')) Inline keyboard example: about_us_keyboard = { "inline": True, "buttons": [ [{ "action": { "type": "text", "payload": "{\\"button\\": \\"1\\"}" , "label": "Basic information" }, "color": "positive" }], [{ "action": { "type": "text", "payload": "{\\"button\\": \\"2\\"}", "label": "What are we doing?" }, "color": "primary" }, { "action": { "type": "text", "payload": "{\\"button\\": \\"3\\"}", " label": "Where are we?", }, "color": "positive" }], [{ "action": { "type": "text", "payload": "{\\"button\\" : \\"4\\"}", "label": "How to get into the team?", }, "color": "primary" }], [{ "action": { "type": "text", "payload": "{\\"button\\": \\"5\\"}", "label": "Contacts", }, "color": "secondary" }], [{ "action": { "type": "text", "payload": "{\\"button\\": \\"6\\"}", "label": "project manager", }, "color": "negative " }] ], } Don't forget to convert all used keyboards into json format: about_us_keyboard = json.dumps(about_us_keyboard, ensure_ascii=False).encode('utf-8') about_us_keyboard = str(about_us_keyboard.decode('utf-8' )) Let's create a function write_msg, in order not to suffer from constantly sending messages from the bot: def write_msg(user_id, message, key): vk.method('messages.send', {'user_id': user_id, 'message': message, 'keyboard': key, 'random_id': random.randint(0, 2048)}) After creating all the prototypes, we can move on to the next step. (we will return to this file later and finalize the processing of communication between the user and our vk-bot)

▍2.1 Main functionality (create the vk_bot.py file)

We will not develop methods that will perform, for example, the function of parsing time or weather; we will call them secondary.
I will show only the main method that will access these secondary methods to process certain messages from the user. At the end of the article, I will post a link to my GitHub, where you can independently view the functionality of any of the methods that interests you. So: Class constructor:

class VkBot: def __init__(self, user_id): self.USER_ID = user_id self._USERNAME = self._get_user_name_from_vk_id(user_id) self.my_str = "" self._COMMANDS = ["hello", "weather", "time", " bye"] self._inputMes = {"basic information": answers.about_us1, "what do we do?": answers.about_us2, "where are we located?": answers.about_us3, "upcoming events": answers.events1, "held events": answers.events2, "volunteering for an event": answers.events3, "ongoing projects at NSTU": answers.events4, "events of the interuniversity center": answers.events5 } The last property of the class - inputMes - is a special dictionary that has the key values ​​are the text from the answers.py file, where I arranged the text in the form of lines, so in order not to clutter the code, I moved the main text to another file.

(Example code from answers.py )

events1 = "So, the upcoming events:\\n\\n" \\ "Forum "Baikal"\\n"\\ "Digital Wind Competition\\n"\\ "PRONETI" events2 = "Here is a list of events held :\\n"\\ "MNTK\\n"\\ "Seminars on project activities\\n"\\ "Meeting with representatives of enterprises\\n"\\ events3 = "Concerning this criterion, write to Ilya ()\\ n"\\ "And also, you can fill out a form, thanks to which,\\n"\\ "one of the heads of the direction\\n"\\ "or the project coordinator ()" So, the main method of the class is this is new_message, which takes one parameter - message, which is processed by the corresponding conditional block and returns some value back to where it was called from. def _get_user_name_from_vk_id(self, user_id): request = requests.get("" + str(user_id)) bs = bs4.BeautifulSoup(request.text, "html.parser") user_name = self._clean_all_tag_from_str(bs.findAll("title "")[0]) return user_name.split()[0] def new_message(self, message): # self.my_str = " ".join(re.findall('[0-9]{2}', message) ) if message.lower() == self._COMMANDS[0]: return f"Hello, {self._USERNAME}!" elif message.lower() == self._COMMANDS[1] or message.lower() == "get the weather": return self._get_weather() elif message.lower() == self._COMMANDS[2] or message. lower() == "find out the exact time ": return self._get_time() elif message.lower() == self._COMMANDS[3]: return f"See you soon, {self._USERNAME}!" else: for key, value in self._inputMes.items(): if message.lower() == key: return value return “I don’t understand you “

Game with chatbot

Now we need to think over a chain of questions and answers for the “Let’s Go” team.

  1. Create a new team, enter a question.
  2. Select the “Switch to another command if” form and enter the correct answer.
  3. In the script, select the pre-generated key (correct answer).

  1. In the key, write the next question and the new key with the correct answer.

This is what happened.

Dynamic buttons

Buttons can be implemented at any stage. In this article we will show you how to do this with the “Let’s Go” command.

  1. Script → menu → command keyboard.
  2. In the panel with buttons, write a keyword → add a transition → script for the key “let’s go” → save.

This is what the button looks like in a message.

You can experiment with buttons: make many buttons with answer options, change their colors, connect them at all stages.

#3. bots-kit constructor

Another interesting designer is bots-kit.com. In order to start using it, you must also register.

Or, as an option, use the VK login.

  • Using the already familiar procedure, allow the application to access your page.
  • After this, you can proceed to actually creating and setting up a bot for your group.

Please note that there are paid plans for this type of builder. But the prices do not bite (from 50 to 150 rubles per month). Be sure to read them before making your bot in a group or on a VK page.

  • Then move on to creating a helper. To do this, click on the “Bots” tab and select the “Create” section.

  • At the first stage, come up with a name for the service and click “Continue”.
  • Select the platform where you want to embed the bot (in our case, VKontakte).

  • Then, in the Settings section, edit the script.

  • After you finish setting up, don't forget to click "Save".

  • There is another option for setting up a bot using keywords. To do this, go to the “Scenarios” section and click the “Add answer” button.

  • Fill out a short form and click “Add” for your settings to take effect.


The advantage of using this constructor is that you can create a newsletter (tab of the same name), view statistics or get a report on the assistant’s work. Therefore, this service is one of the most convenient for beginners.

Response to frequently asked questions

Often, before asking a question, users say hello and wait for an answer. So that the subscriber does not have to wait for the message to be read by the administrator, create a reaction to the greeting.

  1. In the “Scripts” section, create the keywords “hello”, “hello” so that the chatbot will immediately respond to the message.
  2. Enter other common requests as well. For example: “how are you”, “help”, “I want to buy”, “delivery”, “promotion”, etc.

Types of bots

Chatbots can be classified by type and purpose. According to the first criterion, two types of programs are distinguished - primitive and advanced.

Primitive chatbots respond to messages that contain a code word. If the user enters an original message - not according to the proposed template - the program will not answer him or will report that he did not understand the command.

Advanced chatbots understand any user requests and try to give relevant answers to them. You don’t have to look for words in hopes of formulating a request—the artificial intelligence program will understand the user in any case.

Advanced chatbots understand not only text, but also voice commands. They are constantly learning, adding to their knowledge base from conversations with users.

A primitive chatbot can be created for free, without any special knowledge or experience. Creating an advanced chatbot is a complex process that requires the participation of programmers.

There is another classification of chatbots - by type of goal. There are four types of programs here:

  1. Assistants. Chatbots of this type will find the information you need—for example, the weather forecast in a neighboring city—and help you order food for the office or find the cheapest air ticket. They understand only template messages.
  2. Artificial intelligence. Those same advanced chat bots. They can be trained to do anything - close clients for a deal, find the user the information they need, etc.
  3. Business bots. A useful tool for business communities. In such a chatbot you can embed a mailing list with a chain of letters to invite people to a webinar or marathon, an autoresponder with notifications about when users perform any actions in the community.
  4. Gaming. With such a chatbot you can play gallows, roulette or any other simple game. Such programs easily imitate human actions, as they are based on artificial intelligence.

A chatbot should be created only when you have decided on your goals. If you need a bot assistant who will warm up leads or bring them to a deal for you, contact the specialists. You can create a simple chatbot for sending messages, increasing activity in a group, or increasing subscribers.

What's the result?

The chatbot constructor Robochat.io and the Senler mailing service significantly save time on communicating with clients and help automate promotion on VKontakte. You yourself saw how they:

  1. Involved the subscriber in the newsletter.
  2. We persuaded him not to unsubscribe from the community.
  3. Helped me find the information I needed.
  4. We played a game.
  5. We talked with the client.

And all this without your participation.

You can experiment and create more complex chains of reactions. To help you, we have collected 25 ideas for implementing a chatbot based on the experience of famous brands. Use it.

How to determine who is communicating with you - a real person or a bot

Modern technologies are so developed, and time flies forward so quickly that the average person has less and less time to communicate.

Many companies optimize business processes by outsourcing the functions of consultants to bots. If you are communicating with a bot consultant, then determining who is in front of you will be much more difficult than with a bot interlocutor.

Observe the reaction of the user who responds to you.

  • If you receive a long message in response in just a couple of seconds, this is a sure sign of conversation automation.
  • If your interlocutor sends you a message again, the text of which is exactly similar to the one sent earlier, a chatbot is probably communicating with you.
Rating
( 1 rating, average 4 out of 5 )
Did you like the article? Share with friends:
For any suggestions regarding the site: [email protected]
Для любых предложений по сайту: [email protected]