TelegramBot / Api

Native PHP Wrapper for Telegram BOT API
MIT License
1.06k stars 324 forks source link

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

Open kison30 opened 2 years ago

kison30 commented 2 years ago

image

muhammadmp97 commented 1 year ago

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.

peektoseen commented 7 months ago

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