How to use twilio whatsapp api
Overview of the WhatsApp Business API with Twilio
Twilio is launching a new Console. Some screenshots on this page may show the Legacy Console and therefore may no longer be accurate. We are working to update all screenshots to reflect the new Console experience. Learn more about the new Console.
Twilio's support for the WhatsApp Business API is now Generally Available! Read more in the Changelog.
WhatsApp is the most popular OTT app in many parts of the world. With the WhatsApp Business API with Twilio, you can reach more than 1.5 billion WhatsApp users. You can send notifications, have two-way conversations, or build chatbots. If you're trying to reach – and better converse with – users in LATAM, EMEA, and APAC, you need to consider using WhatsApp.
WhatsApp requires that your application implement explicit user opt-ins to deliver messages over WhatsApp. You may gather this opt-in information either via a web page or a mobile app, such as during your application's sign-up flow, in your application's account settings, via SMS, etc.
Please note that sending messages to end users without an opt-in may result in users blocking your business as well as the suspension of your WhatsApp Business account.
On WhatsApp, users message each other using phone numbers. To send and receive WhatsApp messages using the Twilio Programmable Messaging API, you'll need a phone number as well. The Twilio API addresses WhatsApp users and your numbers, using the following prefixed address format:
whatsapp:<E.164 formatted phone number>
(E.164 is an international telephone number format; you will see it often in the strings that represent Twilio phone numbers.)
Enabling WhatsApp with a Twilio Number
To use WhatsApp messaging in production apps, you must enable WhatsApp on your Twilio number. WhatsApp is currently opening up this access in a limited availability program. This means that WhatsApp approval is required for all customers who wish to create their own profiles.
For a step-by-step walkthrough of the process, visit our guide to Connecting your Twilio Number to your WhatsApp Business Profile. One your request has been submitted and approved, you will be able to select your Twilio numbers and apply for them to be enabled in WhatsApp.
For information about using a non-Twilio number with WhatsApp, check out our Support guide Can I activate my own phone number for WhatsApp on Twilio?
Submit your Facebook Business Manager Account
WhatsApp uses your Facebook Business Manager account to identify your business and associate your phone numbers with it.
You must get approval to enable your Twilio numbers for WhatsApp. Next, you will need to provide Twilio with your Facebook Business Manager ID. If you do not already have a Facebook Business Manager account, follow Facebook's instructions to create one.
Your Facebook Business Manager ID can be found in the "Business Info" section under Business Settings.
Manage and Configure Your WhatsApp-enabled Twilio Numbers
You can request to configure up to 25 new numbers for WhatsApp. To manage your own templates and your WhatsApp profile, go to Messaging > Senders > WhatsApp Senders in the Console. Here, you can see the list of your WhatsApp-enabled Twilio phone numbers (senders) as well as any templates that you have submitted for approval.
Clicking on a specific Sender (WhatsApp-enabled phone number) takes you to its specific Configuration page. This includes the Endpoint configuration section, where you can specify what action Twilio should take when it receives a WhatsApp message at this number. You can configure this sender as part of a Messaging Service or with an individual webhook URL.
WhatsApp requires that business-initiated notifications sent by your application be templated and pre-registered, with the exception of messages sent as a reply to a user-initiated message. (See Conversational Messaging on WhatsApp for more details).
To learn more, consult our Guide to Sending WhatsApp Notifications Using Message Templates.
To have 2-way conversations with end users, you need to be able to receive messages from them. Users can send your business messages either directly or in response to a templated notification.
How to Initiate WhatsApp "24-hour Session"
A WhatsApp session begins when a user sends a message to your app. Sessions are valid for 24 hours after the most recently received message, during which you can communicate with customers using free-form messages. To send a message outside the 24-hour session window, you must use a pre-approved message template. (See our Guide to WhatsApp Message Templates).
Configuring Inbound Message Webhooks
When customers send you a WhatsApp message, Twilio sends a webhook (a request to a URL that you specify) to your application. You can configure the URL to which Twilio sends a webhook when it receives inbound messages in the Twilio Console:
- on the Sandbox page
- on the page for WhatsApp-enabled numbers
- under the "Integration" section of your settings for a specific Messaging Service (Under the Messaging Services section of the Console)
Configuring Fallback URLs for your WhatsApp-enabled Senders
Optionally, you can configure a Fallback URL in the same place that you set your default webhook URL. If a fatal error occurs while making a request to your primary webhook URL, Twilio "falls back" to this secondary fallback URL.
When making the request to your fallback URL, Twilio also submits the ErrorCode
and ErrorUrl
parameters, indicating the error code of the failure and the URL for which the failure occurred.
Configuring Inbound Message Webhooks for Twilio Sandbox for WhatsApp | Configuring Inbound Message webhooks for your WhatsApp enabled Twilio number |
For details on the data provided in the request that Twilio makes to your application (via the webhook URL), read more about Twilio's HTTP Requests to Your a Application.
Receiving a WhatsApp Message
The webhook for inbound messages uses the same format as incoming SMS and MMS messages, with the exception that To
and From
addresses will be set to WhatsApp addresses (whatsapp:<your E. 164 number>
and whatsapp:<User's E.164 phone number>
), respectively.
Incoming messages may include text or media. The Body
field contains the message text, and the MediaUrl0
field contains a link to the media file. You can learn how to download incoming media included in a message in the Receive and Download Images on Incoming MMS Messages tutorial. Supported media include images (JPG, JPEG, PNG), audio files, and PDF files, with a size limit of 16MB per message.
Responding to Incoming Messages with TwiML
WhatsApp incoming messages are fully supported by TwiML, allowing you to seamlessly use your existing SMS app with WhatsApp. For more information, check out Documentation on How to Use TwiML.
Sending a Freeform WhatsApp Message Using the API
Within a WhatsApp session, you can send freeform messages using the Programmable Messaging API. Freeform messages may include text or media.
Web links in Freeform WhatsApp Messages
Freeform WhatsApp messages that include web links will display a web page snippet preview when received on the WhatsApp client.
You are viewing an outdated version of this SDK.
Show sample response
Example JSON response
Show code
Send a freeform message within the 24-hour session
Send an outbound freeform WhatsApp Message
Send a freeform message within the 24-hour session
You are viewing an outdated version of this SDK.
Show sample response
Example JSON response
Show code
Send a freeform media message within the 24-hour session
Send a freeform WhatsApp message with media
Send a freeform media message within the 24-hour session
To receive real-time status updates for outbound messages, you can choose to set a Status Callback URL. Twilio sends a request to this URL each time your message status changes to one of the following: queued
, failed
, sent
, delivered
, read
.
You can set the Status Callback URL in the Console, or when you send an individual outbound message, by including the StatusCallback
parameter. You can set this in different parts of the Twilio Console depending on your messaging set-up:
- Set the status callback URL for the WhatsApp Sandbox
- Set the status callback for an individual WhatsApp Sender
- Set the status callback for a Messaging Service (under the Integration settings for a specific Messaging Service)
When you set the Status Callback URL, Twilio sends a POST request to that URL, including the MessageSid
(the Message's Unique identifier) along with the other standard request parameters as well as MessageStatus
and ErrorCode
.
The parameters Twilio sends to your callback URL include all standard request parameters, as well as some unique messaging parameters. You can see the full list of parameters in the API Reference for the Message Resource.
Rate this page:1 2 3 4 5
Need some help?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.
- Terms of Service
- Privacy Policy
- Copyright © 2022 Twilio Inc.
The WhatsApp Business API with Twilio
Twilio's support for the WhatsApp Business API is now Generally Available! Read more in the Changelog.
Using the WhatsApp Business API with Twilio, you can send and receive messages to WhatsApp users using the same Twilio Messaging APIs you already know and enjoy. Dive into the Twilio SDKs and helper libraries, see our quickstart and API reference docs, read through guides on templates and Twilio phone numbers, and find the sample code you'll need.
Not a developer? See our Whatsapp product page.
To sign up for a WhatsApp Sender, head over to the Messaging section of the Twilio Console. Then navigate to Senders > WhatsApp senders on the Console side menu. Once there, you'll see one of the following options to begin the sign up process:
- Select a phone number to register: You can select an existing Twilio phone number or bring your own number and begin the registration process using the WhatsApp Self Sign-up guide. Note: This process is fully self service.
- Submit your first WhatsApp Sender: Click the "Submit a WhatsApp Sender" button to start the standard WhatsApp submission process. Note: It takes around 2-5 business days for approval from WhatsApp.
Once you have an approved WhatsApp Sender, continue on below to to get started with a WhatsApp Quickstart in the language of your choice!
We suggest starting with the WhatsApp quickstart in your language of choice below to learn how to send and receive WhatsApp messages using the Twilio Programmable Messaging API.
Quickstarts
Our WhatsApp Quickstart shows you a common WhatsApp integration using six popular web languages as well as cURL. If you're looking for the fastest way to test the ins and outs of working with WhatsApp with Twilio Programmable Messaging, try the quickstart in your language of choice:
Can't decide? Head to the WhatsApp Quickstart overview for your guide to the guides!
Check out the Programmable Messaging API Reference
Our API Reference and overview has setup hints as well as descriptions of features that come with WhatsApp, such as formatting, location messages, and templates.
From there, learn how to send messages with the Programmable Messaging Message Resource. Sending WhatsApp messages is part of Twilio Programmable Messaging, so you'll use the same API calls to send SMS or MMS messages.
Suggested guides and tutorials for one-way messaging with WhatsApp and Twilio
Our WhatsApp Guides provide useful information for getting started with WhatsApp and Twilio, such as using templates for notifications, key concepts, and how to register your WhatsApp Business Profile using Twilio.
If you want to send One-Time-Passcodes (OTPs) via WhatsApp, check-out our Verify WhatsApp API instead. This purpose-built API lets you start sending OTPs right away, without throttling and other restrictions that make successful implementation difficult or even impossible.
If you're looking to build conversational or back-and-forth messaging with WhatsApp, we recommend the Twilio Conversations API. With Twilio Conversations, you can build two-way messaging experiences that are cross-channel. So in addition to building WhatsApp-only Conversations, you can also build one customer experience with WhatsApp, SMS, MMS, and browser-based or mobile chat messages.
Suggested guides and tutorials for conversational messaging with WhatsApp and Twilio
The following guides will help you get accustomed to building conversational messaging with WhatsApp and Twilio
The quickest way to add WhatsApp integration to your web app with the Twilio APIs is using one of our Helper Libraries. We have helper libraries to assist you with common web languages – get from 0 to 200 OK
in the minimum of time.
Got questions about WhatsApp or the integration with Twilio? You aren't alone – see the most commonly asked questions we field as well as a peppering of our best practices for your own Twilio API for WhatsApp integration.
- Twilio API for WhatsApp FAQ and Best Practices
1 2 3 4 5
- Terms of Service
- Privacy Policy
- Copyright © 2022 Twilio Inc.
Start messaging in 5 minutes [Jul 2021]
Before you can send messages to your customers using the Twilio WhatsApp API, you need to connect it to the mailbox. In this article, we will tell you why you should use respond.io as your Twilio WhatsApp mailbox. We will discuss how the Twilio WhatsApp integration with respond.io works. You'll learn how to reply to WhatsApp messages from the mobile app, import WhatsApp contacts, run WhatsApp Click-to-Chat Ads, connect with leads, assign contacts to agents, and send proactive notifications.
Twilio WhatsApp Inbox: Why you should use Respond.io
In this section, we will discuss how to start messaging using the Twilio WhatsApp API. Since the API is just a pipe passing information to and from the WhatsApp network, it does not have a messaging interface.
Why do you need Twilio WhatsApp Inbox
This means that you can't easily reply to WhatsApp messages unless you connect your WhatsApp API account to a third party WhatsApp Inbox like respond.io.
You may want to connect your Twilio WhatsApp API account to your CRM company in the same way as you do with email. While regular CRMs like Hubspot or Salesforce are great for managing customer information, they lack the corresponding messaging features.
Twilio WhatsApp Inbox helps manage messaging conversationsBecause of this, most agents prefer to send and receive emails directly from Gmail or Outlook, even if their email is connected to CRM.
Unlike CRM, Twilio WhatsApp Inbox, like respond. io, is designed to manage messaging. Respond.io comes with full-fledged messaging features such as comments and snippets, allowing agents to collaborate and respond faster.
Twilio WhatsApp Inbox is great for messaging with customers via WhatsApp, but what about other channels?
Delight your customers with omnichannel opportunities
Omnichannel gives customers the opportunity to contact you in any way they want, which increases customer loyalty. Here are some examples of how an omnichannel approach makes life easier for your customers.
Some channels work better under certain conditions. For example, at work, your customers may prefer to contact you via email rather than WhatsApp. By offering email as an alternative communication channel, you are on your way to winning loyal customers!
Here's another case where multi-channel capabilities come in handy. WhatsApp might be great for customers on the go, but not for those on your site. Offering web chat in addition to WhatsApp makes it easier for customers to contact you wherever they are.
Difficulties in moving to omnichannelAn omnichannel approach makes life easier for your customers, but increases the burden on agents and merchants. They have to juggle different platforms, respond to clients on one platform while checking incoming messages on another platform.
The multichannel approach has another drawback. When someone is reaching out to you on two different platforms, it's hard to understand the context of the customer because the conversation becomes isolated.
Imagine this scenario: a salesperson had a long WhatsApp conversation with a customer and promised him a special deal. But when a customer enters a web chat, it looks like a new conversation for a help desk agent who doesn't know anything about the deal.
Respond.io helps overcome these issues by allowing you to easily implement omnichannel and better understand the customer context with Contact Merge.
Simplify your agent's life with Omnichannel
If you want to use multiple channels but don't want to overwhelm your sales and support team, Respond. io is the perfect multi-channel solution. It allows you to manage conversations from multiple channels on one unified platform.
Respond.io supports all popular channels, including major apps like WhatsApp, Messenger and Instagram. It also supports niche messaging apps like Telegram, Viber, WeChat and LINE which are popular in some countries.
Respond.io supports all popular channelsAnd we mentioned that respond.io supports email and web chat. You can manage email and web chat conversations on respond.io along with messaging apps as part of the omnichannel strategy.
For a truly multichannel experience, consider Contact Merge. Contact Merge merges chats with the same customer across multiple channels, giving you a clearer picture of what's going on.
Break down loops and understand customer context with Contact Merge
By providing context for conversations, Contact Merge enables your help desk to respond more empathetically to customer requests. Agents can simply scroll up to view conversations that have taken place on different channels.
Using Contact Merge, the help desk agent in the previous example can easily figure out the promise made to the customer by the seller via WhatsApp and give the correct answer.
Contact Merge helps you understand the context of the clientMerge contacts on respond.io is easy, you can merge chats with a contact from different channels into one single profile and conversation with just a few clicks. Connect your Twilio WhatsApp API to respond.io to experience contact merging. To get started, create a free respond.io account.
Twilio WhatsApp Integration: Connecting Twilio WhatsApp API to Respond.io
After creating the respond.io account, it's time to connect the Twilio WhatsApp API to respond.io.
1. Navigate to Settings > Channels. Then click Add Channel.
Setting up Respond.io with Twilio WhatsApp integration: Channel module2. Select WhatsApp and click Next.
Connecting WhatsApp to Respond.io3. Click Twilio and click Next.
Connect Twilio API for WhatsApp to Respond.io4. Fill in account SID and Auth Token.
Filling in the Account ID and Auth TokenYou can find your account SID and Auth Token in the Twilio dashboard. Once completed, click Next.
5. Add WhatsApp enabled number.
Adding a WhatsApp-enabled numberTo access your WhatsApp-enabled number, go to your Twilio dashboard and click the More products and services button in the left pane. Then go to Programmable Messaging > Senders > WhatsApp Senders > Configure.
6. Copy the URLs from the platform and add them to the appropriate fields. When finished, click the configure button.
Twilio WhatsApp number setupFinally, click the Done button on our platform to complete the setup. You are now ready to use respond.io with Twilio WhatsApp Integration!
Respond.
io with Twilio WhatsApp integration: 6 quick wins to get startedRespond.io with Twilio WhatsApp integration suits all use cases and workflows. However, we'll start with six quick steps you can take to get the most out of your Twilio WhatsApp Inbox.
1. Import or sync WhatsApp contacts to Respond.io using Twilio WhatsApp Integration
Whether you want to contact a prospect or send proactive notifications to your customers, the first step to using Twilio WhatsApp Inbox is always importing contacts.
Importing WhatsApp contacts into Respond.ioImporting contacts into respond.io is a breeze because you can import one or more contacts by uploading a CSV file. You can even sync contacts on the fly using the Contacts API. After that, you can connect to your contacts. If you want to connect with more customers, consider Click-to-WhatsApp advertising.
2. Launch a WhatsApp Marketing Campaign with Click-to-WhatsApp Ads
Click-to-WhatsApp ads allow you to connect with potential buyers without having to ask for their contact information. Clicking on a Click-to-WhatsApp ad takes potential users to a WhatsApp conversation. You can send them a reply message if they sent the first message.
How Click-to-WhatsApp advertising worksWhatsApp campaigns will inevitably lead to an increase in incoming message traffic, and it will not be easy to process a large volume of messages in an organized manner. This is where contact assignment comes in.
3. Assigning Contacts to Multiple Agents
Assigning contacts helps your sales team stay organized even with a large number of incoming messages. There are two ways to assign contacts in respond.io: selection and automatic assignment.
Assign contacts to multiple agentsThe Picking method is great for small companies. It allows agents to manually assign snooze contacts to themselves or other people. If you're bombarded with messages, turn on the "Auto-assign" and "Assign only to online users" options to ensure a quick response.
If you have a lot of site visitors, you can set up a contact form and use Twilio WhatsApp Inbox to contact them.
4. Reach out to potential customers who have completed the contact form
Whatsapp is an effective way to reach out to potential customers who have completed the contact form. They are more likely to respond because they first expressed their interest by filling out their details. You can start a WhatsApp chat by sending a template message.
Reaching out to potential customers who filled out the contact formBut first you need to create a Template message in Twilio. Once approved, import the Message Template into respond.io and you're ready to send your first message to potential customers.
You can continue the conversation if the customers answer. Sales staff may not be able to respond immediately as they are not always at their desk. We've created a mobile app for your sales force to respond to messages on the go.
5. Reply to incoming messages from the mobile app
The respond.io mobile app allows you to reply to incoming messages on the go. It includes Dashboard, Contacts, Messages & Settings modules, making it easy to reply to messages and add team members right from the app.
Sending WhatsApp messages with Twilio from the mobile appYou will receive a new notification each time a new message arrives. Thanks to push notifications, agents will not miss a single message, even when they are away from their workplace. Download apps for Android and iOS from Google Play Store and Apple App Store.
In addition to 1:1 communication, Twilio WhatsApp Inbox also allows you to send messages in bulk. This is useful for sending important updates, such as scheduled maintenance announcements.
6. Sending proactive notifications with Twilio WhatsApp Inbox
WhatsApp notifications are more likely to be read because they trigger push notifications that are hard to ignore. Respond.io allows you to schedule notifications and even select an audience to send notifications to.
Sending WhatsApp notifications with Respond. io with Twilio WhatsApp integrationYou must obtain consent from your customers before sending WhatsApp notifications. Clients can block you if you spam them with unwanted messages, which will affect your Quality Score.
Further reading
This is how respond.io can be used with the Twilio WhatsApp Integration. If you're curious about how other companies sell, support, and market WhatsApp, we encourage you to read these three articles.
- 7 Ways Companies Close Whatsapp Sales
- 7 Ways Companies Use Whatsapp for Customer Service
- 12 Ways Companies Use Whatsapp Marketing
Twilio Integration (WhatsApp)
Twilio is a service with many features, including being the official WhatsApp Business API provider.
Setting up WhatsApp Business in Twilio
If you don't have a Twilio account yet, please review the pricing and WhatsApp Business API information before signing up.
After registration, you need to decide which number to connect to WhatsApp Business, and there are two options:
-
if you have your own number, activate it to work with WhatsApp through Twilio;
-
if you don't have a number, get a ready-made number from Twilio (the list of countries whose numbers are available; there are no numbers with the code "+7" for the Russian Federation), but first, read the article to understand which numbers are suitable for connecting to WhatsApp Business.
The next step is to request access to the WhatsApp Business API and connect WhatsApp Business to Twilio.
Connecting to Omnidesk
subsection "Integrations" → block "Other integrations" .
2. In the Twilio console, follow the path: Messaging → Senders → WhatsApp senders → Edit sender . On the page that opens, in block Endpoint configuration , select the option use webhooks and in all fields specify the Omnidesk Webhook URL from the integration connection form.
3. In the integration connection form in Omnidesk, specify the phone number configured in Twilio as WhatsApp Sender, select the default group that will receive calls from this number, and click the "Connect" button.
Important points
a. WhatsApp has a "maintenance window" which is 24 hours, meaning there is always a 24 hour countdown from the user's last message, during which you can send a reply. If more than 24 hours have passed since the user's last message, WhatsApp will block your response and you will only be able to send the user a paid template message agreed with WhatsApp.
b. WhatsApp Business accounts cannot be added to group chats.
c. The limit for receiving files from users is 25 MB. The limit for sending files by employees from Omnidesk is 16 MB (the limit of Twilio itself). If you need to send larger files, you can connect integration with cloud storages.
In order for WhatsApp users to see your company name in their chat list instead of just a phone number, you need to get a WhatsApp Official Business Account.
Correspondence
The general list of calls displays only those calls for which asynchronous communication is in progress - each side responds when it can. Chats in real time are displayed separately and processed through a special interface.
When a new chat arrives (WhatsApp, Telegram, Viber, Skype, Slack, VK messages, FB messages, online chat), a green icon appears in the upper right corner of the employee's account. Incoming chats or new replies in chats are displayed through it:
In the general list of calls, chats are also displayed, but not immediately, but after they are completed:
-
if the employee ends the chat on his own using the “end chat” link in the lower right corner;
-
after 10 minutes (default value) of inactivity on both sides;
-
when one of the automation rules is triggered, in which there is an action "end chat and set status" (for example, if you do not plan to quickly respond to chats and want to immediately see chats in the general list).
We have deliberately separated synchronous and asynchronous communication, because in order to provide first-class support, it is necessary to take into account the specifics and expectations of customers, depending on the type of channel through which communication is carried out.