Mapping between Botpress/WhatsApp
Content mapping for the official WhatsApp integration.
Here’s a breakdown of how WhatsApp treats data it receives from Botpress:
Botpress type | WhatsApp type |
---|---|
text | Text Object |
text with Markdown | Text Object |
image | Media Image Object |
audio | Media Audio Object |
video | Media Video Object |
file | Media File Object |
location | Location Object |
Some data types have restrictions in WhatsApp:
Here’s a breakdown of how WhatsApp treats data it receives from Botpress:
Botpress type | WhatsApp type |
---|---|
text | Text Object |
text with Markdown | Text Object |
image | Media Image Object |
audio | Media Audio Object |
video | Media Video Object |
file | Media File Object |
location | Location Object |
Some data types have restrictions in WhatsApp:
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 type | Botpress type | How to read |
---|---|---|
Text Object | text | Directly through event.preview |
Choices made from Interactive Objects | text | Directly through event.preview |
Media Image Object | image | Through event.payload |
Media Audio Object | audio | Through event.payload |
Media Video Object | video | Through event.payload |
Media File Object | file | Through event.payload |
Location Object | location | Through 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:
Type | Payload properties |
---|---|
image | imageUrl |
audio | audioUrl |
video | videoUrl |
file | fileUrl , filename |
location | latitude , longitude |
Read raw file data
To get the raw file content from WhatsApp:
Set a configuration variable
- In your dashboard, navigate to your bot’s Configuration Variables section in the left sidebar.
- Create a Configuration Variable named
WHATSAPP_ACCESS_TOKEN
. - Set its value to your WhatsApp access token.
Make a `GET` request
Now you can make an HTTP GET
request to get the raw file data:
Be sure to:
-
Replace
<URL>
with the actual URL provided in the payload -
Pass
whatsappAccessToken
as aBearer
token in the HTTPAuthorization
headerFor more information, check the WhatsApp documentation on downloading media files.
Get WhatsApp user info in Botpress
You can read event
variables to get information about the WhatsApp user your bot is chatting with.
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
You can also get the conversation’s WhatsApp phone number ID:
event.tags.conversation['whatsapp:phoneNumberId']
This is useful if you have multiple phone number IDs pointing to the same bot.