chatId(); $userId = $bot->userId(); if ($chatId === null || $userId === null) { 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)) { SafeLog::channel('telegram')->info('telegram GroupAdminOnly: rejected non-group chat', [ 'chat_id' => $chatId, 'type' => $typeValue, ]); return null; } try { $member = $bot->getChatMember($chatId, $userId); } catch (\Throwable $e) { SafeLog::channel('telegram')->warning('telegram GroupAdminOnly: getChatMember failed', [ 'chat_id' => $chatId, 'user_id' => $userId, 'error' => $e->getMessage(), ]); $bot->sendMessage('⛔ Unable to verify admin status.'); return null; } $status = $member?->status; $statusValue = $status instanceof ChatMemberStatus ? $status->value : (string) $status; $ok = in_array($statusValue, [ ChatMemberStatus::CREATOR->value, ChatMemberStatus::ADMINISTRATOR->value, 'creator', 'administrator', ], true); if (! $ok) { $bot->sendMessage('⛔ Only group admins can use this command.'); return null; } return $next($bot); } }