Skip to content

Access to the parameters received from Telegram after sending the request in TelegramException class #248

Closed Answered by Lukasss93
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

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

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant