Skip to content

Latest commit

 

History

History
86 lines (74 loc) · 2.16 KB

README.md

File metadata and controls

86 lines (74 loc) · 2.16 KB

License Minimum PHP Version

client-for-vk-chatbots 1.0

VK API client for chatbots with support v. 5.80.

Documentation

Beginning of work

// config.php

define('VERSION', '5.80');          // VK API version
define('TOKEN', '9d94d3...70d59e'); // your token
define('KEY', '4cw0de5e');          // your security key
// example.php

require_once('vk.php'); // connection library for working with VK API
$vk = new VK();         // creating a VK class object

The universal method

$vk->request($method, $callback = []);

$method - methods of VK API

$callback - array of transmitted fields

Request:

$user_info = $vk->request('users.get', ['user_ids' => '391726310']);

Response:

{
    "response":
    [
        {
            "id": 391726310,
            "first_name": "Sherzod",
            "last_name": "Mamadaliev"
        }
    ]
}

Output:

echo 'Name: ' . $user_info['response'][0]['first_name']; // Name: Sherzod

Example

require_once('vk.php'); // connection library for working with VK API

$vk = new VK();         // creating a VK class object

if ($vk->data['type'] == 'message_new') // if there is an event message_new
{
    $peer_id = $vk->data['object']['peer_id'];  // user ID
    $text = $vk->data['object']['text'];        // incoming message

    if ($text == 'Start') // if the text is Start, it will send a Started message.
    {
        $vk->send($peer_id, 'Started');
    }
    elseif ($text == 'Hi') // if the text is Hi, it will send a Hello message.
    {
        $vk->send($peer_id, 'Hello');
    }
    else
    {
        $vk->send($peer_id, 'Error'); // error
    }
}