context->expectedChatId(); if ($expected === '') { Log::warning('telegram AuthorizedChat: chat id empty', [ 'agent_id' => $this->context->agent()?->id, ]); return null; } $chatId = $bot->chatId(); if ($chatId === null || (string) $chatId !== $expected) { Log::info('telegram AuthorizedChat: chat rejected', [ 'chat_id' => $chatId, 'expected' => $expected, 'agent_id' => $this->context->agent()?->id, ]); return null; } $type = $bot->chat()?->type; $typeValue = $type instanceof ChatType ? $type->value : (string) $type; if (! in_array($typeValue, [ChatType::GROUP->value, ChatType::SUPERGROUP->value, 'group', 'supergroup'], true)) { Log::info('telegram AuthorizedChat: not a group chat', [ 'chat_id' => $chatId, 'type' => $typeValue, ]); return null; } return $next($bot); } }