0

I have this code :

<?php

$update = json_decode(file_get_contents('php://input'), TRUE);

$botToken = "*****";
$botAPI = "https://api.telegram.org/bot" . $botToken;

// Check if callback is set
if (isset($update['callback_query'])) {

    // Reply with callback_query data
    $data = http_build_query([
        'text' => 'Selected language: ' . $update['callback_query']['data'],
        'chat_id' => $update['callback_query']['from']['id']
    ]);
    $url = $botAPI . "/sendMessage?{$data}";

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);
    curl_close($curl);
}

// Check for normal command
$msg = $update['message']['text'];
if ($msg === "/start") {

    // Create keyboard
    $data = http_build_query([
        'text' => 'Please select language:',
        'chat_id' => $update['message']['from']['id']
    ]);
    $keyboard = json_encode([
        "inline_keyboard" => [
            [
                [
                    "text" => "english",
                    "callback_data" => "english"
                ],
                [
                    "text" => "russian",
                    "callback_data" => "russian"
                ]
            ]
        ]
    ]);

    // Send keyboard
    $url = $botAPI . "/sendMessage?{$data}&reply_markup={$keyboard}";

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);
    curl_close($curl);
}

?>

It works as I expected, in terms of showing menu and replying message.

But, there's something annoying to me: it keeps showing a loading icon and in few minutes later, there's a message that shows 'not responding'.

How can I remove this loading icon to prevent the 'not responding' message?

Thank you.

enter image description here

0stone0
  • 34,288
  • 4
  • 39
  • 64
Saint Robson
  • 5,475
  • 18
  • 71
  • 118

1 Answers1

0

The loading icon is there until you let Telegram know you've handled the Button press.

Option 1, Remove the keyboard

If it's a single use button, removing the keyboard will (ofc) also remove the loading button

Option 2, Call CallbackQuery

If the button can be pressed multiple times, send a CallbackQuery (or getUpdates with an offset)

0stone0
  • 34,288
  • 4
  • 39
  • 64