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 ответов

48 просмотров

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?

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

Карта сайта