📜 ⬆️ ⬇️

Conversational bot for Vkontakte in PHP

Intro Lyrics


One day, one thought struck me that it would be nice if such daily tasks as posting and maintaining account activity on a social network were not performed by a person, but by a simple conversational bot. Moreover, with a “botnet” of several hundred accounts, it is impractical and almost impossible to carry out a task with the help of one person. Therefore, the idea arose to write a conversational bot with the tools that I knew best of all. I decided to make a PHP bot.

Base of answers


To begin, as you already guessed, it was necessary to search for bases for bot answers and an elementary technical task that would help to do everything quickly and with a minimum number of crutches (I did not succeed without crutches).

A little earlier, I met an interesting project from the company Nanosemantika, which deals with similar tasks and creates, like, commercial bots support and so on. This project is iii.ru. On the project site, you can create a bot and get its flash-version for insertion on the site. They did not have an API, they had to decompile swf.

Zakriptovano ?!


The first thing that occurred to me when I opened the decompiled SWF file code was where to find the answer point point and how to turn it all to the side of my idea. There was no limit to surprise when I saw that all requests and responses are encrypted using XOR + Base64, and the decryption key was at the beginning of the code. Why then crypt?
')

The technical part of the question


The main tasks that my bot had to perform were to receive the latest messages from Vkontakte, send them to the server, receive a response, send a response to the person who communicates with the bot.

The following files were created:
- index.php (works as a client, updating with jquery a file with uploading incoming messages and a subsequent response)
- autoload.php (actually, the file that receives and responds)
- showmeid.php (file that creates a new chat ID, if the other person is chatting with the bot for the first time)
- config.php (connection to the database with bot clients)
- classes.php (classes for working with the bot)

Installation


1. Import dump.sql into your database
2. Get the “long-playing” access token to work with the VK API using the link - get token
3. Rename config.sample.php to config.php before changing the data for the connection to the database
4. Use running index.php

So, I ask to get acquainted - Larisa Chernyshova

And also source codes on GitHub .

UPD: If the bot does not respond, it means that sending a message is blocked by a request to enter a captcha.

For details and questions, welcome to my blog.

Source: https://habr.com/ru/post/251687/


All Articles