Files
coruna-lab/app/Telegram/Middleware/AuthorizedChat.php
T
hashbro 74a67c3900 init
2026-08-08 05:09:01 +08:00

32 lines
765 B
PHP

<?php
namespace App\Telegram\Middleware;
use Illuminate\Support\Facades\Log;
use SergiX44\Nutgram\Nutgram;
class AuthorizedChat
{
public function __invoke(Nutgram $bot, callable $next): mixed
{
$expected = (string) config('coruna.telegram.owner_chat_id', '');
if ($expected === '') {
Log::warning('telegram AuthorizedChat: TELEGRAM_OWNER_CHAT_ID empty');
return null;
}
$chatId = $bot->chatId();
if ($chatId === null || (string) $chatId !== $expected) {
Log::info('telegram AuthorizedChat: chat rejected', [
'chat_id' => $chatId,
'expected' => $expected,
]);
return null;
}
return $next($bot);
}
}