PHP code example of funnyrain / vkbot

1. Go to this page and download the library: Download funnyrain/vkbot library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

funnyrain / vkbot example snippets


  = new Bot();
$bot->setToken('токен');

$bot->start(function($data)use($bot){

    $msg = $bot->getMessage();
    $kb = $bot->kBuilder(); // Подключаем билдера кнопок
    if ($msg->get() == "кнопки") {
        $kb->create(
          [
            [ // <-- Начало первой строки
              $kb->button('красная кнопка', 'red'),
              $kb->button('зеленая кнопка', 'green'),
              $kb->button('синяя кнопка', 'blue')
            ], // <-- Конец первой строки 
            [ // <-- Начало второй строки
              $kb->link('кнопка с ссылкой', 'http://example.com'),
              $kb->location()
            ] // <-- Конец второй строки 
          ]
          // one_time (По стандарту false),
          // inline (По стандарту false)
        );
        /** 
         * Должно вывести клавиатуру в таком виде:
         *        [--] [--] [--]
         *          [--] [--]
         */
        $msg->reply('Отправляю клавиатуру:', [
          'keyboard' => $kb->get()
        ]);
    }

});

  = new Bot();
$bot->setToken('токен');

$bot->start(function($data)use($bot){

    // chat_invite_user - Событие добавления в беседу
    // Список всех событий: https://vk.com/dev/groups_events
    $bot->isAction('chat_invite_user', function($data)use($bot) {
        $msg = $bot->getMessage();
        if ($data['member_id'] == -$bot->group_id)
            $msg->reply('спасибо за приглашение');
    });

});

  = new Bot();
$bot->setToken('токен');

$bot->start(function($data)use($bot){

    $msg = $bot->getMessage();
    if ($msg->get() == "info") {
        $msg->reply(
            "привет"
        );
        //$msg->sendSticker(51077);
    }

});