Answer the question
In order to leave comments, you need to log in
Inline buttons in Telegram - Callback?
Hello!
It is necessary to arrange a handler for clicking on inline buttons in Telegram, which does not quite work out ...
The scenario is as follows: the user clicks on the predefined command "/stop", and the bot answers with the question "Are you sure?" and displays two options: "Yes" and "No". If you click on "Yes" - then you need to intercept this command and perform a certain action on the server.
My code:
require_once('TelegramUserBot.php');
$api = new TelegramUserBot();
$api->token = '433336723:AAF*******************';
$updates = json_decode(file_get_contents('php://input') ,true);
$chat_id = $updates['message']['chat']['id'];
$callback_query = $updates['callback_query'];
$data = $callback_query['data'];
if($updates['update_id']) {
switch($updates['message']['text']) {
case '/stop':
//disable notifications for this user
$inline_button1 = array("text"=>"Да","callback_data"=>'/stop-confirm');
$inline_button2 = array("text"=>"Нет","callback_data"=>'/stop-continue');
$inline_keyboard = ;
$keyboard=array("inline_keyboard"=>$inline_keyboard);
$api->sendMessage($chat_id, "Вы уверены?", json_encode($keyboard));
break;
default:
$api->sendMessage($chat_id, "Команда \"".$updates['message']['text']."\" не найдена");
break;
if($updates['message']['text'] == '/stop-confirm') {
$api->sendMessage($chat_id, "Вы ответили подтверждением");
//TODO - disable notifications
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question