In php without library Is there a code to drop webhook

requests if the bot is not working?
Also another one for avoiding flood by someone

14 ответов

5 просмотров

Drop pending requests: <?php file_get_contents('https://api.telegram.org/bot<token>/setWebhook?url=<you_url>&drop_pending_updates=true');

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?

ッ Marshmallow 🎀 ❦ ᵐⁱˢˢ Σ ᶜᵒˡˡᵉᵍⁱᵃⁿ ᵃⁿᵈ ᵍᵃᵐᵉʳ 👱🏻‍♀ 🦋²⁰²²ᵗʰ 🎀 🧞‍♀️×͜×
Can you explain more? When a bot contains a bug, t...

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?

ッ Marshmallow 🎀 ❦ ᵐⁱˢˢ Σ ᶜᵒˡˡᵉᵍⁱᵃⁿ ᵃⁿᵈ ᵍᵃᵐᵉʳ 👱🏻‍♀ 🦋²⁰²²ᵗʰ 🎀 🧞‍♀️×͜×
If there is a bug in the script, the bot does not ...

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.', ])); } });

ッ Marshmallow 🎀 ❦ ᵐⁱˢˢ Σ ᶜᵒˡˡᵉᵍⁱᵃⁿ ᵃⁿᵈ ᵍᵃᵐᵉʳ 👱🏻‍♀ 🦋²⁰²²ᵗʰ 🎀 🧞‍♀️×͜×
Not working

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); });

ッ Marshmallow 🎀 ❦ ᵐⁱˢˢ Σ ᶜᵒˡˡᵉᵍⁱᵃⁿ ᵃⁿᵈ ᵍᵃᵐᵉʳ 👱🏻‍♀ 🦋²⁰²²ᵗʰ 🎀 🧞‍♀️×͜×
Not working

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).

Похожие вопросы

Обсуждают сегодня

Кстати @darkhole1 для rich telegram app с поддержкой транзакций p2p через ton - какой язык считается с самой хорошей поддержкой?
Serg Gini
3
Эх кто-то пришел и весь праздник испортил :( You need complex FBX scene importing setup to change things on import? good luck with that. You need navigation and pathfinding? g...
Serg Gini
5
есть спецы по гитлабу? нужно решить проблему того, что гитлаб не показывает файлы с расширением txt в артефактах и предлагает их скачать и смотреть локально. а это неудобно. в...
Aleksandr Druzhinin
1
Здравствуйте. Есть спецы на языке D ? Есть проект (торговый бот) нужна долгосрочная поддержка на материальной основе) (достойная оплата) Подробности в лс.
6h123 6h123
1
как работают все эти прокси онлайн, где ты можешь ввести сайт и он зайдет на сайт от своего имени?
Aleksandr Druzhinin
1
День добрый. Стандартная библиотека phobos (std.array) ссылается на внешнюю фунцию _d_newarrayUTrace и при сборке с ключом profile-gc эта ссылка остаётся неопределённой. Никак...
slacker linuxoid
5
на D можно построить абсолютно разный архитект, как объектный, так и нет, оч широкий простор для принятия решений. Однако проблема в том, что большинство книг об айтишной архи...
Constantin_FV
1
Доброго времени суток. Сейчас я работаю над своей архитектурой Component / Systems. Если просто, это то что использовали до дробления на ECS. Потому что ECS это все таки нишев...
Vi
26
Для меня наследование это просто удобство ради удобства. Без множественного наследования, это бесполезная вещь, но удобная. С множественным наследованием, это опасная, но мощн...
Vi
1
string xczhojoxueaflfhhygcc ="xczhojoxueaflfhhygcc"; long xczhojoxueaflfhhygcc_2 =1368962155; import std.conv: text; writeln(text(xczhojoxueaflfhhygcc, " ", xczhojoxueaflfhhyg...
Constantin_FV
6
Карта сайта