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.comConfigure 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)
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
You can only send a message to a new user using a template. A free text message can only be sent after you have received a response from a user or when a user has sent a message to you first. Whatsapp wants to avoid that spam is sent to 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:Example code to send a template message with dynamic content and a Whatsapp flow (click to expand)
Example code to send a template message with dynamic content and a Whatsapp flow (click to expand)
Sending a text message
Example of sending a text message in a Peliqan low-code Python script: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 webhooks Configure your Peliqan Account webhook URL for your Whatsapp app. You can find your Webhook URL in Peliqan under Admin > Settings > Account webhook: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.
Example script that will process webhooks incrementally, by storing a "state" (click here to expand)
Example script that will process webhooks incrementally, by storing a "state" (click here to expand)
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 APIs Add a script of type “API handler” to handle incoming API calls (webhooks) from Whatsapp.Example code for a real-time chatbot in Whatsapp using OpenAI ChatGPT (click to expand)
Example code for a real-time chatbot in Whatsapp using OpenAI ChatGPT (click to expand)
GET. Example:
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.