Send WhatsApp messages from analytics events
Contents
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 dashboard:
- Access token - Generate a WhatsApp Cloud API access token in your Meta app dashboard. This is found under WhatsApp > API Setup.
- Phone number ID - The ID associated with your WhatsApp Business phone number. Find this in the WhatsApp Manager or your Meta app's WhatsApp > API Setup page.
Configuring PostHog's WhatsApp destination
- In PostHog, click the Data pipeline tab in the left sidebar.
- Click the Destinations tab.
- 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.
| Option | Description |
|---|---|
Access tokenType: string Required: True | Your WhatsApp Cloud API access token from Meta. Generate it in the Meta for Developers app dashboard. |
Phone number IDType: string Required: True | The phone number ID associated with your WhatsApp Business account (found in the WhatsApp Manager). |
Graph API versionType: string Required: False | The Meta Graph API version to call. Defaults to v21.0. |
Recipient phone numberType: string Required: True | Phone number to send the message to (in E.164 format, e.g., +1234567890). |
Message typeType: choice Required: True | Text messages can only be sent within the 24-hour customer service window. Use a pre-approved template for business-initiated conversations. |
MessageType: string Required: False | Message body (max 4096 characters). Only used for text messages. |
Template nameType: string Required: False | Name of the pre-approved WhatsApp message template. Only used for template messages. |
Template languageType: choice Required: 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: boolean Required: False | Logs the WhatsApp sending responses for debugging. |
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 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 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!
What if I have feedback on this destination?
We love feature requests and feedback. Please tell us what you think.
What if my question isn't answered above?
We love answering questions. Ask us anything via our community forum.