Skip to content
Johan Peña

Published · 3 min read

A checkbox that leaves a receipt

TuPatriSeguro's contact form does not send an email. It opens WhatsApp with a message already written. Under Colombian data-protection rules the business has to be able to show that a person authorized the use of their data, and a ticked checkbox in someone's browser proves nothing once the page is closed. The question was what to store so that, months later, a conversation could be matched to a record of what that person accepted.

What a record has to answer

Who accepted, what they accepted, which version of each document, when, and from where. The last two matter because documents change: “accepted the privacy policy” is meaningless if the policy has been rewritten since.

So the table keeps the version of every document next to the acceptance, plus the page, IP address and browser of the request. Cookie choices go in the same table with a different type.

TuPatriSeguro · lib/db/schema.ts
export const consentimientos = pgTable("consentimientos", {
  id: uuid("id").primaryKey().defaultRandom(),
  /** Código corto que ve la persona y que viaja en su mensaje de WhatsApp. */
  referencia: text("referencia").notNull().unique(),
  tipo: text("tipo").notNull(), // "formulario_contacto" | "cookies"
  nombre: text("nombre"),
  aceptaTerminos: boolean("acepta_terminos").notNull().default(false),
  versionTerminos: text("version_terminos"),
  aceptaPrivacidad: boolean("acepta_privacidad").notNull().default(false),
  versionPrivacidad: text("version_privacidad"),
  cookies: jsonb("cookies").$type<{ necesarias: true; preferencias: boolean; terceros: boolean }>(),
  versionCookies: text("version_cookies"),
  pagina: text("pagina"),
  ip: text("ip"),
  userAgent: text("user_agent"),
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
});

Nothing in the code updates or deletes a row. A visitor who changes their cookie preferences produces a new record, so the log shows what was true at each moment instead of only the latest state.

The server decides what was accepted

The browser sends a reference, a name, the page and two booleans. It does not send document versions: those are read on the server from the same file that renders the legal pages. A request that does not accept both documents, or whose reference is not in the expected format, is rejected without writing anything.

TuPatriSeguro · lib/consentimiento/acciones.ts
if (!REFERENCIA_VALIDA.test(entrada.referencia)) return { ok: false };
if (entrada.aceptaTerminos !== true || entrada.aceptaPrivacidad !== true) return { ok: false };

await crearConsentimiento({
  referencia: entrada.referencia,
  tipo: "formulario_contacto",
  nombre: recortar(entrada.nombre, 120),
  aceptaTerminos: true,
  versionTerminos: legal.documentos.terminos.version,
  aceptaPrivacidad: true,
  versionPrivacidad: legal.documentos.privacidad.version,
  pagina: recortar(entrada.pagina, 300),
  ...(await contextoSolicitud()),
});

The name and page are trimmed to a maximum length, and the IP and browser come from the request headers, not from the form.

A reference that travels with the message

The conversation happens in WhatsApp, outside the site. To connect the two, the browser generates a short code — TPS- followed by eight characters from an alphabet without look-alike letters — and that code is both stored with the record and written at the end of the message, next to the versions accepted.

There is a constraint in the way. Browsers only allow a new window inside the user's click; if the code waits for the server, WhatsApp is blocked as a pop-up. So the record is sent without waiting and the window opens immediately.

TuPatriSeguro · components/sections/Contacto.tsx
const referencia = nuevaReferencia();
// Se registra sin esperar: WhatsApp debe abrirse dentro del mismo clic
// (si no, el navegador lo bloquea como ventana emergente).
void registrarConsentimientoFormulario({
  referencia, nombre, aceptaTerminos, aceptaPrivacidad,
  pagina: location.pathname,
});
// ...
window.open(linkWhatsappGeneral(texto), "_blank", "noopener,noreferrer");

That is a trade-off, not a free win. If the write fails, the message still opens and carries a reference with no row behind it. The server logs the failure, and a missing reference is visible when someone looks it up, but the record is not guaranteed.

Exporting without opening a hole

The panel lists, filters and searches the records, and downloads them as CSV for whoever needs to answer a request. The export checks the admin session itself instead of relying on the page that links to it.

Visitors type their own name, and the file will be opened in a spreadsheet. A value that starts with =, +, - or @ can run as a formula there, so every cell is quoted and those values get a leading apostrophe. The file also starts with a byte-order mark, so Excel reads the accents correctly.

TuPatriSeguro · app/admin/consentimientos/exportar/route.ts
function celda(valor: unknown): string {
  const texto = valor === null || valor === undefined ? "" : String(valor);
  // Evita inyección de fórmulas en Excel y escapa comillas.
  const seguro = /^[=+\-@]/.test(texto) ? `'${texto}` : texto;
  return `"${seguro.replace(/"/g, '""')}"`;
}

What this does not do

  • It is evidence of what the site recorded, not legal advice; the documents' content still has to be right.
  • A record can be missing if the background write fails, as described above.
  • There is no automated test around the flow yet.

← All writing