$data = json_decode(file_get_contents("php://input"), true); $phone = $data['phone']; // 1. buscar contato $stmt = $conn->prepare(" SELECT c.*, cl.* FROM contacts c JOIN clients cl ON cl.id = c.client_id WHERE c.phone = ? LIMIT 1 "); $stmt->execute([$phone]); $contact = $stmt->fetch(); // 2. fallback (cliente desconhecido) if (!$contact) { echo json_encode([ 'agent' => 'default', 'client' => null ]); exit; } // 3. retorna contexto echo json_encode([ 'agent' => 'suporte', 'client_id' => $contact['client_id'], 'client_name' => $contact['name'], 'vector_collection' => $contact['vector_collection'] ]);