The Whatsapp connector can be used to send automated messages to users using Whatsapp, and to receive messages from users. You can send messages based on templates and free text messages. You can also use Whatsapp Flows, which allows sending structured screens with forms, request the location of a user etc.
Setting up Whatsapp For Business (WABA)
Create a Facebook (Meta) app
Go to the Facebook (Meta) developers portal, create a Business Account and add an app:
https://developers.facebook.com
Configure Whatsapp for your Facebook (Meta) app
Go into the details of your app.
In the left pane under “Whatsapp” > Quick start, configure Whatsapp for your app:
- Add a phone number (can be mobile number or land line)
- Add the Webhook URL (see below under “Receiving messages”)
- Configure a System User with a token (see below)
Now add a connection in Peliqan for Whatsapp and add your WABA id and access token.
Find your WABA id
To find the ID of a WhatsApp Business Account (WABA):
Go to Business Manager > Business Settings > Accounts > WhatsApp Business Accounts.
Create a token
Go to Meta Business Manager > Business Settings > Users > System users.
- Add a System User
- Assign permissions to your app
- Generate a new token that does not expire, enable the permissions for Whatsapp:
whatsapp_business_management
,whatsapp_business_messaging
Sending messages to Whatsapp users
Sending a template message
Create a template first in your Whatsapp app:
In your Meta app under the section Whatsapp (left pane) > Quickstart. In the center pane under Whatsapp Business, click on “Message templates”. Add a message template.
Example of sending a template-based message in a Peliqan low-code Python script:
# Get your "from" phone number id
whatsapp_api = pq.connect('Whatsapp')
phonenumbers = whatsapp_api.list('phonenumbers')
st.json(phonenumbers) # Show result
templatemessage = {
"to": "+32498776655",
"langcode": "en_US",
"template_name": "hello_world", # Create your template first
"from_phonenumber_id": "263567523509780" # From above lookup
}
result = whatsapp_api.add('templatemessage', templatemessage)
st.json(result)
Sending a text message
Example of sending a text message in a Peliqan low-code Python script:
whatsapp_api = pq.connect('Whatsapp')
text = "Hi there"
textmessage = {
'to': "+32498776655",
'text': text.replace('"', "'").replace("\n", ""),
'from_phonenumber_id': "263567523509790" # See above for details
}
result = whatsapp_api.add('textmessage', textmessage)
st.json(result)
Receiving messages from Whatsapp users
Whatsapp (Facebook) will send webhook events for each message from a user.
There are 2 ways to process incoming webhooks in Peliqan:
- Using the Peliqan Webhook queue table (batch)
- Using an API handler script (realtime)
Using the webhook queue (batch)
This approach allows you to process incoming Whatsapp messages (webhooks) in batch. Incoming webhooks are stored in a table in the Peliqan data warehouse. More info:
Incoming webhooksConfigure your Peliqan Account webhook URL for your Whatsapp app.
You can find your Webhook URL in Peliqan under Admin > Settings > Account webhook:
Add this URL for your app under Whatsapp > Configuration > Webhook > Callback URL:
Note that a new webhook requires a verification from Meta, but this is built-in into Peliqan and will automatically be performed !
Now when a user sends you a message or replies to your message, an incoming webhook event will be stored in your account. You can find these events in the following table in your Peliqan Data Warehouse: webhook.incoming_webhooks
.
You can configure a scheduled script that runs e.g. every 5 minutes to process new incoming messages incrementally and send responses back to the user in Whatsapp.
Using webhook queue (realtime)
This approach allows you to process incoming Whatsapp messages in real-time using an API handler script in Peliqan. More info:
Publish APIsAdd a script of type “API handler” to handle incoming API calls (webhooks) from Whatsapp.
Configure a public API endpoint with method GET
. Example:
In the Whatsapp configuration, enter the detail of your API endpoint as Callback URL.
Click on “Verify and Save”. Facebook will now make an API call to your script to get the URL verified.
The script will send the “challenge” in the response.
Once the verification is done, change your API endpoint method from GET
to POST
.
From now on, when you send a Whatsapp message, the script will send out a Whatsapp message and echo back your message.