I want to get callback data from response but array is empty.
I am trying to show in message callback_data
array.
Here is my code:
$botToken = "token";
$botAPI = "https://api.telegram.org/bot" . $botToken;
$update = json_decode(file_get_contents('php://input'), TRUE);
$message = $update["message"]["text"]
$chatId = $update["message"]["chat"]["id"];
$callback_query = $update['callback_query'];
$callback_query_data = $callback_query['data'];
$url = $botAPI . '/sendMessage?chat_id=' . $chatId . '&text=';
if(isset($callback_query)){
file_get_contents($url . $callback_query_data);
}
if($message == "/start"){
$parameters = array('chat_id' => $chatId, "text" => "Здравствуйте. Выберите язык. \nАссалом. Забонро интихоб кунед.\nHi! Select your language.");
$parameters["method"] = "sendMessage";
$keyboard = ['inline_keyboard' => [[
['text' => "🇹🇯Точики", 'callback_data' => 'tajik'],
['text' => "🇷🇺Русский", 'callback_data' => 'russian'],
['text' => '🇺🇸English', 'callback_data' => 'english']
]]];
$parameters["reply_markup"] = json_encode($keyboard, true);
echo json_encode($parameters);
}
if(isset($callback_query))
makes zero sense the way you are using it. Of course that variable is always set at this point - you yourself did that four lines further up the code. – Biafraif($message == "/start")
– what is$message
, where is that supposed to magically come from? – Biafra$message = $update["message"]["text"]
. So how to printcallback_query
? – Trouper$update['callback_query']
will be set or not, in the data you receive from the outside - well then you need to check on that, and not something compeltely different. – Biafra$update['callback_query]
, am I right? – Trouper