Api icon indicating copy to clipboard operation
Api copied to clipboard

Uncaught Error: Call to undefined method TelegramBot\Api\Types\Inline\InlineKeyboardMarkup::toJson()

Open kison30 opened this issue 4 years ago • 2 comments

image

kison30 avatar Jan 06 '22 03:01 kison30

I think you have to put the whole array in another array. EDIT: This is so weird, because this class extends the BaseType class that already has a toJson() method.

muhammadmp97 avatar Jul 21 '22 18:07 muhammadmp97

I think you have to put the whole array in another array. EDIT: This is so weird, because this class extends the BaseType class that already has a toJson() method.

Same error. I try code from answer, but no result.

Whole code:

<?php require_once "vendor/autoload.php";

try {

    $bot = new \TelegramBot\Api\Client('TOKEN_HERE');

    $inlineKeyboard =[ [
        [
            'text' => 'a',
            'callback_data' => '1',
        ],
        [
            'text' => 'b',
            'callback_data' => '2'
        ]
    ]];

    $keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup($inlineKeyboard);

    $bot->sendMessage(92473368, 'test', null, false, null, $keyboard);

} catch (\TelegramBot\Api\Exception $e) {
    $e->getMessage();
}

And error:

root@d57baf0087f0:/var/www/html# php telegram.php 
[07-Dec-2023 19:49:20 Europe/Moscow] PHP Fatal error:  Uncaught Error: Call to undefined method TelegramBot\Api\Types\Inline\InlineKeyboardMarkup::toJson() in /var/www/html/vendor/telegram-bot/api/src/BotApi.php:325
Stack trace:
#0 [internal function]: TelegramBot\Api\BotApi->sendMessage(92473368, 'test', NULL, false, NULL, Object(TelegramBot\Api\Types\Inline\InlineKeyboardMarkup))
#1 /var/www/html/vendor/telegram-bot/api/src/Client.php(405): call_user_func_array(Array, Array)
#2 /var/www/html/telegram.php(20): TelegramBot\Api\Client->__call('sendMessage', Array)
#3 {main}
  thrown in /var/www/html/vendor/telegram-bot/api/src/BotApi.php on line 325

Fatal error: Uncaught Error: Call to undefined method TelegramBot\Api\Types\Inline\InlineKeyboardMarkup::toJson() in /var/www/html/vendor/telegram-bot/api/src/BotApi.php:325
Stack trace:
#0 [internal function]: TelegramBot\Api\BotApi->sendMessage(92473368, 'test', NULL, false, NULL, Object(TelegramBot\Api\Types\Inline\InlineKeyboardMarkup))
#1 /var/www/html/vendor/telegram-bot/api/src/Client.php(405): call_user_func_array(Array, Array)
#2 /var/www/html/telegram.php(20): TelegramBot\Api\Client->__call('sendMessage', Array)
#3 {main}
  thrown in /var/www/html/vendor/telegram-bot/api/src/BotApi.php on line 325

peektoseen avatar Dec 07 '23 16:12 peektoseen