requests if the bot is not working?
Also another one for avoiding flood by someone
Drop pending requests: <?php file_get_contents('https://api.telegram.org/bot<token>/setWebhook?url=<you_url>&drop_pending_updates=true');
When this code works?
When you execute this code manually
Can you explain more? When a bot contains a bug, the bot receives the request but answers when I fix the bug Where should I put this at the end of the script?
no, I assumed you needed a way to reset webhooks updates after a long shutdown of the bot. Could you describe your problem in more detail?
If there is a bug in the script, the bot does not respond to users but receives requests when they send something means if someone send 10 times command /start The webhook will receive a 10 pending requests When I fix the error in script the bot will responds to the user 10 times I want to automatically drop these requests when the bot does not respond, what should I do?
If the script is prone to errors and is slowed, you can check pending updates regularly or by a polling method,and if it exceeds certain amount you reset that to zero.(0)
Updates (requests) are pending when your script responds to telegram not with 200 http code. So you can try to do something like this in the beginning of the php script: <?php register_shutdown_function(function() { if(http_response_code() != 200) { http_response_code(200); file_get_contents('https://api.telegram.org/bot<token>/sendMessage?' . http_build_query([ 'chat_id' => '<chat id from update request>', 'text' => 'An internal server error has occurred. Please try again later.', ])); } });
Not working
Also you should drop the current pending updates.
If you don't want to send the "An internal server error has occurred. Please try again later." message to user you can use: <?php register_shutdown_function(function() { http_response_code(200); });
Also ensure the ini directive display_errors is 0 (or use ini_set('display_errors', 0); in the beginning of the php script) and the script has no output from print, echo, etc. (because http_response_code doesn't work after some output).
Sorry nothing works fine always there's pending updates Thanks for your time
You could try to debug webserver response http code
Обсуждают сегодня