# Send WhatsApp messages from analytics events - Docs

You can use your PostHog event data to send WhatsApp messages via the WhatsApp Cloud API (Meta Graph API). Here's everything you need to get started.

## Configuring WhatsApp

First, you need a Meta Business account with WhatsApp Cloud API access. Gather the following credentials from the [Meta for Developers](https://developers.facebook.com/) dashboard:

1.  **Access token** - Generate a WhatsApp Cloud API access token in your Meta app dashboard. This is found under **WhatsApp** > **API Setup**.
2.  **Phone number ID** - The ID associated with your WhatsApp Business phone number. Find this in the [WhatsApp Manager](https://business.facebook.com/wa/manage/) or your Meta app's **WhatsApp** > **API Setup** page.

## Configuring PostHog's WhatsApp destination

1.  In PostHog, click the **[Data pipeline](https://app.posthog.com/pipeline/destinations)** tab in the left sidebar.
2.  Click the [Destinations](https://app.posthog.com/pipeline/destinations?search=whatsapp) tab.
3.  Click **New destination** and choose WhatsApp's **Create** button.

Enter your access token and phone number ID from Meta. The recipient phone number defaults to `{{ person.properties.phone }}` and supports Liquid templating.

## Message types

WhatsApp supports two message types, selectable via the **Message type** input:

-   **Text** - A free-form message body (max 4,096 characters). Text messages can only be sent within WhatsApp's 24-hour customer service window – i.e., within 24 hours after the recipient last messaged you.
-   **Template** - A pre-approved message template registered in your WhatsApp Manager. Use templates for business-initiated conversations outside the 24-hour window, such as drip campaigns or transactional notifications. You must provide the template name and the language code it was approved in.

> **Important:** If you're sending business-initiated messages (e.g., marketing campaigns or transactional alerts), you must use the **Template** message type with a pre-approved template. Free-form text messages sent outside the 24-hour window will fail.

### Filtering

Filter events to only those that contain a valid phone number property, as this is required for sending WhatsApp messages.

### Testing

Once you've configured your WhatsApp destination, click **Start testing** to verify everything works the way you want. Switch off **Mock out async functions** in order to send a test WhatsApp message.

 | --- |
| Access tokenType: stringRequired: True | Your WhatsApp Cloud API access token from Meta. Generate it in the Meta for Developers app dashboard. |
| Phone number IDType: stringRequired: True | The phone number ID associated with your WhatsApp Business account (found in the WhatsApp Manager). |
| Graph API versionType: stringRequired: False | The Meta Graph API version to call. Defaults to v21.0. |
| Recipient phone numberType: stringRequired: True | Phone number to send the message to (in E.164 format, e.g., +1234567890). |
| Message typeType: choiceRequired: True | Text messages can only be sent within the 24-hour customer service window. Use a pre-approved template for business-initiated conversations. |
| MessageType: stringRequired: False | Message body (max 4096 characters). Only used for text messages. |
| Template nameType: stringRequired: False | Name of the pre-approved WhatsApp message template. Only used for template messages. |
| Template languageType: choiceRequired: False | Language and locale code of the pre-approved template. Must match the language the template was approved in. Only used for template messages. |
| Log responsesType: booleanRequired: False | Logs the WhatsApp sending responses for debugging. |

How to create this via the API

Using our REST API you can create this destination like so:

Terminal

PostHog AI

```bash
# Create a new destination
curl --location 'https://us.i.posthog.com/api/environments/:project_id/hog_functions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <POSTHOG_PERSONAL_API_KEY>' \
--data '{
    "type": "destination",
    "name": "WhatsApp",
    "inputs": {
        "access_token": {
            "value": ""
        },
        "phone_number_id": {
            "value": ""
        },
        "api_version": {
            "value": "v21.0"
        },
        "to_number": {
            "value": "{{ person.properties.phone }}"
        },
        "message_type": {
            "value": "text"
        },
        "message": {
            "value": "PostHog event {{ event.event }} was triggered"
        },
        "template_language": {
            "value": "en_US"
        }
    },
    "enabled": true,
    "template_id": "template-whatsapp"
}'
```

## FAQ

### Is the source code for this destination available?

PostHog is open-source and so are all the destinations on the platform. The [source code](https://github.com/PostHog/posthog/blob/master/nodejs/src/cdp/templates/_destinations/whatsapp/whatsapp.template.ts) is available on GitHub.

### What phone number format is required?

Phone numbers must be in E.164 format (e.g., +1234567890). This includes the country code preceded by a plus sign, followed by the phone number without spaces or special characters.

### What is the 24-hour customer service window?

WhatsApp restricts free-form (text) messages to a 24-hour window that opens when a customer messages you first. After 24 hours of inactivity, you can only send pre-approved template messages. See [Meta's documentation on conversations](https://developers.facebook.com/docs/whatsapp/conversation-types) for details.

### What Graph API version does this use?

The destination defaults to Meta Graph API `v21.0`. You can override this in the **Graph API version** input field if you need a different version.

### Who maintains this?

This is maintained by PostHog. If you have issues with it not functioning as intended, please [let us know](https://us.posthog.com/#panel=support%3Asupport%3Aapps%3A%3Atrue)!

### What if I have feedback on this destination?

We love feature requests and feedback. Please [tell us what you think](https://us.posthog.com/#panel=support%3Afeedback%3Aapps%3Alow%3Atrue).

### What if my question isn't answered above?

We love answering questions. Ask us anything via [our community forum](/questions.md).

### Community questions

Ask a question

### Was this page useful?

HelpfulCould be better