I have been suffering for quite a long time, I decided to register here. To the point. I use the library Telegram Bot PHP SDK. Here are the code snippets.

<?php include('vendor/autoload.php'); //Подключаем библиотеку use Telegram\Bot\Api; $telegram = new Api('ххх'); //Устанавливаем токен, полученный у BotFather $updates = $telegram->getWebhookUpdates(); //Передаем в переменную $updates полную информацию о сообщении пользователя $text = $updates["message"]["text"]; //Текст сообщения $chat_id = $updates["message"]["chat"]["id"]; //Уникальный идентификатор пользователя $name = $updates["message"]["from"]["username"]; //Юзернейм пользователя $callback_query = $updates['callback_query']; $data = $callback_query['data']; ... }elseif ($text == "Work plz") { require('keyboard.php'); $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => "Test", 'reply_markup' => $replyMarkup1 ]); if ($data == "1") { $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => "1" ]); } else { $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => "2" ]);} 

keyboard.php

 <?php // Inline keyboard #1 $inline_button0 = array("text"=>"0","callback_data"=>"1"); $inline_button1 = array("text"=>"1","callback_data"=>'/2'); $inline_button1 = array("text"=>"2","callback_data"=>'/3'); $inline_keyboard = [[ $inline_button0,$inline_button1,$inline_button2], ]; $keyboard1=array("inline_keyboard"=>$inline_keyboard); $replyMarkup1 = json_encode($keyboard1); ?> 

She principle (like everything else) is working properly. I can responsibly say that I reviewed all the topics here, and even went to the second page of Google. What could be wrong here, xs. The version is not dev, I tried to install it, so the code stopped working at all, did how it was -> How to handle pressing the bot's keyboard button created on the Telegram Bot API - PHP SDK? sense - 0.

  • and what error? what's wrong? - n.osennij
  • there is no mistake, just nothing happens. And if you take the code in this case, then always after the message with the inline there will be a two (which means that fucking does not work (it appears before I press the inline button itself)) - AndrewKO322
  • @ n.osennij so what. Can you help me? - AndrewKO322
  • I? not. I did not say that I can - n.osennij

1 answer 1

If anyone needs it, that's how I decided it. (I still updated to the dev version, also included @botfather inline mode) Kod:

 $inline_id = $updates["callback_query"]["message"]["chat"]["id"]; $data = $updates["callback_query"]["data"]; if (isset($data)) { $telegram->sendMessage([ 'chat_id' => $inline_id, 'text' => "Test" ]); }