With virtually 3 billion energetic customers worldwide, WhatsApp has turn into a wonderful channel for companies seeking to join with their viewers successfully. The WhatsApp Enterprise API takes its performance to the following degree.
The API permits you to ship messages to 1000’s of consumers mechanically. You possibly can ship texts, pictures, movies, and even interactive messages. It is an effective way for companies to ship clients data related to them, proper once they want it. No extra generic mass emails or hoping they see your social media posts.
On this information, we’ll stroll you thru use the WhatsApp API to ship messages. We’ll cowl:
- Organising your WhatsApp Enterprise Platform
- Getting entry tokens
- Sending various kinds of messages
- Learn how to automate the messaging workflow effectively
Let’s get began then.
Getting Began with the WhatsApp Enterprise Platform
The WhatsApp Enterprise Platform is designed for medium to massive companies to interact with clients on a big scale. It allows enterprises to rapidly provoke conversations, ship notifications about help or purchases, supply customized companies, and help clients of their most well-liked communication channels.
Listed below are the three internet hosting choices obtainable for the WhatsApp Enterprise API:
- Cloud API: Hosted by Meta, this API gives a simple, maintenance-friendly approach for companies to attach with clients. It is the popular selection for many corporations resulting from its simplicity, ease of use, and automated scaling.
- On-Premises API: Companies have to host this themselves. This feature supplies extra management over the infrastructure however requires extra technical sources and upkeep.
- Enterprise Administration API: Important for managing your WhatsApp Enterprise Account settings, belongings, and message templates, this API is important no matter whether or not you select the Cloud API or the On-Premises API.
💡
Do you know? The Cloud API permits you to ship as much as 1,000 messages per second, whereas the On-Premises API is restricted to 250 messages per second.
To start out utilizing the WhatsApp Enterprise Platform, you have to create a Meta Developer Account and a enterprise app within the Meta Developer Dashboard. Whereas not necessary, you’ll be able to arrange a Meta Enterprise Supervisor to arrange and handle your online business belongings, together with your WhatsApp Enterprise Account.
You will additionally have to receive a devoted telephone quantity for your online business. Then, use that to create a WhatsApp Enterprise Account. Register the quantity via the WhatsApp Enterprise app or the API.
Then, add the WhatsApp product to your app within the Meta Developer Dashboard. It will mechanically create a take a look at WhatsApp Enterprise Account, a take a look at enterprise telephone quantity, and a set of pre-approved message templates for testing and growth functions.
To entry sure options, equivalent to larger messaging limits and the flexibility to ship template messages, you have to full the Enterprise Verification course of. You should submit your online business data for evaluation within the Meta Enterprise Supervisor.
Necessities of WhatsApp Enterprise Administration API
The WhatsApp Enterprise Administration API is an important a part of the WhatsApp Enterprise Platform. It really works alongside the Cloud API and On-Premises API that can assist you handle your WhatsApp Enterprise Account settings, belongings, and entry tokens.
Entry Tokens
Entry tokens are obligatory for authenticating your API requests. They guarantee safe communication between your software and the WhatsApp Enterprise Platform.
The Enterprise Administration API helps three kinds of entry tokens:
- System Person Entry Tokens: These tokens signify your online business and do not expire. They’re important for Answer Companions who share credit score traces with their clients. There are two kinds of System Person tokens:
- Worker System Customers: For restricted entry to particular WhatsApp Enterprise Accounts.
- Admin System Customers: For full entry to all WhatsApp Enterprise Accounts and belongings.
- Enterprise Integration System Person Entry Tokens: These tokens are particular to particular person buyer knowledge and are utilized by Tech Suppliers and Answer Companions for automated actions with out consumer enter.
- Person Entry Tokens: Usually used for preliminary app testing. They expire rapidly and are much less appropriate for ongoing growth. This token was used within the take a look at message despatched above.
Creating System Customers and producing Entry Tokens
To create a System Person and generate an entry token:
- Go to the Meta Enterprise Suite and discover your online business account.
- Click on the Settings icon and choose “Enterprise settings.”
- Go to “Customers” > “System customers” and click on “Add” to create an admin or worker System Person.
- Choose the System Person and click on “Generate new token.”
- Select the app and permissions for the token.
- Click on “Generate” to create the entry token.
Producing these entry tokens with the proper permissions is essential for making certain your software has the required entry. With out that, your software could encounter errors or be unable to carry out particular actions. It hinders your capability to successfully use the WhatsApp Enterprise Platform.
💡
To get a Enterprise Integration System Person entry token, it’s worthwhile to arrange Embedded Signup utilizing Fb Login for Companies. When a buyer completes the signup course of, you trade the obtained code for the token.
Charge Limits
These limits decide the variety of API calls allowed per hour and assist forestall abuse or overload of the platform. The precise limits rely upon the kind of name and your WhatsApp Enterprise Account standing. Realizing these limits and adhering to them helps keep away from potential disruptions.
💡
Tip: At all times hold your entry tokens safe and by no means share them publicly, as they grant entry to your WhatsApp Enterprise Account.
Understanding entry tokens, create them, and the speed limits will assist you authenticate your requests and handle your WhatsApp Enterprise Account successfully.
Learn how to Set Up the WhatsApp Cloud API
Companies want Cloud API over on-premises because it gives a extra easy setup and upkeep course of. Meta hosts the required infrastructure, making certain scalability and reliability. This enables companies to give attention to constructing their functions and buyer experiences quite than managing servers and infrastructure.
The WhatsApp Cloud API is a cloud-hosted model of the WhatsApp Enterprise Platform. It programmatically allows companies to ship and obtain messages, media, and interactive message templates.
With the cloud API, you’ll be able to simply combine WhatsApp messaging into your online business workflows, like buyer help, order updates, appointment reminders, and functions like CRM and advertising and marketing platforms.
To start out utilizing the WhatsApp Cloud API, observe these steps:
1. Create a Meta Developer Account: If you do not have one already, create a Meta Developer Account at builders.fb.com.
2. Create a brand new App: Within the Meta Developer Dashboard, click on on “Create App”, select others, choose “Enterprise” because the app sort. Fill within the required particulars and click on “Create App”.
3. Add the WhatsApp product: In your app’s dashboard, scroll to the “Add a Product” part and click on “Set Up” on the WhatsApp card. You probably have a Meta Enterprise Account (MBA), you will be requested to hyperlink it throughout this course of. If not, you will be guided to create one.
4. Configure your WhatsApp Enterprise Account: As soon as your MBA is linked, you will be taken to the WhatsApp Enterprise Account configuration dashboard.
Right here, you’ll be able to:
- Arrange a take a look at WhatsApp Enterprise Account (free however with utilization limitations)
- Create a take a look at enterprise telephone quantity linked to your WhatsApp Enterprise Account
- Generate pre-approved messaging templates for testing
5. Add a recipient quantity: To ship take a look at messages, you have to add a sound WhatsApp quantity. Go to the App Dashboard, navigate to WhatsApp > API Setup, and underneath the message-sending part, search for the ‘To’ subject to handle your telephone quantity listing. Enter a sound WhatsApp quantity and confirm it utilizing the affirmation code despatched by way of WhatsApp.
6. Ship a take a look at message: Use the pre-approved ‘hello_world’ template to ship a take a look at message to your verified recipient quantity. You are able to do this utilizing the API panel within the dashboard or by working the offered Python code.
import requests
url = "https://graph.fb.com/v17.0/206324309221106/messages"
headers = {
'Authorization': 'Bearer YOUR_TEMPORARY_ACCESS_TOKEN',
'Content material-Kind': 'software/json'
}
knowledge = {
"messaging_product": "whatsapp",
"to": "RECEPIENT_PHONE_NUMBER",
"sort": "template",
"template": {
"identify": "hello_world",
"language": {
"code": "en_US"
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.textual content)
On this instance:
- Ensure your take a look at enterprise quantity is within the ‘From’ subject.
- Make sure the recipient’s quantity is chosen within the ‘To’ subject. You possibly can ship messages to a number of numbers if added.
The command you will use signifies that you simply’re sending a template message, specifying the ‘hello_world’ template. A message just like the one under ought to seem on the recipient’s telephone quantity.
Transferring to Manufacturing
Whenever you’re able to ship messages to your clients, you’ll be able to add an precise enterprise telephone quantity to the API Setup and create an official WhatsApp Enterprise Account. It will will let you ship messages to your clients with out the restrictions of the take a look at account.
Learn how to Ship Messages Utilizing the WhatsApp Cloud API
The platform additionally helps two kinds of messages: free-form and template messages. Free-form messages enable for extra flexibility however have to be despatched inside 24 hours of the client’s final message. It may well embrace textual content, pictures, movies, paperwork, and clickable parts.
Template messages are pre-approved, standardized codecs that companies can use to ship notifications or buyer care messages to opted-in clients. These messages require consumer consent and approval from the WhatsApp evaluation group. They will embrace appointment reminders, transport data, situation decision, or fee updates.
To ship a message utilizing the WhatsApp Cloud API, it’s worthwhile to make an HTTP POST request to the /messages endpoint.
POST /<WHATSAPP_BUSINESS_PHONE_NUMBER>/messages
The request ought to embrace your entry token within the Authorization header and the message payload within the request physique. The message payload has an ordinary format, with variations relying on the message sort:
{
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "<TO>",
"sort": "<TYPE>",
// Particular payload relying on message sort
}
<TO>
: WhatsApp ID or telephone variety of the recipient (e.g., +16315551234).<TYPE>
: Kind of message (e.g., ‘textual content’, ‘picture’, and many others.).
The response incorporates a message ID, which is useful for sending replies or reactions and checking for unsuccessful requests by way of the standing code within the response (typical conference the place standing code 200 signifies a profitable name).
{
"messaging_product": "whatsapp",
"contacts": [{
"input": "<PHONE_NUMBER>",
"wa_id": "<WHATSAPP_ID>",
}],
"messages": [{
"id": "<wamid.ID>",
}]
}
Let’s discover ship various kinds of messages utilizing the WhatsApp Cloud API.
➡️
To make use of the code, exchange the placeholders within the payload with the suitable contact data.
1. Textual content Messages
Textual content messages are probably the most primary sort of message you’ll be able to ship utilizing the WhatsApp Cloud API. They comprise plain textual content and might embrace formatting and preview URLs.
This is an instance of ship a textual content message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "textual content",
"textual content": {
"preview_url": False,
"physique": "Good day, this can be a textual content message from the WhatsApp Cloud API!"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
is the ID of your WhatsApp Enterprise Account telephone quantity.YOUR_ACCESS_TOKEN
is the entry token you generated to your app.RECIPIENT_PHONE_NUMBER
is the WhatsApp variety of the message recipient.
The message payload contains the next fields:
messaging_product
: At all times set to'whatsapp'
.recipient_type
: Set to'particular person'
for sending messages to particular person customers.to
: The WhatsApp variety of the message recipient.sort
: The kind of message you are sending, on this case,'textual content'
.textual content
: An object containing the textual content message particulars, together withpreview_url
(set toFalse
to show off hyperlink previews) andphysique
(the precise textual content content material of the message).
2. Response Messages
Response messages will let you react to a earlier message despatched by a consumer with an emoji. This characteristic lets you acknowledge or reply to messages in a fast and expressive approach.
This is an instance of ship a response message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "response",
"response": {
"message_id": "wamid.HBgLM...",
"emoji": "U0001F600"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier instance.sort
is ready to'response'
to point that you simply’re sending a response message.- The
response
object incorporates themessage_id
(ID of the message you are reacting to) and theemoji
you need to use because the response – on this case, the emoji python code is 😀.
3. Media Messages
Media messages will let you ship numerous kinds of media recordsdata, equivalent to pictures, paperwork, audio, or video, to recipients utilizing the WhatsApp Cloud API.
Change TYPE
with the suitable media sort (picture
, doc
, audio
, or video
), MEDIA_URL
with the media file URL, and CAPTION
with an non-obligatory caption for the media.
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "picture",
"picture": {
"hyperlink": "https://instance.com/picture.jpg",
"caption": "Take a look at this picture!"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.sort
is ready to"picture"
to point that you simply’re sending a picture message.- The
picture
object incorporates thehyperlink
(URL of the picture file) and an non-obligatorycaption
for the picture. - If the
picture
object incorporates an object, use theID
property to point its ID (which you have to generate) or location in your public server.
4. Location Messages
Location messages will let you ship a location’s coordinates to a WhatsApp consumer.
To ship location messages, make a POST
name to /YOUR_PHONE_NUMBER_ID/messages
and fix a message
object with sort=location
. Then, add a location object.
This is an instance of ship a location message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "location",
"location": {
"latitude": LATITUDE,
"longitude": LONGITUDE,
"identify": "LOCATION_NAME",
"tackle": "LOCATION_ADDRESS"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.LATITUDE
andLONGITUDE
are the coordinates of the placement you need to ship.LOCATION_NAME
is the identify of the placement.LOCATION_ADDRESS
is the tackle of the placement.- Set
sort
to"location"
to point that you simply’re sending a location message. It ought to embracelatitude
,longitude
,identify
, andtackle
.
5. Contact Messages
Contact messages will let you ship a contact’s data, equivalent to their identify, telephone quantity, and tackle, to a WhatsApp consumer.
This is an instance of ship a contact message utilizing Python:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "contacts",
"contacts": [
{
"addresses": [
{
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345",
"country": "United States",
"country_code": "US",
"type": "HOME"
}
],
"birthday": "1990-01-01",
"emails": [
{
"email": "[email protected]",
"type": "WORK"
}
],
"identify": {
"formatted_name": "John Doe",
"first_name": "John",
"last_name": "Doe"
},
"org": {
"firm": "Instance Inc.",
"division": "Gross sales",
"title": "Gross sales Supervisor"
},
"telephones": [
{
"phone": "+1 (555) 123-4567",
"type": "CELL",
"wa_id": "15551234567"
}
],
"urls": [
{
"url": "https://www.example.com",
"type": "WORK"
}
]
}
]
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- Set
sort
to"contacts"
to point that you simply’re sending a contact message. contacts
: An array of contact objects containing contact data, equivalent toaddresses
,birthdays
,emails
,names
,org names
,telephone numbers
, andurls
.
6. Interactive Messages
Interactive messages will let you create extra partaking and interactive experiences for customers. The primary kinds of interactive messages are:
a. Checklist Messages
b. Reply Buttons
c. Messages with CTA (Name-to-Motion) URL Buttons
d. Move messages
To ship interactive messages, make a POST name to /YOUR_PHONE_NUMBER_ID/messages and fix a message object with sort=interactive. Then, add an interactive object.
a. Checklist Messages: Checklist messages current an inventory of choices for customers to select from.
This is an instance of ship an inventory message utilizing Python:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "interactive",
"interactive": {
"sort": "listing",
"header": {
"sort": "textual content",
"textual content": "Select an choice:"
},
"physique": {
"textual content": "Please choose one of many following choices:"
},
"footer": {
"textual content": "Thanks to your choice!"
},
"motion": {
"button": "Choose",
"sections": [
{
"title": "Section 1",
"rows": [
{
"id": "option1",
"title": "Option 1",
"description": "This is the first option"
},
{
"id": "option2",
"title": "Option 2",
"description": "This is the second option"
}
]
}
]
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- Set
sort
to"interactive"
to point that you simply’re sending an interactive message. - Set
interactive.sort
to"listing"
to specify that you simply’re sending an inventory message. - The
interactive
object incorporates the main points of the listing message, together with theheader
,physique
,footer
, andmotion
(which defines the listing sections and their corresponding rows).
b. Reply buttons: Reply buttons show as much as three buttons with predefined reply choices.
This is an instance of ship reply buttons utilizing Python:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "interactive",
"interactive": {
"sort": "button",
"physique": {
"textual content": "Choose an choice:"
},
"motion": {
"buttons": [
{
"type": "reply",
"reply": {
"id": "option1",
"title": "Option 1"
}
},
{
"type": "reply",
"reply": {
"id": "option2",
"title": "Option 2"
}
}
]
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- Set
sort
to"interactive"
to point that you simply’re sending an interactive message. - Set
interactive.sort
to"button"
to specify that you simply’re sending reply buttons. - The
interactive
object incorporates the main points of the reply buttons, together with thephysique
(button textual content) andmotion
(which defines the reply buttons and their corresponding IDs and titles).
c. Messages with CTA URL Buttons: They will let you embrace clickable buttons that redirect customers to a selected URL.
This is an instance of ship a message with CTA URL buttons utilizing Python:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "interactive",
"interactive": {
"sort": "button",
"physique": {
"textual content": "Click on the button under:"
},
"motion": {
"buttons": [
{
"type": "url",
"url": "https://example.com",
"title": "Visit Website"
}
]
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- Set
sort
to"interactive"
to point that you simply’re sending an interactive message. - Set
interactive.sort
to"button"
to specify that you simply’re sending CTA URL buttons. - The
interactive
object incorporates the main points of the CTA URL buttons, together with thephysique
(button textual content) andmotion
(which defines the URL buttons and their corresponding URLs and titles).
d. Move Messages: These messages are designed to information customers via a collection of predefined steps or screens. These messages present a extra partaking and structured strategy to work together along with your clients.
This is an instance of ship a Move Message utilizing the WhatsApp Enterprise API:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "interactive",
"interactive": {
"sort": "move",
"header": {
"sort": "textual content",
"textual content": "Welcome to our Move!"
},
"physique": {
"textual content": "Please observe the steps to finish the method."
},
"footer": {
"textual content": "Thanks for utilizing our service."
},
"motion": {
"identify": "move",
"parameters": {
"flow_message_version": "3",
"flow_token": "YOUR_FLOW_TOKEN",
"flow_id": "YOUR_FLOW_ID",
"flow_cta": "Begin",
"flow_action": "navigate",
"flow_action_payload": {
"display screen": "SCREEN_ID",
"knowledge": {
"key1": "value1",
"key2": "value2"
}
}
}
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
interactive.sort and interactive.motion.identify
have to be set to"move"
to point that you simply’re sending a Move Message.interactive.motion.parameters.flow_token
: This property is a singular token generated by the enterprise to function an identifier for the Move.interactive.motion.parameters.flow_id
: This property is a singular ID offered by WhatsApp for the particular Move.interactive.motion.parameters.flow_cta
: This property represents the textual content displayed on the call-to-action (CTA) button, equivalent to “Signup”. The character restrict for this property is 20 characters, and emojis should not allowed.interactive.motion.parameters.flow_action
: This property might be set to both"navigate"
or"data_exchange"
. The default worth is"navigate"
.
7. Sending Quoted Replies
You possibly can ship a message as a reply to a earlier message in a dialog by together with the ID of the earlier message within the context
object of your request payload. This manner, the recipient will obtain the brand new message with a contextual bubble displaying the content material of the message you are replying to.
💡
This is an instance of ship a reply utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"context": {
"message_id": "wamid.HBgLM..."
},
"sort": "textual content",
"textual content": {
"preview_url": False,
"physique": "This can be a reply to a earlier message."
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.MESSAGE_ID_TO_REPLY_TO
is the ID of the message you need to reply to.context
object ought to embrace themessage_id
of the message you need to reply to.- Set the
sort
of message you are sending (on this case,"textual content"
). textual content
object incorporates the textual content message particulars, together withpreview_url
(set tofalse
to show off hyperlink previews) andphysique
(the precise textual content content material of your reply).
➡️
To make use of the code, exchange the placeholders (YOUR_PHONE_NUMBER_ID
, YOUR_ACCESS_TOKEN
, RECIPIENT_PHONE_NUMBER
, MESSAGE_ID_TO_REPLY_TO
) with the suitable values to your use case.
8. Video Messages
Now you can ship video messages to your clients on WhatsApp. The message will show a thumbnail preview of the video together with an non-obligatory caption. When the recipient faucets on the preview, the video is loaded and performed inside WhatsApp.
This is an instance of ship a video message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "video",
"video": {
"hyperlink": "https://instance.com/video.mp4",
"caption": "Take a look at this superb video!"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- The
video
object incorporates thehyperlink
property, enter the URL of the video file hosted in your server right here. Alternatively, you should use theid
property if in case you have beforehand uploaded the video to WhatsApp’s servers utilizing the Media API. - The
caption
property is non-obligatory and permits you to add a caption to the video message. The utmost size of the caption is 1024 characters. - The API helps codecs like 3GPP and MP4, with a most dimension of 16 MB and a video/3gp MIME sort.
- Solely the H.264 video codec and AAC audio codec are supported. The video ought to both have a single audio stream or no audio stream in any respect.
9. Deal with Messages
Deal with messages will let you simply request a supply tackle from WhatsApp customers. This characteristic is presently obtainable just for companies based mostly in Singapore and their Singapore clients, and companies based mostly in India and their India clients.
This is an instance of ship an tackle message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"sort": "interactive",
"interactive": {
"sort": "address_message",
"physique": {
"textual content": "Please present your supply tackle."
},
"motion": {
"identify": "address_message",
"parameters": {
"nation": "IN",
"values": {
"identify": "John Doe",
"phone_number": "+91XXXXXXXXXX"
}
}
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
- Optionally, prefill tackle fields utilizing the
values
parameter. - Set
interactive.sort
to"address_message"
to point that you simply’re sending an tackle message. - Present the message textual content within the
physique.textual content
subject. - Set the
motion.identify
to"address_message"
. - Specify the
nation
parameter with the ISO code of the nation (e.g., “IN” for India, “SG” for Singapore).
When a consumer submits an tackle, you’ll obtain a webhook notification containing the main points of the submitted tackle within the response_json
subject.
Whereas free-form messages supply flexibility, WhatsApp additionally supplies a strategy to ship pre-approved message templates for widespread use circumstances, which we’ll discover under.
Template Messages
WhatsApp message templates are pre-approved message codecs that companies can use to ship notifications or buyer care messages to customers who’ve opted in. These messages can embrace appointment reminders, transport data, situation decision, fee updates, and extra.
Earlier than sending a template message, it’s worthwhile to create a template within the WhatsApp Supervisor:
Step 1: Go to Enterprise Supervisor and choose your online business.
Step 2: Open the Menu and click on on “WhatsApp Supervisor”.
Step 3: Click on on “Handle Message Templates”.
You possibly can create message templates in two methods:
- Use one of many pre-approved templates offered by WhatsApp. You’ll find an inventory of pre-approved templates right here. These templates are prepared to make use of and don’t want approval.
- Create your individual template with the required framework and submit it for approval by Meta. As soon as authorized, you can begin utilizing your customized template.
Let’s discover a couple of examples of sending various kinds of message templates.
1. Catalog Template Messages
Catalog template messages will let you showcase merchandise out of your stock in a WhatsApp message. To ship catalog template messages, it’s worthwhile to have:
- A list uploaded to Meta. You possibly can create it utilizing this information.
- An e-commerce catalog related to your WhatsApp Enterprise Account.
Setup: You will first have to create a catalog template. Observe this information to create a catalog template in minutes.
Request Syntax: To ship a catalog template message, use the WhatsApp Enterprise Telephone Quantity > Messages endpoint.
For example we create a template known as summer_sale_catalog.
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "1605551234",
"sort": "template",
"template": {
"identify": "fashionista_summer_dresses",
"language": {
"code": "en_US"
},
"parts": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Floral Maxi Dress - $79.99"
},
{
"type": "text",
"text": "Bohemian Sundress - $59.99"
},
{
"type": "text",
"text": "Lace Midi Dress - $89.99"
}
]
},
{
"sort": "button",
"sub_type": "CATALOG",
"index": 0,
"parameters": [
{
"type": "action",
"action": {
"thumbnail_product_retailer_id": "SDRSS2023"
}
}
]
}
]
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
- The
template
object specifies the identify of the catalog template (fashionista_summer_dresses
) and the language code (en_US
for English). - The
parts
array incorporates threeparameters
, every representing a unique summer season gown and its worth:- The primary parameter represents the “Floral Maxi Gown” priced at $79.99.
- The second parameter represents the “Bohemian Sundress” priced at $59.99.
- The third parameter represents the “Lace Midi Gown” priced at $89.99.
button
showcases a selected summer season gown from the catalog utilizing thethumbnail_product_retailer_id
set to"SDRSS2023"
.
2. Carousel Template Messages
Carousel templates will let you ship interactive messages with a number of scrollable playing cards, every containing a picture, textual content, and buttons.
Request Syntax: Much like catalog templates, use the WhatsApp Enterprise Telephone Quantity > Messages endpoint.
Beneath is a pattern request for dispatching a carousel template, incorporating a message bubble that wants enter for 2 distinct variables. It contains two carousel playing cards, every that includes a picture header, and necessitates enter for textual content within the physique and variables related to buttons.
Setup: You will have to be sure you create a carousel template first. Observe this information to create a carousel template inside seconds.
Instance Request:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Kind": "software/json"
}
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "1605551234",
"sort": "template",
"template": {
"identify": "fashionista_summer_carousel",
"language": {
"code": "en_US"
},
"parts": [
{
"type": "header",
"parameters": [
{
"type": "text",
"text": "Fashionista Summer Collection"
}
]
},
{
"sort": "physique",
"parameters": [
{
"type": "text",
"text": "Check out our stunning summer dresses:"
}
]
},
{
"sort": "CAROUSEL",
"playing cards": [
{
"card_index": 0,
"components": [
{
"type": "HEADER",
"parameters": [
{
"type": "IMAGE",
"image": {
"id": "1234567890"
}
}
]
},
{
"sort": "BODY",
"parameters": [
{
"type": "TEXT",
"text": "Floral Maxi Dress"
},
{
"type": "TEXT",
"text": "$79.99"
}
]
},
{
"sort": "BUTTON",
"sub_type": "URL",
"index": 0,
"parameters": [
{
"type": "TEXT",
"text": "floral-maxi-dress"
}
]
}
]
},
{
"card_index": 1,
"parts": [
{
"type": "HEADER",
"parameters": [
{
"type": "IMAGE",
"image": {
"id": "0987654321"
}
}
]
},
{
"sort": "BODY",
"parameters": [
{
"type": "TEXT",
"text": "Bohemian Sundress"
},
{
"type": "TEXT",
"text": "$59.99"
}
]
},
{
"sort": "BUTTON",
"sub_type": "URL",
"index": 0,
"parameters": [
{
"type": "TEXT",
"text": "bohemian-sundress"
}
]
}
]
},
{
"card_index": 2,
"parts": [
{
"type": "HEADER",
"parameters": [
{
"type": "IMAGE",
"image": {
"id": "1357924680"
}
}
]
},
{
"sort": "BODY",
"parameters": [
{
"type": "TEXT",
"text": "Lace Midi Dress"
},
{
"type": "TEXT",
"text": "$89.99"
}
]
},
{
"sort": "BUTTON",
"sub_type": "URL",
"index": 0,
"parameters": [
{
"type": "TEXT",
"text": "lace-midi-dress"
}
]
}
]
}
]
}
]
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
- The
template
object specifies the identify of the carousel template ("fashionista_summer_carousel"
) and the language code ("en_US"
for English). - The
parts
array incorporates 4 objects:header
shows the title “Fashionista Summer season Assortment”.physique
supplies an introductory message.CAROUSEL
contains an array ofplaying cards
, every representing a unique summer season gown.
- Every card has a
card_index
and its personal set ofparts
:HEADER
shows a picture of the gown utilizing thepicture
parameter, theBODY
element reveals the identify and worth of the gown, and theBUTTON
contains the URL slug for the particular gown.
For extra data on message templates and their utilization, consult with the WhatsApp Enterprise Platform documentation.
WhatsApp Messaging Workflow
How does all of it translate into a whole messaging workflow? That is what we’ll focus on on this part. Let’s take into account a Whatsapp advertising and marketing marketing campaign for instance. The thought is to attempt to automate it utilizing the Whatsapp API in Python.
To start with, we’ll automate the method of extracting every day leads from HubSpot by way of its API. Automated messages will then be despatched to those leads via WhatsApp’s API. Sounds attention-grabbing, proper? Let’s break it down step-by-step.
Please word that we’ll be utilizing HubSpot fields to create dynamic messages based mostly on numerous attributes.
Step 1: Script to Get Each day Leads from HubSpot
Let’s write a Python script to fetch every day leads from HubSpot utilizing their API. We’ll use a customized subject, like Date_Created
, to filter the leads created inside the final 24 hours.
This script does the next:
- We calculate yesterday’s date utilizing
datetime
andtimedelta
to filter leads created inside the final 24 hours. - We extract the related data (identify, telephone, electronic mail) from the leads and retailer them within the
daily_leads
listing.
Step 2: Sending Automated Messages by way of WhatsApp API
Now that we now have the listing of every day leads, let’s ship them customized messages utilizing the WhatsApp API. We’ll create dynamic messages based mostly on the lead’s data from HubSpot, equivalent to their identify, electronic mail, or another related knowledge.
import requests
import json
# WhatsApp API particulars
WHATSAPP_API_URL = 'https://graph.fb.com/v18.0/YOUR_PHONE_NUMBER_ID/messages'
ACCESS_TOKEN = 'your_whatsapp_access_token'
# Perform to ship message
def send_whatsapp_message(phone_number, message):
headers = {
'Authorization': f'Bearer {ACCESS_TOKEN}',
'Content material-Kind': 'software/json'
}
payload = {
'messaging_product': 'whatsapp',
'recipient_type': 'particular person',
'to': phone_number,
'sort': 'textual content',
'textual content': {'physique': message}
}
response = requests.publish(WHATSAPP_API_URL, headers=headers, json=payload)
return response.json()
# Loop via the leads and ship messages
for lead in daily_leads:
# Customized message based mostly on HubSpot fields
message = f"Good day {lead['name']}, we now have thrilling updates for you! Examine your electronic mail at {lead['email']} for extra particulars."
# Ship message
send_response = send_whatsapp_message(lead['phone'], message)
print(f"Message despatched to {lead['name']}: {send_response}")
On this script:
send_whatsapp_message
takes a telephone quantity and a message as enter. This operate sends the message to the required telephone quantity utilizing the WhatsApp API.- We loop via every lead within the
daily_leads
listing. - For every lead, we create a customized message utilizing the lead’s data from HubSpot, equivalent to their identify and electronic mail.
- We name the
send_whatsapp_message
operate to ship the customized message to the lead’s telephone quantity.
By combining these two scripts, you’ll be able to automate the method of extracting every day leads from HubSpot and sending them customized messages by way of WhatsApp. This workflow helps you have interaction along with your leads promptly and effectively, rising the probabilities of conversion and constructing stronger relationships.
💡
Now, in case you’re seeking to automate this workflow with out writing a line of script, you’ll be able to discover no-code options like Nanonets.
Learn how to automate WhatsApp messaging workflow with Nanonets
With Nanonets, you’ll be able to automate your whole WhatsApp messaging workflow utilizing pure language prompts. Merely describe your workflow necessities in plain English, and Nanonets’ clever workflow builder will create the workflow inside seconds.
To get began, it’s worthwhile to authenticate your HubSpot and WhatsApp accounts inside Nanonets. As soon as that is carried out, you are able to deploy your workflow and make it dwell.
Let’s discover a couple of extra sensible examples of how you should use Nanonets to automate your WhatsApp messaging workflow:
1. Gross sales Lead Notification Workflow
Maintaining observe of each lead and making certain well timed follow-up is usually a daunting job. That is the place this specific workflow turns out to be useful. It permits you to automate lead data seize and use that data to set off notifications throughout totally different platforms.
Apps Concerned: WhatsApp, Salesforce, Google Sheets
Workflow:
- Set off: A possible buyer sends a message to your organization’s WhatsApp quantity expressing curiosity in a services or products.
- Motion 1: The lead’s particulars (identify, contact data, curiosity) are mechanically logged into Salesforce underneath a brand new lead entry.
- Motion 2: The identical data can be added to a Google Sheet that tracks all incoming leads for additional evaluation and follow-up.
- Motion 3: An automatic introductory message created utilizing a WhatsApp Catalog Template is shipped as a WhatsApp reply.
2. Appointment Reminder and Affirmation Workflow
Whenever you’re a service supplier with a packed schedule, conserving observe of every shopper appointment is usually a actual problem. The Appointment Reminder and Affirmation Workflow takes the trouble out of this by automating reminders and confirmations.
Apps Concerned: WhatsApp, Google Calendar, Trello
- Set off: A calendar occasion (appointment) is approaching in Google Calendar (e.g., 24 hours earlier than the scheduled time).
- Motion 1: An automatic reminder message is shipped to the shopper’s WhatsApp quantity, asking for affirmation or rescheduling.
- Motion 2: Upon receiving a affirmation reply from the shopper on WhatsApp, a Trello card is mechanically created or up to date in your online business’s undertaking administration board. It signifies the confirmed appointment.
3. Buyer Assist Ticket and Observe-Up Workflow
Managing a excessive quantity of help requests throughout a number of channels might be overwhelming. The next workflow streamlines the help course of by mechanically creating tickets, notifying related groups, and making certain immediate follow-up.
Apps Concerned: WhatsApp, Zendesk, Slack, Gmail, Trello
- Set off: A buyer sends a message to your online business’s WhatsApp quantity with a selected key phrase current within the message physique (e.g., “assist” or “help”).
- Motion 1: The message triggers the creation of a brand new help ticket in Zendesk.
- Motion 2: The ticket data, together with the client’s authentic message, is mechanically forwarded to a devoted Slack channel (e.g., #customer_support) to your help group to view and focus on.
- Motion 3: An automatic electronic mail is generated and despatched to your help group’s Gmail account. It’s going to embrace the client’s message and get in touch with particulars for follow-up. This electronic mail additionally incorporates a hyperlink to the newly created Zendesk ticket.
- Motion 4: A Trello card is created in a chosen board and listing (e.g., ‘New Tickets’ listing on a ‘Assist’ board), capturing the client’s situation particulars. This card is used for monitoring the progress of the ticket via numerous levels of decision.
- Motion 5: As soon as the help ticket is marked as resolved in Zendesk, an automatic message is shipped to the client via WhatsApp. It’s going to affirm the decision of their situation and asking for any additional help.
Most of these automated messaging workflows could make your online business communication extra environment friendly and efficient. Think about having the ability to reply rapidly, hold observe of vital interactions, and simply handle duties throughout totally different platforms. That is what you are able to do with Nanonets’ no-code workflow automation.