telegram-bot-sdk icon indicating copy to clipboard operation
telegram-bot-sdk copied to clipboard

callback not working with version 3.4

Open chansovann opened this issue 2 years ago • 2 comments

I have try many day for fix callback function but still not working. It show nothing when I click on inline keyboard. I have use all this in my custom command handle.

use Telegram;
use Telegram\Bot\Commands\Command;
use Telegram\Bot\Keyboard\Keyboard;
use Telegram\Bot\Objects\Update;

this is my handle function

public function handle()
    {
		$update = $this->telegram->getWebhookUpdate();
        if ($update->isType('callback_query')) {
            $this->telegram->sendMessage([
                'chat_id' => "123456",
                'parse_mode' => 'HTML',
                'text' => 'ddd',
            ]);
        } else {
            $keyboard = json_encode([
		"inline_keyboard" => [
			[
				[
					"text" => "english",
					"callback_data" => "/english"
				],
				[
					"text" => "russian",
					"callback_data" => "/russian"
				]
			]
		]
	]);

            $this->telegram->sendMessage([
                'chat_id' => $update->getMessage()->chat->id,
                'text' => 'Text with inline button',
                'reply_markup' => $keyboard
            ]);
        }
}

image Thank for help me

chansovann avatar Jun 09 '22 03:06 chansovann

Hello, friend! It is possible that you have already solved the problem, but if not, I will answer you: I see the problem in several places. If we talk about your question, you do not have a handler function for callback_query data, therefore the buttons do not work the way you want.

I think your approach for creating a keyboard is wrong within the framework (you can do it much easier). To create a keyboard, refer to the Keyboard(::make) class. After you have already initiated the creation of the object, create an instance of the inline button via object->row(Keyboard::inline()). After you create the buttons, you will need a handler for callback calls. Describe it, and, based on the information in callback_query, call the functionality you need. An example of creating a keyboard is shown in the screenshot. image

Areizewei avatar Jul 31 '22 10:07 Areizewei

"After you create the buttons, you will need a handler for callback calls. Describe it, and, based on the information in callback_query, call the functionality you need."

Hello, friend!

Tell me how to write a handler for a callback. Thanks!

IggorGor avatar Sep 14 '22 08:09 IggorGor