0

I've created a bot in PHP in Telegram where I've 2 buttons inline. I receive right the click but after how I can send back another message? With the code below I can send a message but it doesn't work in this case.

$content = file_get_contents("php://input");
$update = json_decode($content, true);
if(!$update) {
  exit;
}

header("Content-Type: application/json");
$chatId = isset($message['chat']['id']) ? $message['chat']['id'] : "";
$callback_query = isset($update['callback_query']) ? $update['callback_query'] : "";
if($callback_query["data"]=='1'){
    $parameters = array('chat_id' => $chatId, "text" => '1');
    $parameters["method"] = "sendMessage"; 
    echo json_encode($parameters);
    exit; 
} 
Matteo Enna
  • 1,285
  • 1
  • 15
  • 36

2 Answers2

1

You must call answerCallbackQuery method!

Pay attention to this part of Telegram Bot API:

NOTE: After the user presses an inline button, Telegram clients will display a progress bar until you call answerCallbackQuery. It is, therefore, necessary to react by calling answerCallbackQuery even if no notification to the user is needed (e.g., without specifying any of the optional parameters).

hamed.p90
  • 11
  • 2
0

The easiest way is:

$sendto =API_URL."sendmessage?chat_id=".$parameters['chatID']."&text=".urlencode("Your message");
file_get_contents($sendto);
Matteo Enna
  • 1,285
  • 1
  • 15
  • 36