Talk bot for Vkontakte in PHP

    Intro Lyrics


    One day, it dawned on me that it would be nice if such everyday tasks as posting and maintaining the activity of an account on any social network were performed not by a person, but by a simple conversational bot. Moreover, with a “botnet” of several hundred accounts, it is impractical and almost impossible to complete a task with the help of one person. Therefore, the idea came up to write a conversational bot by means that were best known to me. I decided to make a bot in PHP.

    Answer Base


    As you already guessed, you had to start by searching the bases for the bot’s answers and elementary technical task, which would help to do everything quickly and with the minimum number of crutches (I couldn’t do without crutches).

    A little earlier, I met one interesting project from the Nanosemantics company, which deals with similar tasks and creates, like, commercial bots and supports, and more. 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, I had to decompile swf.

    Scripted ?!


    The first thing that occurred to me when I opened the decompiled code of the SWF file is where to find the output point of the answers and how to turn it all in the direction 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 crypt then?

    The technical part of the question


    The main tasks that my bot was supposed 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 is communicating with the bot.

    The following files were created:
    - index.php (it works as a client, updating a file using jquery with loading of received messages and the subsequent response)
    - autoload.php (actually the file that accepts and responds)
    - showmeid.php (file that creates a new chat ID if the interlocutor first communicates with the bot)
    - 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 a “long-playing” access token for working with VK API using the link - get token
    3. Rename config.sample.php to config.php after changing the data for the database connection
    4 Use running index.php

    So, please get acquainted - Larisa Chernyshova

    And also the source code on GitHub .

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

    For details and questions - welcome to my blog

    Also popular now: