Really no one knows how to droup updates?? All of this

not working
"pending_update_count":11
Look like my scrips can't send http post if status >=500 something wrong here

14 ответов

21 просмотр

You are already dropping the pending updates. But it surely doesn't do anything in your first if (line 18) since $http_status is not defined there, so that expression will always be evaluated as false. It's not an API issue, is a logic issue.

is that the full file, or just pieces of it. It looks like just pieces of it...

ッ Marshmallow 🎀 ❦ ᵐⁱˢˢ Σ ᶜᵒˡˡᵉᵍⁱᵃⁿ ᵃⁿᵈ ᵍᵃᵐᵉʳ 👱🏻‍♀ 🦋²⁰²²ᵗʰ 🎀 🧞‍♀️×͜×
screenshot I edit it also there's error

Good. Now with that error message you can debug your application, because your file is incomplete that it wouldn't be able to execute at all as is.

There are several errors in your code: 1. Replace register_shutdown_function(function() { to register_shutdown_function(function() use($token, $chat_id) {. 2. As far as I understand fastcgi_finish_request() closes the connection. So if you use php as fastcgi it won't work with register_shutdown_function, because since the connection is closed, http_response_code won't be able to change the http code. 3. You don't need sleep(10); because file_get_contents waits until the request is done. 4. Remove all unnecessary /setWebhook requests. I don't know what part of the project your HTTP.php file is. if HTTP.php is the entrypoint (i.e. registered as webhook) then HTTP.php should look like: <?php ini_set('display_errors', 0); define('API_URL', 'https://api.telegram.org/bot'); $token = "123456:etc"; $update = json_decode(file_get_contents('php://input'), true); $chat_id = $update['message']['chat']['id'] ?? $update['callback_query']['message']['chat']['id'] ?? ''; register_shutdown_function(function () use($token, $chat_id) { if (http_response_code() != 200 && $chat_id) { http_response_code(200); file_get_contents(API_URL . $token . "/sendMessage?" . http_build_query([ 'chat_id' => $chat_id, 'text' => 'An internal server error has occurred. Please try again later.', ])); } }); $method = '/sendMessage'; $parameters = [ 'chat_id' => $chat_id, 'text' => 'Test message', ]; function exec_curl_request($handle) { $response = curl_exec($handle); if ($response === false) { $errno = curl_errno($handle); $error = curl_error($handle); error_log("Curl returned error $errno: $error\n"); curl_close($handle); return false; } $http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE)); curl_close($handle); if ($http_code != 200) { $response = json_decode($response, true); error_log("Request has failed with error {$response['error_code']}: {$response['description']}\n"); if ($http_code == 401) { throw new Exception('Invalid access token provided'); } return false; } else { $response = json_decode($response, true); if (isset($response['description'])) { error_log("Request was successful: {$response['description']}\n"); } $response = $response['result']; } return $response; } if (!isset($parameters) || !$parameters) { $parameters = array(); } else if (!is_array($parameters)) { error_log("Parameters must be an array\n"); return false; } $handle = curl_init(API_URL . $token . $method); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($handle, CURLOPT_TIMEOUT, 60); curl_setopt($handle, CURLOPT_POST, true); curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($parameters, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8")); exec_curl_request($handle);

Михаил
There are several errors in your code: 1. Replace ...

i'm afraid she left the group but maybe she'll be back soon to see your message

ッ Marshmallow 🎀 ❦ ᵐⁱˢˢ Σ ᶜᵒˡˡᵉᵍⁱᵃⁿ ᵃⁿᵈ ᵍᵃᵐᵉʳ 👱🏻‍♀ 🦋²⁰²²ᵗʰ 🎀 🧞‍♀️×͜×
Yes i put all your codes non of them can drop the ...

I think you can't drop the updates by requesting setWebhook?drop_pending_updated=true from the php script returns 500, because after setWebhook request the script will return 500 and will create a new pending update. You should make sure the http request returns 200 when php error. Maybe my code with http_response_code not works on your environment. I tested it on apache+mod_php but your environment might use apache+php-fpm, nginx+php-fpm, etc. Try to execute only this code on your environment: <?php ini_set('display_errors', 0); http_response_code(400); register_shutdown_function(function() { http_response_code(200); }); throw new \Exception('Error'); Request it in browser/curl/etc. What http response code do you see?

What means "when the bot is inactive"? Do you want to drop pending updates manually? If yes, execute in the Terminal (if mac or linux): curl 'https://api.telegram.org/bot<TOKEN>/setWebhook' -d '{"url": "https://Name-Heroku-App.herokuapp.com/bot.php", "drop_pending_updates": true}' Or execute in php console manually: file_get_contents("https://api.telegram.org/bot<TOKEN>/setWebhook?url=" . urlencode('https://Name-Heroku-App.herokuapp.com/bot.php') . "&drop_pending_updates=true"); If you want to drop pending updates periodically, add this script execution to cron timer.

In this code if i turn off the Dyno the bot will send hello word right?

ッ Marshmallow 🎀 ❦ ᵐⁱˢˢ Σ ᶜᵒˡˡᵉᵍⁱᵃⁿ ᵃⁿᵈ ᵍᵃᵐᵉʳ 👱🏻‍♀ 🦋²⁰²²ᵗʰ 🎀 🧞‍♀️×͜×
In this code if i turn off the Dyno the bot will s...

I don't know what is Dyno. Now script sends error message. If you remove syntax error from "handler.php" (see the comment in the file) then it will send "Hello!" message.

Михаил
What means "when the bot is inactive"? Do you want...

isnt it easier to implement manual update dropping in code than f*cking with manual api requests each time?

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

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

есть спецы по гитлабу? нужно решить проблему того, что гитлаб не показывает файлы с расширением txt в артефактах и предлагает их скачать и смотреть локально. а это неудобно. в...
Aleksandr Druzhinin
1
Эх кто-то пришел и весь праздник испортил :( 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
Здравствуйте. Есть спецы на языке 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
а у нас кто-нибудь разбирается в матлаб? Накопал статью по замощению Фодерберга, о нём вообще мало инфы в сети. Но там матлабовский код, который нужно через песочницу по сути ...
Constantin_FV
1
string xczhojoxueaflfhhygcc ="xczhojoxueaflfhhygcc"; long xczhojoxueaflfhhygcc_2 =1368962155; import std.conv: text; writeln(text(xczhojoxueaflfhhygcc, " ", xczhojoxueaflfhhyg...
Constantin_FV
6
Карта сайта