├── .gitignore ├── README.md ├── composer.json ├── composer.lock ├── composer.phar └── index.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | .idea -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # demo-bot 2 | 3 | php composer.phar install 4 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vkcom/vk-php-sdk": "^0.2.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "508ef5dd21698c10801cf24fe18994fd", 8 | "packages": [ 9 | { 10 | "name": "vkcom/vk-php-sdk", 11 | "version": "0.2.0", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/VKCOM/vk-php-sdk.git", 15 | "reference": "4e31c1eecf0a310018e6249e48e6a336cd6d90e6" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/VKCOM/vk-php-sdk/zipball/4e31c1eecf0a310018e6249e48e6a336cd6d90e6", 20 | "reference": "4e31c1eecf0a310018e6249e48e6a336cd6d90e6", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "php": ">=7.1" 25 | }, 26 | "require-dev": { 27 | "phpunit/phpunit": "^6", 28 | "vkcom/vk-api-schema": "^1.8.0" 29 | }, 30 | "type": "library", 31 | "autoload": { 32 | "psr-4": { 33 | "VK\\": "src/VK" 34 | } 35 | }, 36 | "notification-url": "https://packagist.org/downloads/", 37 | "license": [ 38 | "MIT" 39 | ], 40 | "description": "VK PHP SDK", 41 | "homepage": "https://github.com/VKCOM/vk-php-sdk", 42 | "keywords": [ 43 | "sdk", 44 | "vk" 45 | ], 46 | "time": "2018-04-09T08:54:34+00:00" 47 | } 48 | ], 49 | "packages-dev": [], 50 | "aliases": [], 51 | "minimum-stability": "stable", 52 | "stability-flags": [], 53 | "prefer-stable": false, 54 | "prefer-lowest": false, 55 | "platform": [], 56 | "platform-dev": [] 57 | } 58 | -------------------------------------------------------------------------------- /composer.phar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stels-cs/demo-bot/249499153b75976adf3a424e98fdadb587897d09/composer.phar -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | [ 27 | 'type' => 'text', 28 | "payload" => json_encode($payload, JSON_UNESCAPED_UNICODE), 29 | 'label' => $label 30 | ], 31 | 'color' => $color 32 | ]; 33 | } 34 | 35 | 36 | $json = file_get_contents('php://input'); 37 | //myLog($json); 38 | 39 | 40 | $data = json_decode($json, true); 41 | 42 | $type = $data['type'] ?? ''; 43 | 44 | $vk = new VKApiClient('5.78', VKLanguage::RUSSIAN); 45 | 46 | if ($type === 'message_new') { 47 | 48 | 49 | $message = $data['object'] ?? []; 50 | $userId = $message['user_id'] ?? $message['peer_id']; 51 | $body = $message['body'] ?? ''; 52 | 53 | $payload = $message['payload'] ?? ''; 54 | 55 | if ($payload) { 56 | $payload = json_decode($payload, true); 57 | } 58 | 59 | myLog("MSG: ".$body." PAYLOAD:".$payload); 60 | 61 | $kbd = [ 62 | 'one_time' => false, 63 | 'buttons' => [ 64 | [getBtn("Покажи мой ID", COLOR_DEFAULT, CMD_ID)], 65 | [getBtn("Далее", COLOR_PRIMARY, CMD_NEXT)], 66 | 67 | ] 68 | ]; 69 | 70 | $msg = "Привет я бот!"; 71 | 72 | if ($payload === CMD_ID) { 73 | $msg = "Ваш id ".$userId; 74 | } 75 | 76 | if ($payload === CMD_NEXT) { 77 | $kbd = [ 78 | 'one_time' => false, 79 | 'buttons' => [ 80 | [getBtn("Пошли тайпинг", COLOR_POSITIVE, CMD_TYPING)], 81 | [getBtn("Назад", COLOR_NEGATIVE)], 82 | ] 83 | ]; 84 | } 85 | 86 | if ($payload === CMD_TYPING) { 87 | try { 88 | $res = $vk->messages()->setActivity(VK_TOKEN, [ 89 | 'peer_id' => $userId, 90 | 'type' => 'typing' 91 | ]); 92 | $msg = null; 93 | } catch (\Exception $e) { 94 | myLog( $e->getCode().' '.$e->getMessage() ); 95 | } 96 | } 97 | 98 | try { 99 | if ($msg !== null) { 100 | $response = $vk->messages()->send(VK_TOKEN, [ 101 | 'peer_id' => $userId, 102 | 'message' => $msg, 103 | 'keyboard' => json_encode($kbd, JSON_UNESCAPED_UNICODE) 104 | ]); 105 | } 106 | } catch (\Exception $e) { 107 | myLog( $e->getCode().' '.$e->getMessage() ); 108 | } 109 | 110 | } 111 | 112 | 113 | echo "OK"; 114 | --------------------------------------------------------------------------------