# WhatsApp

> Connect a WhatsApp business number so messages start flows and flows can read the pictures and files people send and answer with text, buttons, templates, documents and private links. Covers the 24-hour window, templates and the shared number.

Source: https://docs.go-lumen.ai/connectors/whatsapp

A WhatsApp connection is your business number on Meta's WhatsApp Cloud API. Messages people send to it can start flows, and flows can read the pictures and files people send and answer with text, up to three reply buttons, Meta-approved templates, documents and private links.

-   Needs a Meta business account
-   Admin to connect
-   4 values from Meta

## Which number

| Connection | Number | Who it reaches |
| --- | --- | --- |
| **WhatsApp (Meta Cloud API)** | Your own business number, set up by you in this page. | Anyone who writes to it. |
| **WhatsApp (app's shared number)** | One number that your app's operator owns and shares between workspaces. It appears in **Connectors** with a lock icon, and you do not set it up. | The members of your workspace, routed by the phone each of them verified. |

The rest of this page is about your own number. On a shared number everything below about flows, steps and the 24-hour window applies in the same way. What differs: the number's templates are managed by its owner, so you see them read only, and a flow can write only to phones that members verified in your workspace.

## Connect your number

You need a WhatsApp Business account at Meta with a phone number, and four values from it. Lumen keeps them apart from the connection and never shows them again.

| Value | Where to find it at Meta |
| --- | --- |
| **System user access token** | Business settings, System users, **Generate token**. It needs `whatsapp_business_messaging` and `whatsapp_business_management`. |
| **App secret** | Your Meta app, **App settings**, **Basic**. It signs every message Meta sends to Lumen. |
| **Phone number ID** | Your Meta app, **WhatsApp**, **API setup**. It is the id of the number, not the number itself. |
| **WhatsApp Business account ID** | The same page. |

**Console:**

1.  In the sidebar, open **Connectors**, click **Add connection** and choose **WhatsApp (Meta Cloud API)**.
2.  Give it a **Name**, such as `Support line`.
3.  Paste the **System user access token**, the **App secret**, the **Phone number ID** and the **WhatsApp Business account ID**.
4.  Click **Test connection**. Lumen reads the number from Meta and shows its display number and verified name. Then click **Add WhatsApp (Meta Cloud API)**.

![The Add connection panel for WhatsApp (Meta Cloud API). Name holds Support line. A note says the credentials are kept out of sight, stored apart from the connection and never shown again. Four empty fields follow: System user access token, App secret, Phone number ID and WhatsApp Business account ID. Test connection, Cancel and Add WhatsApp (Meta Cloud API) are at the bottom.](https://docs.go-lumen.ai/img/connectors/whatsapp-01-add-number.png)

*Four values from Meta. The two secrets are hidden as you type.*

Now tell Meta where to send messages. Open the connection and click **Show webhook details**. In your Meta app, open **WhatsApp**, **Configuration**, **Webhook**, paste the **Callback URL** and the **Verify token**, and subscribe to two fields:

| Field | What it does |
| --- | --- |
| `messages` | The messages people send. |
| `message_template_status_update` | Keeps your template statuses current as Meta reviews them. |

![The Webhook for Meta section of a WhatsApp connection, open. It says to paste the callback URL and verify token in the Meta app's WhatsApp configuration. The Callback URL and Verify token are shown in boxes with copy buttons, and a button to make a new verify token. Two webhook fields to subscribe to are listed: messages, the messages people send, and message\_template\_status\_update, which keeps template statuses current. A Hide button follows.](https://docs.go-lumen.ai/img/connectors/whatsapp-03-webhook.png)

*The callback URL and verify token are for Meta's webhook settings. The token shown is a placeholder.*

Only an admin can see these details. **Make a new verify token** replaces the token: the old one stops working, so paste the new one in Meta and verify again.

**CLI:**

```bash title="Connect a WhatsApp number from a terminal"
lumen connect whatsapp-cloud support-whatsapp \
  --secret-env accessToken=WA_ACCESS_TOKEN \
  --secret-env appSecret=WA_APP_SECRET \
  --secret-env phoneNumberId=WA_PHONE_NUMBER_ID \
  --secret-env wabaId=WA_BUSINESS_ACCOUNT_ID
```

Secrets are read from the environment variables you name, or asked with hidden input. The callback URL and verify token for Meta's webhook settings are in the console, under **Show webhook details**.

**YAML:**

```yaml title="support-whatsapp.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Connector
metadata:
  name: support-whatsapp
  namespace: tenant-acme
spec:
  classRef: {name: whatsapp-cloud}
  config: {}
  credentials:
    secretRef: {name: lumen-conn-support-whatsapp}
```

The four values are the keys `accessToken`, `appSecret`, `phoneNumberId` and `wabaId` of the Secret `lumen-conn-support-whatsapp`. Write them through the console or `lumen connect` so Lumen creates the Secret for you. The connection's address for Meta is generated when it is created.

## The 24-hour window

WhatsApp lets a business answer freely for 24 hours after the person last wrote to its number. This is the **window**. Outside it, Meta accepts only an approved template.

| The person last wrote | What a flow can send |
| --- | --- |
| Within 24 hours | Text, reply buttons, documents, document links, templates. |
| Longer ago | Only an approved template. |

The steps check the window before sending. If you send text or ask a question outside it and you named no template, Lumen does not fail the step. It sends its generic template with the message cut to one line, and holds the real message. When the person writes back or taps the template's button, the held message is delivered. A held message expires after 72 hours, and a held question when its wait ends. The step's `whatsappStatus` is `held` meanwhile.

The window belongs to the number and the person, so it is the same for every flow and workspace that uses the number.

## Message templates

Open the connection to manage templates without leaving Lumen. The **Message templates** section lists each template with its category, language, number of parameters and status: **Approved**, waiting for Meta to review it, **Rejected by Meta** (with the reason), paused or disabled.

![A WhatsApp connection named Lumen Demo, Ready. Below the webhook section and a Test connection button, a section titled Message templates shows Synced just now, a refresh button and a New template button, then a button Add Lumen's generic templates. A table lists six templates with category, language and parameter count and a delete button each: receipt\_ready, expense\_approval, weekly\_summary, spring\_offer, order\_shipped and winter\_sale, with status icons for approved, waiting, rejected, paused and disabled.](https://docs.go-lumen.ai/img/connectors/whatsapp-02-templates.png)

*Templates are listed with their review status. Only an approved one can be sent.*

-   **Sync templates from Meta** (the refresh button) reads them again. Meta also tells Lumen when a review ends.
-   **New template** opens a form. Give it a **Name** (lowercase letters, digits and underscores, like `order_shipped`), a **Category** (**Utility** for something the person asked for or already does with you, **Marketing** for offers and news, which Meta reviews more strictly), a **Language**, an optional **Header**, the **Message** with `{{1}}`, `{{2}}` where values go, **Example values**, an optional **Footer** and up to 10 **Quick replies**. A message may not start or end with a variable. The form checks these rules as you type and shows a preview. Click **Send to Meta for review**; review usually takes minutes.
-   **Add Lumen's generic templates** creates `lumen_update` and `lumen_question`, which Lumen sends when a message has to go outside the window.
-   The bin button deletes a template at Meta too. Meta blocks reusing the name of a deleted approved template for 30 days.

## Start a flow from a message

Add the trigger **A WhatsApp message arrives**. A person writing to your number, or tapping a button you sent, starts it.

![The settings of the trigger A WhatsApp message arrives. Which address starts this flow shows Sales line, WhatsApp (Meta Cloud API). Start on offers all, text and buttons, with all selected. Only from these numbers is empty. Show typing while the flow works is switched on, with a note that it marks their message read and shows typing until the flow's first WhatsApp answer.](https://docs.go-lumen.ai/img/connectors/whatsapp-04-trigger.png)

*The trigger listens on one WhatsApp connection.*

| Setting | Default | What it does |
| --- | --- | --- |
| **Start on** (`only`) | `all` | `all`, `text` (only typed messages) or `buttons` (only a tapped button). |
| **Only from these numbers** (`from`) | Anyone | Phone numbers with the country code. |
| **Show typing while the flow works** (`showTyping`) | On | Marks their message read and shows "typing" until the flow's first WhatsApp answer, for up to about a minute and a half. Turn it off for a flow that never answers on WhatsApp. |

The trigger gives the flow these fields: `message` (what they wrote, the title of the button they tapped, or a media caption), `from` (their number) and `name`, `kind` (`text`, `button_reply`, `media` or `other`), `buttonId`, `conversationId`, `sessionId`, `messageId`, `connection`, `receivedAt`, and for pictures and files `mediaType`, `mediaCount` and `mediaError`.

### Pictures and files people send

When someone sends a photo, a document or a sticker, Lumen takes the file from WhatsApp the moment the message arrives, with your number's own access, and the flow starts with it as the run's file. Steps that read files and AI agents see it as they see an email attachment. The message stays `kind: media` and its caption is `message`. `mediaType` is `image`, `document` or `sticker`, and `mediaCount` is `1`. A document keeps the name the person gave it. A photo is named after its WhatsApp id, such as `wamid-123.jpg`.

Lumen takes pictures (JPEG, PNG, GIF, WebP), PDF, Word, Excel and PowerPoint files, plain text and CSV, up to 25 MB, the same limit as an email. It checks that the file really is what it says. Voice notes and videos are not taken.

If the file cannot be taken, the flow still starts, with no file and `mediaCount` `0`, and `mediaError` says why, so the flow can answer the person:

| `mediaError` | Meaning |
| --- | --- |
| `too_large` | The file is over 25 MB. |
| `unsupported_type` | A kind of file Lumen does not take, or one that is not what it claims to be. |
| `expired` | WhatsApp no longer has the file. |
| `unavailable` | WhatsApp could not be reached. |

A file from a person is outside data: a step that reads it marks it as untrusted for the model. Add a **Branch** on `mediaCount` or `mediaError` to ask the person to send the file again.

An AI agent after this trigger converses over the same WhatsApp conversation: it reads back the earlier turns and its reply can be sent with **Send a WhatsApp message**.

## Answer on WhatsApp

| Step | Does | Window |
| --- | --- | --- |
| **Send a WhatsApp message** | Sends text (`text`, up to 4,096 characters). | Inside, or held |
| **Send a WhatsApp template** | Sends an approved template with `template`, `language`, `params` for `{{1}}`, `{{2}}` and `buttonPayloads` for its quick replies. | Any time |
| **Send a file on WhatsApp** | Sends one of the run's files as a document in the chat (`file`, `caption`). | Inside, or held |
| **Send a document link on WhatsApp** | Sends a private link to a file (`file`, `caption`, `expiresDays`). | Inside, or held |
| **Ask with buttons on WhatsApp** | Sends a question with up to three buttons (`id` and a `title` of at most 20 characters). A tap starts your flow again with `kind: button_reply` and the button's `id` in `buttonId`. | Inside, or held |
| **Ask on WhatsApp and wait** | The same, but the run waits for the tap and goes on with the answer. See [Ask on WhatsApp](https://docs.go-lumen.ai/approvals/ask-on-whatsapp.md). | Inside, or a template |

Every send step has the same three addressing settings:

-   **Send from** (`connectorRef`): the connection. Empty is the number the run's message came in on, else the workspace's only WhatsApp connection. With none or several the step fails and asks you to pick one.
-   **To** (`to`): a phone number in any format with the country code, or a placeholder. Empty answers whoever sent the message that started the run. A run that no WhatsApp message started needs it.
-   **To a member** (`toMember`): a member's sign-in email, used when **To** is empty. The member must have joined or verified their phone on the number, so no phone numbers sit in the flow.

Each step adds `whatsappMessageId` and `whatsappStatus` and sends once per attempt, so a step run again after a lost worker does not send twice.

### Send a file or send a link

**Send a file on WhatsApp** puts the file itself in the chat, as a document the person can open and forward, with your `caption` under it. **File** names the run's file (a name, or a placeholder); empty is its first PDF, or its first file. The file is uploaded to WhatsApp, which is run by Meta, so use it for what the person should have in their own chat. Up to 100 MB, and the caption up to 1,024 characters. Outside the 24-hour window it is held and sent when the person writes back, like text.

**Send a document link on WhatsApp** never uploads the file. It sends a message with a private link to the file in Lumen's storage and turns link previews off, so neither WhatsApp nor Meta fetches it. The link stops working after **Link works for (days)**: 1 to 30, default 7. **File** names the run's file; empty is its first PDF, or its first file. Keep message text minimal for the same reason: what the person needs (a name, an amount), never the document's contents.

## Flows that answer, read a picture and send a document

```yaml title="whatsapp-support-reply.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: whatsapp-support-reply
  namespace: tenant-acme
spec:
  displayName: Acknowledge WhatsApp requests
  triggers:
    - id: msg
      ref: {name: whatsapp-message-received}
      connectorRef: {name: support-whatsapp}
      config: {only: text, showTyping: true}
      next: [reply]
  nodes:
    - id: reply
      stepRef: {name: whatsapp-send-text}
      config:
        text: "Thanks {msg.name}, we got your message and will reply today."
      next: [team]
    - id: team
      stepRef: {name: notify-in-app}
      config:
        to: admins
        title: "WhatsApp from {msg.name}"
        body: "{msg.name} ({msg.from}) wrote: {msg.message}"
```

The reply goes to whoever wrote, from the number the message came in on. The second flow reads a photo of a bank transfer that the person sent and answers with what it says. Its agent is handed the run's file, which is the photo.

```yaml title="whatsapp-read-transfer.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: whatsapp-read-transfer
  namespace: tenant-acme
spec:
  displayName: Read a bank transfer sent on WhatsApp
  triggers:
    - id: msg
      ref: {name: whatsapp-message-received}
      connectorRef: {name: support-whatsapp}
      next: [read]
  nodes:
    - id: read
      stepRef: {name: chat-agent}
      config:
        files: {mode: attach}
        limits: {maxTurns: 2, maxTokens: 30000, maxMinutes: 3}
        instructions: |
          The person sent a screenshot of a bank transfer. Say the amount, the date and who it was paid to,
          in one short line. If there is no picture ({msg.mediaError}), ask them to send it again.
      next: [answer]
    - id: answer
      stepRef: {name: whatsapp-send-text}
      config:
        text: "{read.reply}"
```

The third flow starts from the invoice inbox and sends each PDF to a phone as a link that works for 3 days.

```yaml title="whatsapp-invoice-links.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: whatsapp-invoice-links
  namespace: tenant-acme
spec:
  displayName: Send invoices to Dana on WhatsApp
  triggers:
    - id: email
      ref: {name: email-arrives}
      connectorRef: {name: invoices-inbox}
      config: {attachments: separate, requireAttachment: true}
      next: [pdfs]
  nodes:
    - id: pdfs
      stepRef: {name: keep-pdfs}
      next: [send]
    - id: send
      stepRef: {name: whatsapp-send-document-link}
      config:
        connectorRef: support-whatsapp
        to: "12025550143"
        caption: "New invoice from {email.from}"
        expiresDays: 3
```

The second flow sends to a number no WhatsApp message started, so it relies on the window: if the person has not written in 24 hours, Lumen holds the message and sends its generic template first. To always reach them, use a template of your own:

```yaml title="A template step, as a fragment of a flow's nodes"
- id: notify
  stepRef: {name: whatsapp-send-template}
  config:
    connectorRef: support-whatsapp
    to: "12025550143"
    template: receipt_ready
    language: en
    params: ["{email.from}", "{email.subject}"]
```

## See the conversations

The chat button on a connection's card opens **Conversations**: every conversation with its messages, delivery status (**Sending**, **Sent**, **Delivered**, **Read**, **Failed**), the window (**Free replies until** a time, or **Only approved templates can be sent**) and a link to the run that sent each message. It is read only: replies are sent by your flows. Only an admin sees all conversations. A member sees the conversation of the phone they verified.

## Next steps

[Ask on WhatsAppPause a run until a person taps an answer.](https://docs.go-lumen.ai/approvals/ask-on-whatsapp.md)[TriggersEvery way to start a flow, and the Start only when condition.](https://docs.go-lumen.ai/build/triggers.md)[AgentsLet an agent converse over the WhatsApp conversation.](https://docs.go-lumen.ai/ai/agents.md)[Email forwardingStart flows from mail, then notify people on WhatsApp.](https://docs.go-lumen.ai/connectors/email-forwarding.md)
