File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 6969 'log_errors ' => [
7070 '500 '
7171 ],
72+
73+ /*
74+ | --------------------------------------------------------------------------
75+ | Rate Limiter max attempts
76+ | --------------------------------------------------------------------------
77+ |
78+ | This option defines the maximum number of attempts to send a message
79+ | to the Telegram Bot API. The default value is 1.
80+ | Telegram log will send one exemplary message per day.
81+ |
82+ */
83+
84+ 'max_attempts ' => 1 ,
85+
86+ /*
87+ | --------------------------------------------------------------------------
88+ | Rate Limiter decay seconds
89+ | --------------------------------------------------------------------------
90+ |
91+ | This option defines the number of seconds to wait before retrying to
92+ | send a message to the Telegram Bot API. The default value is 1 day.
93+ |
94+ */
95+
96+ 'decay_seconds ' => 60 * 60 * 24 ,
7297];
Original file line number Diff line number Diff line change @@ -46,13 +46,16 @@ public function setChatId(string $chatId): self
4646 protected function rateLimiter ($ message ): bool
4747 {
4848 $ key = md5 ('telegram_logger ' . $ message );
49+ $ decaySeconds = config ('telegram-logger.decay_seconds ' , 60 * 60 * 24 );
50+ $ maxAttempts = config ('telegram-logger.max_attempts ' , 1 );
4951
50- if (RateLimiter::tooManyAttempts ($ key , 5 )) {
52+ if (RateLimiter::tooManyAttempts ($ key , $ maxAttempts )) {
5153 info ('Telegram rate limit exceeded ' );
54+
5255 return false ;
5356 }
5457
55- RateLimiter::hit ($ key );
58+ RateLimiter::hit ($ key, $ decaySeconds );
5659
5760 return true ;
5861 }
You can’t perform that action at this time.
0 commit comments