E
E
Evgeniy V.2019-08-07 07:34:52
PHP
Evgeniy V., 2019-08-07 07:34:52

Why callback comes several times in telegram bot?

if (!empty($result['callback_query'])) {
    $chat_id = $result['callback_query']['from']['id']; 
    $callback_id = $result['callback_query']['id'];
    //file_get_contents("https://api.telegram.org/bot".$token."/answerCallbackQuery?callback_query_id=".$callback_id);
    
    $website="https://api.telegram.org/bot".$token;

    $params=[
      'callback_query_id'=>$callback_id,
      'text'=>'test',
    ];
    $ch = curl_init($website . '/answerCallbackQuery');
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $result_q = curl_exec($ch);
    curl_close($ch);
    
    $telegram->sendMessage([
      'chat_id' => $chat_id,
      'text' => "Here is the callback ". $result_q
    ]); 
  }

5d4a54cf572e4408402501.jpeg
Why does it come several times in a row, like I return answerCallbackQuery and should only work once?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur, 2019-08-07
@ar2rsoft

Maybe before that they sent messages, the callback did not accept them and now they reach?
The message queue can be viewed in getWebhooks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question