With virtually 3 billion energetic customers worldwide, WhatsApp has grow to be a superb channel for companies seeking to join with their viewers successfully. The WhatsApp Enterprise API takes its performance to the subsequent degree.
The API allows you to ship messages to hundreds of consumers routinely. You’ll be able to ship texts, photographs, movies, and even interactive messages. It is a good way for companies to ship prospects 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 the way to use the WhatsApp API to ship messages. We’ll cowl:
- Establishing your WhatsApp Enterprise Platform
- Getting entry tokens
- Sending various kinds of messages
- Tips on 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 prospects on a big scale. It allows enterprises to shortly provoke conversations, ship notifications about help or purchases, provide personalised providers, and help prospects of their most popular communication channels.
Listed here are the three internet hosting choices out there for the WhatsApp Enterprise API:
- Cloud API: Hosted by Meta, this API affords a simple, maintenance-friendly approach for companies to attach with prospects. It is the popular alternative for many firms as a result of its simplicity, ease of use, and computerized scaling.
- On-Premises API: Companies must host this themselves. This feature offers extra management over the infrastructure however requires extra technical assets and upkeep.
- Enterprise Administration API: Important for managing your WhatsApp Enterprise Account settings, property, and message templates, this API is critical no matter whether or not you select the Cloud API or the On-Premises API.
💡
Do you know? The Cloud API lets you 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 obligatory, you’ll be able to arrange a Meta Enterprise Supervisor to prepare and handle your online business property, together with your WhatsApp Enterprise Account.
You may additionally must acquire a devoted telephone quantity for your online business. Then, use that to create a WhatsApp Enterprise Account. Register the quantity by way of the WhatsApp Enterprise app or the API.
Then, add the WhatsApp product to your app within the Meta Developer Dashboard. It will routinely create a check WhatsApp Enterprise Account, a check enterprise telephone quantity, and a set of pre-approved message templates for testing and improvement functions.
To entry sure options, comparable to increased messaging limits and the power to ship template messages, you have to full the Enterprise Verification course of. You have to submit your online business data for evaluate within the Meta Enterprise Supervisor.
Necessities of WhatsApp Enterprise Administration API
The WhatsApp Enterprise Administration API is a necessary 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, property, and entry tokens.
Entry Tokens
Entry tokens are crucial for authenticating your API requests. They guarantee safe communication between your software and the WhatsApp Enterprise Platform.
The Enterprise Administration API helps three varieties of entry tokens:
- System Consumer Entry Tokens: These tokens signify your online business and do not expire. They’re important for Resolution Companions who share credit score strains with their prospects. There are two varieties of System Consumer tokens:
- Worker System Customers: For restricted entry to particular WhatsApp Enterprise Accounts.
- Admin System Customers: For full entry to all WhatsApp Enterprise Accounts and property.
- Enterprise Integration System Consumer Entry Tokens: These tokens are particular to particular person buyer knowledge and are utilized by Tech Suppliers and Resolution Companions for automated actions with out person enter.
- Consumer Entry Tokens: Typically used for preliminary app testing. They expire shortly and are much less appropriate for ongoing improvement. This token was used within the check message despatched above.
Creating System Customers and producing Entry Tokens
To create a System Consumer 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 Consumer.
- Choose the System Consumer 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 guaranteeing 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 Consumer entry token, it’s good 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 depend 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 maintain your entry tokens safe and by no means share them publicly, as they grant entry to your WhatsApp Enterprise Account.
Understanding entry tokens, the way to create them, and the speed limits will assist you authenticate your requests and handle your WhatsApp Enterprise Account successfully.
Tips on how to Set Up the WhatsApp Cloud API
Companies choose Cloud API over on-premises because it affords a extra simple setup and upkeep course of. Meta hosts the required infrastructure, guaranteeing scalability and reliability. This permits companies to give attention to constructing their functions and buyer experiences slightly 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 kind. 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 may be requested to hyperlink it throughout this course of. If not, you may be guided to create one.
4. Configure your WhatsApp Enterprise Account: As soon as your MBA is linked, you may be taken to the WhatsApp Enterprise Account configuration dashboard.
Right here, you’ll be able to:
- Arrange a check WhatsApp Enterprise Account (free however with utilization limitations)
- Create a check enterprise telephone quantity linked to your WhatsApp Enterprise Account
- Generate pre-approved messaging templates for testing
5. Add a recipient quantity: To ship check messages, you have to add a sound WhatsApp quantity. Go to the App Dashboard, navigate to WhatsApp > API Setup, and below the message-sending part, search for the ‘To’ area to handle your telephone quantity record. Enter a sound WhatsApp quantity and confirm it utilizing the affirmation code despatched through WhatsApp.
6. Ship a check message: Use the pre-approved ‘hello_world’ template to ship a check 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",
"kind": "template",
"template": {
"title": "hello_world",
"language": {
"code": "en_US"
}
}
}
response = requests.submit(url, headers=headers, json=knowledge)
print(response.textual content)
On this instance:
- Be sure your check enterprise quantity is within the ‘From’ area.
- Make sure the recipient’s quantity is chosen within the ‘To’ area. You’ll be able to ship messages to a number of numbers if added.
The command you may use signifies that you just’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 prospects, you’ll be able to add an precise enterprise telephone quantity to the API Setup and create an official WhatsApp Enterprise Account. It will permit you to ship messages to your prospects with out the restrictions of the check account.
Tips on how to Ship Messages Utilizing the WhatsApp Cloud API
The platform additionally helps two varieties of messages: free-form and template messages. Free-form messages permit for extra flexibility however should be despatched inside 24 hours of the shopper’s final message. It could embrace textual content, photographs, 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 prospects. These messages require person consent and approval from the WhatsApp evaluate workforce. They will embrace appointment reminders, delivery data, situation decision, or cost updates.
To ship a message utilizing the WhatsApp Cloud API, it’s good 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 a typical format, with variations relying on the message kind:
{
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "<TO>",
"kind": "<TYPE>",
// Particular payload relying on message kind
}
<TO>
: WhatsApp ID or telephone variety of the recipient (e.g., +16315551234).<TYPE>
: Kind of message (e.g., ‘textual content’, ‘picture’, and so on.).
The response accommodates a message ID, which is useful for sending replies or reactions and checking for unsuccessful requests through 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 the way to 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 essentially the most primary kind of message you’ll be able to ship utilizing the WhatsApp Cloud API. They include plain textual content and may embrace formatting and preview URLs.
Here is an instance of the way to 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",
"kind": "textual content",
"textual content": {
"preview_url": False,
"physique": "Good day, this can be a textual content message from the WhatsApp Cloud API!"
}
}
response = requests.submit(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 in 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.kind
: 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 permit you to react to a earlier message despatched by a person with an emoji. This characteristic allows you to acknowledge or reply to messages in a fast and expressive approach.
Here is an instance of the way to 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",
"kind": "response",
"response": {
"message_id": "wamid.HBgLM...",
"emoji": "U0001F600"
}
}
response = requests.submit(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.kind
is about to'response'
to point that you just’re sending a response message.- The
response
object accommodates themessage_id
(ID of the message you are reacting to) and theemoji
you wish to use because the response – on this case, the emoji python code is 😀.
3. Media Messages
Media messages permit you to ship numerous varieties of media information, comparable to photographs, paperwork, audio, or video, to recipients utilizing the WhatsApp Cloud API.
Exchange TYPE
with the suitable media kind (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",
"kind": "picture",
"picture": {
"hyperlink": "https://instance.com/picture.jpg",
"caption": "Take a look at this picture!"
}
}
response = requests.submit(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.kind
is about to"picture"
to point that you just’re sending a picture message.- The
picture
object accommodates thehyperlink
(URL of the picture file) and an non-obligatorycaption
for the picture. - If the
picture
object accommodates 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 permit you to ship a location’s coordinates to a WhatsApp person.
To ship location messages, make a POST
name to /YOUR_PHONE_NUMBER_ID/messages
and fix a message
object with kind=location
. Then, add a location object.
Here is an instance of the way to 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",
"kind": "location",
"location": {
"latitude": LATITUDE,
"longitude": LONGITUDE,
"title": "LOCATION_NAME",
"handle": "LOCATION_ADDRESS"
}
}
response = requests.submit(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 situation you wish to ship.LOCATION_NAME
is the title of the situation.LOCATION_ADDRESS
is the handle of the situation.- Set
kind
to"location"
to point that you just’re sending a location message. It ought to embracelatitude
,longitude
,title
, andhandle
.
5. Contact Messages
Contact messages permit you to ship a contact’s data, comparable to their title, telephone quantity, and handle, to a WhatsApp person.
Here is an instance of the way to 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",
"kind": "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"
}
],
"title": {
"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.submit(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
kind
to"contacts"
to point that you just’re sending a contact message. contacts
: An array of contact objects containing contact data, comparable toaddresses
,birthdays
,emails
,names
,org names
,telephone numbers
, andurls
.
6. Interactive Messages
Interactive messages permit you to create extra participating and interactive experiences for customers. The primary varieties of interactive messages are:
a. Record Messages
b. Reply Buttons
c. Messages with CTA (Name-to-Motion) URL Buttons
d. Movement messages
To ship interactive messages, make a POST name to /YOUR_PHONE_NUMBER_ID/messages and fix a message object with kind=interactive. Then, add an interactive object.
a. Record Messages: Record messages current an inventory of choices for customers to select from.
Here is an instance of the way to 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",
"kind": "interactive",
"interactive": {
"kind": "record",
"header": {
"kind": "textual content",
"textual content": "Select an possibility:"
},
"physique": {
"textual content": "Please choose one of many following choices:"
},
"footer": {
"textual content": "Thanks in 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.submit(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
kind
to"interactive"
to point that you just’re sending an interactive message. - Set
interactive.kind
to"record"
to specify that you just’re sending an inventory message. - The
interactive
object accommodates the main points of the record message, together with theheader
,physique
,footer
, andmotion
(which defines the record sections and their corresponding rows).
b. Reply buttons: Reply buttons show as much as three buttons with predefined reply choices.
Here is an instance of the way to 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",
"kind": "interactive",
"interactive": {
"kind": "button",
"physique": {
"textual content": "Choose an possibility:"
},
"motion": {
"buttons": [
{
"type": "reply",
"reply": {
"id": "option1",
"title": "Option 1"
}
},
{
"type": "reply",
"reply": {
"id": "option2",
"title": "Option 2"
}
}
]
}
}
}
response = requests.submit(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
kind
to"interactive"
to point that you just’re sending an interactive message. - Set
interactive.kind
to"button"
to specify that you just’re sending reply buttons. - The
interactive
object accommodates 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 permit you to embrace clickable buttons that redirect customers to a particular URL.
Here is an instance of the way to 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",
"kind": "interactive",
"interactive": {
"kind": "button",
"physique": {
"textual content": "Click on the button under:"
},
"motion": {
"buttons": [
{
"type": "url",
"url": "https://example.com",
"title": "Visit Website"
}
]
}
}
}
response = requests.submit(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
kind
to"interactive"
to point that you just’re sending an interactive message. - Set
interactive.kind
to"button"
to specify that you just’re sending CTA URL buttons. - The
interactive
object accommodates 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. Movement Messages: These messages are designed to information customers by way of a collection of predefined steps or screens. These messages present a extra participating and structured approach to work together along with your prospects.
Here is an instance of the way to ship a Movement 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",
"kind": "interactive",
"interactive": {
"kind": "circulation",
"header": {
"kind": "textual content",
"textual content": "Welcome to our Movement!"
},
"physique": {
"textual content": "Please observe the steps to finish the method."
},
"footer": {
"textual content": "Thanks for utilizing our service."
},
"motion": {
"title": "circulation",
"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_ID",
"knowledge": {
"key1": "value1",
"key2": "value2"
}
}
}
}
}
}
response = requests.submit(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
interactive.kind and interactive.motion.title
should be set to"circulation"
to point that you just’re sending a Movement Message.interactive.motion.parameters.flow_token
: This property is a novel token generated by the enterprise to function an identifier for the Movement.interactive.motion.parameters.flow_id
: This property is a novel ID offered by WhatsApp for the particular Movement.interactive.motion.parameters.flow_cta
: This property represents the textual content displayed on the call-to-action (CTA) button, comparable to “Signup”. The character restrict for this property is 20 characters, and emojis usually are not allowed.interactive.motion.parameters.flow_action
: This property may be set to both"navigate"
or"data_exchange"
. The default worth is"navigate"
.
7. Sending Quoted Replies
You’ll be able to 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 fashion, the recipient will obtain the brand new message with a contextual bubble displaying the content material of the message you are replying to.
💡
Here is an instance of the way to 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..."
},
"kind": "textual content",
"textual content": {
"preview_url": False,
"physique": "It is a reply to a earlier message."
}
}
response = requests.submit(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 wish to reply to.context
object ought to embrace themessage_id
of the message you wish to reply to.- Set the
kind
of message you are sending (on this case,"textual content"
). textual content
object accommodates 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 in your use case.
8. Video Messages
Now you can ship video messages to your prospects 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.
Here is an instance of the way to 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",
"kind": "video",
"video": {
"hyperlink": "https://instance.com/video.mp4",
"caption": "Take a look at this superb video!"
}
}
response = requests.submit(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 accommodates thehyperlink
property, enter the URL of the video file hosted in your server right here. Alternatively, you need to 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 lets you 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 kind.
- 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. Tackle Messages
Tackle messages permit you to simply request a supply handle from WhatsApp customers. This characteristic is presently out there just for companies based mostly in Singapore and their Singapore prospects, and companies based mostly in India and their India prospects.
Here is an instance of the way to ship an handle 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",
"kind": "interactive",
"interactive": {
"kind": "address_message",
"physique": {
"textual content": "Please present your supply handle."
},
"motion": {
"title": "address_message",
"parameters": {
"nation": "IN",
"values": {
"title": "John Doe",
"phone_number": "+91XXXXXXXXXX"
}
}
}
}
}
response = requests.submit(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
- Optionally, prefill handle fields utilizing the
values
parameter. - Set
interactive.kind
to"address_message"
to point that you just’re sending an handle message. - Present the message textual content within the
physique.textual content
area. - Set the
motion.title
to"address_message"
. - Specify the
nation
parameter with the ISO code of the nation (e.g., “IN” for India, “SG” for Singapore).
When a person submits an handle, you’ll obtain a webhook notification containing the main points of the submitted handle within the response_json
area.
Whereas free-form messages provide flexibility, WhatsApp additionally offers a approach to ship pre-approved message templates for widespread use instances, 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, delivery data, situation decision, cost updates, and extra.
Earlier than sending a template message, it’s good 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’ll be able to 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 permit you to showcase merchandise out of your stock in a WhatsApp message. To ship catalog template messages, it’s good to have:
- A list uploaded to Meta. You’ll be able to create it utilizing this information.
- An e-commerce catalog linked to your WhatsApp Enterprise Account.
Setup: You may first must create a catalog template. Comply with this information to create a catalog template in minutes.
Request Syntax: To ship a catalog template message, use the WhatsApp Enterprise Cellphone Quantity > Messages endpoint.
As an example we create a template referred to 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",
"kind": "template",
"template": {
"title": "fashionista_summer_dresses",
"language": {
"code": "en_US"
},
"elements": [
{
"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"
}
]
},
{
"kind": "button",
"sub_type": "CATALOG",
"index": 0,
"parameters": [
{
"type": "action",
"action": {
"thumbnail_product_retailer_id": "SDRSS2023"
}
}
]
}
]
}
}
response = requests.submit(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
- The
template
object specifies the title of the catalog template (fashionista_summer_dresses
) and the language code (en_US
for English). - The
elements
array accommodates 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 particular summer season gown from the catalog utilizing thethumbnail_product_retailer_id
set to"SDRSS2023"
.
2. Carousel Template Messages
Carousel templates permit you to 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 Cellphone Quantity > Messages endpoint.
Under 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 may must be sure you create a carousel template first. Comply with 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",
"kind": "template",
"template": {
"title": "fashionista_summer_carousel",
"language": {
"code": "en_US"
},
"elements": [
{
"type": "header",
"parameters": [
{
"type": "text",
"text": "Fashionista Summer Collection"
}
]
},
{
"kind": "physique",
"parameters": [
{
"type": "text",
"text": "Check out our stunning summer dresses:"
}
]
},
{
"kind": "CAROUSEL",
"playing cards": [
{
"card_index": 0,
"components": [
{
"type": "HEADER",
"parameters": [
{
"type": "IMAGE",
"image": {
"id": "1234567890"
}
}
]
},
{
"kind": "BODY",
"parameters": [
{
"type": "TEXT",
"text": "Floral Maxi Dress"
},
{
"type": "TEXT",
"text": "$79.99"
}
]
},
{
"kind": "BUTTON",
"sub_type": "URL",
"index": 0,
"parameters": [
{
"type": "TEXT",
"text": "floral-maxi-dress"
}
]
}
]
},
{
"card_index": 1,
"elements": [
{
"type": "HEADER",
"parameters": [
{
"type": "IMAGE",
"image": {
"id": "0987654321"
}
}
]
},
{
"kind": "BODY",
"parameters": [
{
"type": "TEXT",
"text": "Bohemian Sundress"
},
{
"type": "TEXT",
"text": "$59.99"
}
]
},
{
"kind": "BUTTON",
"sub_type": "URL",
"index": 0,
"parameters": [
{
"type": "TEXT",
"text": "bohemian-sundress"
}
]
}
]
},
{
"card_index": 2,
"elements": [
{
"type": "HEADER",
"parameters": [
{
"type": "IMAGE",
"image": {
"id": "1357924680"
}
}
]
},
{
"kind": "BODY",
"parameters": [
{
"type": "TEXT",
"text": "Lace Midi Dress"
},
{
"type": "TEXT",
"text": "$89.99"
}
]
},
{
"kind": "BUTTON",
"sub_type": "URL",
"index": 0,
"parameters": [
{
"type": "TEXT",
"text": "lace-midi-dress"
}
]
}
]
}
]
}
]
}
}
response = requests.submit(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
- The
template
object specifies the title of the carousel template ("fashionista_summer_carousel"
) and the language code ("en_US"
for English). - The
elements
array accommodates 4 objects:header
shows the title “Fashionista Summer season Assortment”.physique
offers 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 ofelements
:HEADER
shows a picture of the gown utilizing thepicture
parameter, theBODY
element reveals the title and worth of the gown, and theBUTTON
contains the URL slug for the particular gown.
For extra data on message templates and their utilization, confer 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 think about a Whatsapp advertising and marketing marketing campaign for example. The concept is to try to automate it utilizing the Whatsapp API in Python.
To start with, we’ll automate the method of extracting every day leads from HubSpot through its API. Automated messages will then be despatched to those leads by way of WhatsApp’s API. Sounds fascinating, proper? Let’s break it down step-by-step.
Please notice that we’ll be utilizing HubSpot fields to create dynamic messages based mostly on numerous attributes.
Step 1: Script to Get Day by 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 area, 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 (title, telephone, electronic mail) from the leads and retailer them within the
daily_leads
record.
Step 2: Sending Automated Messages through WhatsApp API
Now that we have now the record of every day leads, let’s ship them personalised messages utilizing the WhatsApp API. We’ll create dynamic messages based mostly on the lead’s data from HubSpot, comparable to their title, electronic mail, or some other 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'
# Operate 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,
'kind': 'textual content',
'textual content': {'physique': message}
}
response = requests.submit(WHATSAPP_API_URL, headers=headers, json=payload)
return response.json()
# Loop by way of the leads and ship messages
for lead in daily_leads:
# Customized message based mostly on HubSpot fields
message = f"Good day {lead['name']}, we have now thrilling updates for you! Verify 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 perform sends the message to the required telephone quantity utilizing the WhatsApp API.- We loop by way of every lead within the
daily_leads
record. - For every lead, we create a customized message utilizing the lead’s data from HubSpot, comparable to their title and electronic mail.
- We name the
send_whatsapp_message
perform to ship the personalised 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 personalised messages through WhatsApp. This workflow helps you interact along with your leads promptly and effectively, rising the probabilities of conversion and constructing stronger relationships.
💡
Now, if you happen to’re seeking to automate this workflow with out writing a line of script, you’ll be able to discover no-code options like Nanonets.
Tips on 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 good to authenticate your HubSpot and WhatsApp accounts inside Nanonets. As soon as that is performed, you are able to deploy your workflow and make it stay.
Let’s discover a couple of extra sensible examples of how you need to use Nanonets to automate your WhatsApp messaging workflow:
1. Gross sales Lead Notification Workflow
Maintaining monitor of each lead and guaranteeing well timed follow-up generally is a daunting job. That is the place this specific workflow is useful. It lets you 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 (title, contact data, curiosity) are routinely logged into Salesforce below 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 distributed as a WhatsApp reply.
2. Appointment Reminder and Affirmation Workflow
Whenever you’re a service supplier with a packed schedule, maintaining monitor of every shopper appointment generally is 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 distributed 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 routinely created or up to date in your online business’s mission administration board. It signifies the confirmed appointment.
3. Buyer Assist Ticket and Comply with-Up Workflow
Managing a excessive quantity of help requests throughout a number of channels may be overwhelming. The next workflow streamlines the help course of by routinely creating tickets, notifying related groups, and guaranteeing 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 particular 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 shopper’s unique message, is routinely forwarded to a devoted Slack channel (e.g., #customer_support) in your help workforce to view and focus on.
- Motion 3: An automatic electronic mail is generated and despatched to your help workforce’s Gmail account. It’s going to embrace the shopper’s message and make contact with particulars for follow-up. This electronic mail additionally accommodates a hyperlink to the newly created Zendesk ticket.
- Motion 4: A Trello card is created in a chosen board and record (e.g., ‘New Tickets’ record on a ‘Assist’ board), capturing the shopper’s situation particulars. This card is used for monitoring the progress of the ticket by way of numerous phases of decision.
- Motion 5: As soon as the help ticket is marked as resolved in Zendesk, an automatic message is distributed to the shopper by way of WhatsApp. It’s going to verify the decision of their situation and asking for any additional help.
A majority of these automated messaging workflows could make your online business communication extra environment friendly and efficient. Think about having the ability to reply shortly, maintain monitor of necessary interactions, and simply handle duties throughout totally different platforms. That is what you are able to do with Nanonets’ no-code workflow automation.