# WhatsApp

A WhatsApp connection is one WhatsApp Business number. Adlass stores what customers
write (after the sender filter of the connection), what was sent through Adlass and,
with coexistence, what the business wrote on the phone. `whatsapp.numbers.list` lists
the numbers you may read with the `connection_id` and `space_id` to use; every other
operation takes `connection_id`. Without `space_id` only the connection owner may call; with `space_id`
the connection needs an active grant in that Space. Reading needs
`integrations.whatsapp.messages.send` or `integrations.whatsapp.media.download` in the grant,
changes need `integrations.whatsapp.messages.send`.

Reading:
- `whatsapp.conversations.list`: conversations with contact, a preview of the last
  message and `window_open_until`. `needs_reply=true` lists customers waiting for an
  answer, oldest first. Filter by `status`, `label`, `since`; page with `cursor`.
- `whatsapp.conversations.get`: one conversation with its last messages (oldest to
  newest, private notes included); page back with `before` = `next_before`.
- `whatsapp.contacts.search`: by phone digits or name, with conversations.
- `whatsapp.media.get`: a medium a customer sent, with a `download_url` valid 5 min.

Changing:
- `whatsapp.conversations.update`: `status` (open, pending, resolved) and labels
  (`labels` replaces, `add_labels`/`remove_labels` change).
- `whatsapp.notes.add`: private note, never sent.
- `whatsapp.contacts.update`: the name Adlass keeps for a contact.
- `whatsapp.media.to_document`: copy a medium into a Space as a document.

Sending (integration operations, they need the grant):
- `integrations.whatsapp.messages.send` with `to` (E.164 or wa_id) and exactly one of
  `text`, `media`, `template`, `reaction`. It returns an invocation; the sent message
  appears in the conversation once Meta accepted it.
- Free text and media only while the 24 h window is open (`window_open_until`);
  otherwise send an approved template (`integrations.whatsapp.templates.list`).
- A document of the Space goes out as `media.link` from `whatsapp.documents.link`.
- The connection may restrict recipients (`recipient_not_allowed`) and senders.

Events (per Space with a grant, ids only): `whatsapp.message.received`,
`whatsapp.message.echo`, `whatsapp.message.failed`, `whatsapp.template.status_changed`,
`whatsapp.template.category_changed`, `whatsapp.number.status_changed`. Read the content
with the operations above. Local agents receive the same as watch events of the connection.
