Mapping from WhatsApp to Botpress
Content mapping for the official WhatsApp integration.
Overview
In Botpress, you can read data sent from a user’s WhatsApp message using the event
’s properties. This is useful if you want to store user-provided data and access it later.
Here’s a breakdown of how data from WhatsApp is mapped to Botpress:
WhatsApp Message Type | Botpress Type | How to Read |
---|---|---|
Text messages | text | event.preview or event.payload |
Choices from interactive buttons or lists | text | event.preview or event.payload |
Image messages | image | event.payload |
Sticker messages | image | event.payload |
Audio messages | audio | event.payload |
Video messages | video | event.payload |
Document messages | file | event.payload |
Location messages | location | event.payload |
Read data from a payload
To read data from event.payload
:
- Add a Wait for User Input Card to the Node where you want to prompt the user.
- After that Card, check that
event.type
is equal to the data type you’re expecting from the user. - Read
event.payload
.
The payload’s properties depend on the data type:
Get raw file contents
By default, any media sent by a user is automatically uploaded to the Botpress Files API. This means you can read the raw file contents directly from the payload’s URL.
For example, if you prompt the user to send an image, you can read {{event.payload.imageUrl}}
to get the image.
You can also set an expiry time for downloaded files — just update the Downloaded Media Expiry field in the Configuration menu.
From WhatsApp API
If you’d rather get file contents from a WhatsApp media URL, you can disable Download Media in the Configuration menu. When disabled, you’ll have to authenticate with the WhatsApp API to get files.
Tags
You can read event
tags to get information about the current WhatsApp user and conversation:
Phone number
To get the user’s phone number:
event.tags.conversation['whatsapp:userPhone']
This number contains the country code. It has no spaces, dashes (-) or symbols.
Phone number ID
To get the conversation’s WhatsApp phone number ID:
event.tags.conversation['whatsapp:botPhoneNumberId']
This is useful if you have multiple phone number IDs pointing to the same bot.
Check if message is reply
To check if a message was a reply to another:
event.tags.message['whatsapp:replyTo']
If the message is a reply, the tag’s value will be the Botpress messageId
of the quoted message.