VK API client for chatbots with support v. 5.80.
// 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
$vk->request($method, $callback = []);
$method
- methods of VK API
$callback
- array of transmitted fields
$user_info = $vk->request('users.get', ['user_ids' => '391726310']);
{
"response":
[
{
"id": 391726310,
"first_name": "Sherzod",
"last_name": "Mamadaliev"
}
]
}
echo 'Name: ' . $user_info['response'][0]['first_name']; // Name: Sherzod
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
}
}