KeyboardCommand.php 2.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php

/*
 * This file is part of the TelegramBot package.
 *
 * (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 * written by Marco Boretto <marco.bore@gmail.com>
*/
namespace Longman\TelegramBot\Commands;

use Longman\TelegramBot\Request;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
MBoretto's avatar
MBoretto committed
17 18 19 20

use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
use Longman\TelegramBot\Entities\ForceReply;
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

class KeyboardCommand extends Command
{
    protected $name = 'keyboard';
    protected $description = 'Show a custom keybord with reply markup';
    protected $usage = '/keyboard';
    protected $version = '0.0.5';
    protected $enabled = true;

    public function execute()
    {
        $update = $this->getUpdate();
        $message = $this->getMessage();
        $message_id = $message->getMessageId();

        $chat_id = $message->getChat()->getId();
        $text = $message->getText(true);

        $data = array();
        $data['chat_id'] = $chat_id;
        $data['text'] = 'Press a Button:';
        #$data['reply_to_message_id'] = $message_id;



MBoretto's avatar
MBoretto committed
46 47 48 49
        #Keyboard examples
        $keyboards = array();

        //0
50 51 52 53
        $keyboard[] = ['7','8','9'];
        $keyboard[] = ['4','5','6'];
        $keyboard[] = ['1','2','3'];
        $keyboard[] = [' ','0',' '];
MBoretto's avatar
MBoretto committed
54 55 56 57 58
       
        $keyboards[] = $keyboard;
        unset($keyboard);

        //1
59 60 61 62
        $keyboard[] = ['7','8','9','+'];
        $keyboard[] = ['4','5','6','-'];
        $keyboard[] = ['1','2','3','*'];
        $keyboard[] = [' ','0',' ','/'];
MBoretto's avatar
MBoretto committed
63 64 65 66 67 68

        $keyboards[] = $keyboard;
        unset($keyboard);


        //2
69 70 71
        $keyboard[] = ['A'];
        $keyboard[] = ['B'];
        $keyboard[] = ['C'];
MBoretto's avatar
MBoretto committed
72 73 74 75 76

        $keyboards[] = $keyboard;
        unset($keyboard);


77

MBoretto's avatar
MBoretto committed
78
        //3
79 80 81
        $keyboard[] = ['A'];
        $keyboard[] = ['B'];
        $keyboard[] = ['C','D'];
82

MBoretto's avatar
MBoretto committed
83 84
        $keyboards[] = $keyboard;
        unset($keyboard);
85 86


87 88 89 90 91 92 93 94
        $reply_keyboard_markup = new ReplyKeyboardMarkup(
            [
                'keyboard' => $keyboards[1] ,
                'resize_keyboard' => true,
                'one_time_keyboard' => false,
                'selective' => false
            ]
        );
MBoretto's avatar
MBoretto committed
95
        #echo $json;
96
        $data['reply_markup'] = $reply_keyboard_markup;
97 98 99 100 101

        $result = Request::sendMessage($data);
        return $result;
    }
}