Whatsapp

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:

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

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.

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.

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)

Receiving messages from Whatsapp users

Configure your Peliqan Account webhook URL for your Whatsapp app.

You can find your Webhook URL in Peliqan under Admin > Settings > Account webhook:

image

Add this URL for your app under Whatsapp > Configuration > Webhook > Callback URL:

image

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 in the following table in your Peliqan Data Warehouse: webhook.incoming_webhooks.