Skip to content
/ bot Public

Chatbots client for VK API v. 5.80.

License

Notifications You must be signed in to change notification settings

varkrift/bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
    }
}

About

Chatbots client for VK API v. 5.80.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages