2

im developing telegram bot using codeigniter + PHP to respond to user request, and since this morning, its stop working, and pending_update_count : 210 and increasing ...
my question is how we can clear the pending count ?

what have i try :
1. unset the webhook and set it again => this doesnt work, pending_update_count still hasn't cleared
2. using controller that didnt do anything(look my code below) => this also doesnt work, pending_update_count still hasn't cleared

and this is my code that doesnt do anything

class index extends CI_Controller {

function __construct() {
    parent::__construct();

}

public function index() {
    echo('halooo');
    $result = 'ok';
    return $result;
}
}

and this how i usually process the message from telegram bot

class index extends CI_Controller {

function __construct() {
    parent::__construct();

}

public function index() {
    $content = file_get_contents("php://input");
    $update = json_decode($content, true);
    $chatID = $update["message"]["from"]["id"];     

    $strcmd = trim($update["message"]["text"]);     

    $strMsg = $this->process($strcmd); //process

    $sendto =API_URL."sendmessage?chat_id=".$chatID."&sendmessage?text=".$strMsg."";
    file_get_contents($sendto);
}   
}           

i look these question in stackoverflow, but didnt help :
1. Clear "pending_update_count" in Telegram Bot
2. clear pending_update_count in Telegram Bot

Ivan
  • 96
  • 2
  • 8
  • I would not name your controller index because you all ready have index function –  May 11 '18 at 04:30
  • @Mr.ED, thank you for your reply, i have changing controller's name and method's name and then unset webhook and set it again using new controller's, but unfortunately its not working .... – Ivan May 11 '18 at 04:51

1 Answers1

0

ok, i have succeed to solve my problem, and i will post it here in case someone need it ...
before i post my solution, there is something strange about this problem,
usually if pending_update_count > 0, it means somethings wrong with our source code,
we have bug somewhere that have been triggered by something in our source code ...

and telegram bot will process it and since it's error,
our PHP unable to return status ok (200) to telegram,
so telegram will send it again and again and again ... as if we have endless loops...
and from there we know what command that trigger the error and we can trace our source code and fix it,
and meanwhile for pending_update_count(if you have to make it become 0 fast), usually, we can solve it by using PHP that didnt do anything,
or you can try by returning status ok (200), using this command => http_response_code(200),
and dont forget to trace and fix your source code to make the same bug is not happen again;

but this time, it didnt have behave like that, telegram bot just quiet,
it didnt send the same message/command that will cause our source code to be error as usually it behave.
its as if, our source code didnt receive update from telegram bot.
and using php that didnt do anything is also not working ...

and this is how i solve it (coincidentally)
so i try to solve it by revoke my bot(run /revoke in bot father) and get new token,
and i update all my source code using new token, set the webhook again,
and using PHP that didnt do anything and suddenly i see drop in pending_update_count value ...
and for the error that cause this, i still cant find the problem ...

so, thats my solution, hope this can help someone ...

Ivan
  • 96
  • 2
  • 8