Answer the question
In order to leave comments, you need to log in
How to handle callback via php in Telegram bot Api?
I use this library - https://github.com/TelegramBot/
There is such a button:
How to send a message to the user if it is pressed?
For example, I want to send "This is a help message" in response to a button click.
For example, a specific code, please. Thanks in advance
With the help of the function
public function on(Closure $event, Closure $checker = null)
{
$this->events->add($event, $checker);
return $this;
}
Answer the question
In order to leave comments, you need to log in
Use the callbackQuery method, something like this:
require_once "vendor/autoload.php";
try {
$bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN');
// or initialize with botan.io tracker api key
// $bot = new \TelegramBot\Api\Client('YOUR_BOT_API_TOKEN', 'YOUR_BOTAN_TRACKER_API_KEY');
$bot->callbackQuery(function ($callbackQuery) use ($bot) {
switch ($callbackQuery->getData()){
case 'help':
$message = 'Help is here!';
break;
default:
$message = 'Hello!';
}
$bot->sendMessage($callbackQuery->getMessage()->getChat()->getId(), $message);
});
$bot->run();
} catch (\TelegramBot\Api\Exception $e) {
$e->getMessage();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question