# Privacy and LGPD

This page describes how a Herald deployment handles personal data when the email notifier or the
Telegram bot (`herald bot telegram` with `"subscribers": true`) is enabled. The operator of a
Herald instance is the data controller (*controlador*) under Brazil's LGPD (Lei nº 13.709/2018);
adapt this text to your deployment and publish it at the `privacy_url` configured for the email
notifier and the telegram notifier (the bot links it from `/privacy`).

## What is collected

Email subscribers:

| Field | Purpose |
|---|---|
| Email address | Deliver the briefing |
| Language (`pt-BR` / `en`) | Choose the briefing edition |
| `created_at`, `consent_at`, `consent_source` | Record when and where consent was given |
| Token | Confirm and unsubscribe links without exposing the address |
| `unsubscribed_at` | Honor and prove the opt-out |
| `bounced_at` | Stop mailing an address the receiving server permanently refused |

Telegram bot subscribers, one record per chat:

| Field | Purpose |
|---|---|
| `channel`, `chat_id` | Deliver the briefing to that chat |
| Status (`pending` / `active` / `unsubscribed`) | Require the confirmation and honor opt-outs |
| Language (`pt-BR` / `en`) | Choose the briefing edition and the bot's replies |
| Categories followed | Limit the briefing to the sections the subscriber chose (empty = all) |
| `created_at`, `consent_at`, `consent_source` | Record when and where consent was given |
| `unsubscribed_at` | Honor and prove the opt-out |

The bot does not store names, usernames, phone numbers or messages. It only reads messages that
are bot commands sent to it in a private chat; any other message, and anything in groups, is
skipped unread. The Telegram `language_code` is used once, to pick the reply language, and is
not stored. The update offset kept in `herald.db` is a counter, not personal data.

Herald does not use tracking pixels, click tracking, or third-party analytics. Slack, Discord, Matrix,
Teams, Google Chat, webhook and the Telegram `chat_id` delivery go to channels the operator controls and store no
subscriber data.
Push notifications (ntfy, Pushover) carry only the date, the story count and three headlines;
they pass through the ntfy server (ntfy.sh unless self-hosted) or Pushover under their own terms.

WhatsApp recipients are phone numbers the operator lists in `config.json`; Herald stores them
nowhere else and masks them in logs and run reports. Messages go through Meta's WhatsApp
Business Cloud API, so Meta processes the number and the message under its own terms. Add a
number only after its owner explicitly agreed to receive the briefing on WhatsApp, and keep a
record of that consent. Replies with `STOP` / `PARAR` are not processed automatically yet: the
operator removes the number from `recipients` when someone opts out.

## Legal basis and opt-in

Consent (LGPD art. 7, I). Subscription is double opt-in:

1. `herald subscribers add someone@example.com --lang pt-BR --source "site form"` stores the
   address as `pending` and sends a confirmation message.
2. The subscriber confirms through the link (operator endpoint that calls
   `herald subscribers confirm <token>`) or by replying, in which case the operator runs the same
   command.
3. Only `active` subscribers receive briefings.

When consent was already collected and confirmed elsewhere (for example, an existing double
opt-in list), import with `--confirmed --source "<where>"` so the record shows its origin.

The Telegram bot is double opt-in too:

1. `/start` explains what the bot sends and stores, and offers a confirm button. It keeps a
   `pending` record (chat id and language only) for up to 24 hours.
2. The button (or `/start confirm`) from that chat within those 24 hours records consent with
   `consent_source` `telegram /start`. A `/start confirm` without the pending record (for
   example from a `t.me/<bot>?start=confirm` link) only shows the explanation again.
3. Only confirmed (`active`) chats receive briefings.

## Unsubscribe

Every email has an unsubscribe link and `List-Unsubscribe` headers (one-click when an HTTP
endpoint is configured in `unsubscribe_base_url`, `mailto:` otherwise). Opt-outs take effect
before the next delivery: `herald subscribers unsubscribe <email-or-token>`.

Bot subscribers send `/stop`. When a person blocks the bot, Telegram refuses the next delivery
and Herald marks that chat unsubscribed.

## Bounces

When the receiving server permanently refuses an address (an SMTP `5xx` recipient refusal, or
Resend rejecting the `to` address), Herald sets the subscriber to `bounced` and records
`bounced_at`; bounced addresses get no further email. Temporary refusals (`4xx`) and sender-side refusals
(`5.7.x`, `530`, `535`) change nothing. Delivery reports keep only SMTP status codes; reply text
and addresses are left out.
Adding the address again with `--confirmed` makes it active (with a fresh token).

## Data subject rights (LGPD art. 18)

| Right | Email | Telegram bot (in the chat) | Telegram bot (operator) |
|---|---|---|---|
| Access / portability | `herald subscribers export <email>` (JSON) | `/export` | `herald subscribers export telegram:<chat_id>` |
| Correction | re-run `add` with the new language | `/lang`, `/follow`, `/unfollow` | |
| Deletion | `herald subscribers delete <email>` | `/delete` | `herald subscribers delete telegram:<chat_id>` |
| Revoke consent | `herald subscribers unsubscribe <email>` | `/stop` | `herald subscribers unsubscribe telegram:<chat_id>` |

`/privacy` in the bot summarizes this page. Deletion removes the whole record at once.

## Retention

| Record | Kept for |
|---|---|
| Pending (unconfirmed) email sign-ups | 7 days, then deleted |
| Pending bot `/start` (chat id and language only) | 24 hours, then deleted |
| Unsubscribed records (email and bot) | 30 days (proof of opt-out), then deleted |
| Bounced email records | 30 days, then deleted |
| Active subscribers (email and bot) | while subscribed |
| Published stories (no personal data) | `history.retention_days` (default 365) |

Pruning runs automatically at the end of every pipeline run, or manually with
`herald subscribers prune`.

## Storage and sharing

Subscriber data (email and bot) lives in its own SQLite file, `<data_dir>/subscribers.db`, separate from the
story history (`herald.db`), so it can be excluded from caches and shared backups. The bundled
GitHub Actions workflow does not cache it; run the email notifier and the bot from a host you
control. It is shared only with the email provider configured by the operator (the SMTP server,
or Resend with `transport: "resend"`; email addresses) and with Telegram (chat ids, to deliver
messages), for delivery; each processes the data under its own terms. Keep the file private
and back it up encrypted.
