2

I created a functionality in my bot that allows to ping other computers, when the user pings more than 60 times the bot takes a long time to do it, and I think it does not respond to Telegram with an http 200 code, so Telegram sends it again the ping request and the loop never stops. I used this library to build my bot: https://github.com/Eleirbag89/TelegramBotPHP

The code to do it is very simple:

<?php
$telegram = new Telegram('token');
date_default_timezone_set('America/Bogota');
$chat_id = $telegram->ChatID();
$text = $telegram->Text();
$palabras = explode(" ", $text); 
foreach ($palabras as $key) {
  if (filter_var($key, FILTER_VALIDATE_IP)) {
      $ip = $key;
      $key = "";
  }
  if (is_numeric($key)){
    $cant_paq=$key;
  };
};

if (stristr($text, 'ping') && !empty($ip)) {

    $numero = !empty($cant_paq) ? $cant_paq : 4;
    exec("ping -c $numero $ip", $output, $status);
    foreach ($output as $key) {
      $resultPing .= $key . "\r\n";
    }
    $content = array('chat_id' => $chat_id, 'text' => $resultPing);
    $telegram->sendMessage($content);
}
0stone0
  • 34,288
  • 4
  • 39
  • 64

1 Answers1

0

In the end, I managed to solve it myself, I searched all over the internet and found a clue from someone who had the same problem, adding http_response_code (200) was not enough. Now every time the something goes inside (stristr ($ text, 'ping') &&! empty ($ ip)) I clear the pending messages via drop_pending_updates parameter in the setWebhook method https://core.telegram.org/bots/api#setwebhook

Dhia Djobbi
  • 1,176
  • 2
  • 15
  • 35