-
Hi I have coding some scripts for cronjobs.... and i need to access the error params returned by Telegram here... for example there is an error code 429 which is related to floodwait and the response contain How can i access to that ?
|
Beta Was this translation helpful? Give feedback.
Answered by
Lukasss93
Nov 13, 2022
Replies: 1 comment
-
Hi! Try this: class TelegramTooManyRequestsException extends TelegramException
{
protected int $retryAfter;
public function __construct($message, int $retryAfter = 0)
{
$this->retryAfter = $retryAfter;
parent::__construct($message, 0, null);
}
public function getRetryAfter(): int
{
return $this->retryAfter;
}
} $bot->onApiError('.*Too Many Requests.*',function(Nutgram $bot, TelegramException $e){
$message = $e->getMessage();
$retryAfter = 0;
if (preg_match('/retry after (\d+)/', $message, $matches)) {
$retryAfter = (int)$matches[1];
}
throw new TelegramTooManyRequestsException($message, $retryAfter);
}); // your code
try {
foreach (range(1, 300) as $i) {
$bot->sendMessage("Message $i");
}
} catch (TelegramTooManyRequestsException $e) {
$retryAfter = $e->getRetryAfter();
//do something
} In the next update we will implement $bot->onApiError('.*Too Many Requests.*', function(Nutgram $bot, TelegramException $e){
$parameters = $e->getParameters();
throw new YourTooManyRequestsException($e->getMessage(), $parameters['retry_after']);
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! Try this:
// …