AI, NLG, and Machine Learning, Bots for Business
Guide to Building WhatsApp Bots
If you’re wondering how to build a WhatsApp bot, this guide has the details. Start using the WhatsApp Business API to build a bot that serves your customers.
April 14, 2021
For businesses eager to interact with customers in innovative ways, 2018 was a banner year. Ever since its creation, WhatsApp has gained in popularity to become the world’s most popular messaging application, so it’s no wonder that in 2018, when the company opened its platform to chatbot developers, it reached an even wider audience. Today, WhatsApp offers bot-building tools that help businesses of all sizes provide customer service, send updates to users, and connect with new audiences.
So, how do you build a WhatsApp bot? How is it different from building a bot for another platform, such as Facebook or Slack? And how are companies using the platform to maintain relationships with users? To learn more about building WhatsApp bots, let’s take a closer look at the platform’s developer tools, features and integrations, and use cases.
Why build a WhatsApp bot?
Except for in a handful of countries (the United States being the most notable), WhatsApp dominates the global messaging landscape in terms of the number of active users. Given the app’s large international footprint, it’s no wonder that Facebook was eager to acquire it in 2014 for $19 billion.
In Europe, South America, Africa, South Asia, and the Middle East, WhatsApp usage is particularly widespread. If your brand is already active in any of these regions, you should consider building WhatsApp bots. After all, it’s where your audience already spends time.
Besides the huge number of potential users, another reason to utilize the platform’s chatbot integration is trust. WhatsApp is a relatively late arrival to the world of chatbots-via-messaging apps, and it seems to be entering the fray with a healthy dose of discretion. For example, instead of making its main API, the WhatsApp Business API, freely available, WhatsApp requires you to go through an application process. In other words, WhatsApp vets you.
That’s a good thing because it shows that WhatsApp cares about users. Theoretically, by filtering out individuals and organizations that might not be a good fit for the platform, WhatsApp provides a markedly user-centered chatbot experience. The platform also prohibits promotional messages, so your audience can rest assured that you’re there to help them with something—not to make a sale.
Because of the thorough WhatsApp process, users know they can trust its bots.
How to build a WhatsApp bot
The first step is to apply for access to the WhatsApp Business API. Although WhatsApp says its API is only available to “medium and large businesses,” the company’s literature isn’t clear on how it defines medium or large. At present, organizations as large as Singapore Airlines and as small as redBus (an Indian transportation booking service that employs 600–700 people) have deployed WhatsApp chatbots. Even if you’re not sure whether you’ll be approved, it’s worth it just to apply.
Following your approval, you need to create a Business Profile. That way, WhatsApp users can get quick access to essential information, such as your locations, hours, and website URL. Publishing the profile also gives you the ability to send and receive messages from customers and to create automated notifications.
Other business steps include adding an eligible phone number and a verified name to your account. These are the non-technical hurdles you have to clear before you get to work on your bot.
First, set up an on-premises environment or opt to run everything through Amazon Web Services (AWS). After completing a few initial steps, such as registering your API client, testing the installation, tweaking your settings, and creating backups, set up your webhooks.
Webhooks are the cogs and gears that churn inside your chatbot. They’re callbacks that are activated by certain kinds of user activity. Whenever a user sends a particular type of message—that is, an event—it triggers one or more webhooks. Your bot then sends the right response, and the user sees the message. WhatsApp developer documentation contains a detailed overview of how webhooks work in the WhatsApp Business API.
If you want your bots to send images or other types of media to users, review the WhatsApp guide to sending media-rich messages. You can also work with WhatsApp Message Templates to standardize certain types of correspondence with customers.
Potential stumbling blocks
Right away, you might wonder why WhatsApp requires you to host its API client with a database. Why not just have an open API to call? This is a frequently asked question that’s covered in the developer documentation.
According to WhatsApp, the company’s encryption requirements specify that all messages are encrypted with sender and receiver keys. Users store these keys in their devices. Businesses store them in—you guessed it!—a database. WhatsApp notes, “Having an API to send messages on will break end-to-end encryption which is against the WhatsApp philosophy.”
For some, the database requirement might present a challenge. That’s especially true if you’re planning to set up the database, maintain it, and scale it in-house. Just be aware of the IT effort that may be involved in this undertaking. Depending on the resources at your disposal, it may not be an issue.
Keep in mind that WhatsApp is just one platform where customers can interact with your brand. To ensure that your bot transcends the limitations of any one platform, consider redirecting or deploying an identical (or similar) bot—not just on another messaging app but on your own domain name.
Messaging applications come and go. They also change over time, and their user bases grow and shrink. WhatsApp might be the perfect place for your chatbot to live today, but that might not always be the case. That’s why it’s a good idea to build your bot on a domain that you always control and where the bot will be available to your audience.
A .BOT domain name, in particular, is the perfect place to host your bot. Customers will always know it’s where your bot lives (.BOT is easy to remember, after all), and they’ll know they can always connect with you there.
How to integrate your bot with WhatsApp
Many WhatsApp chatbot integration frameworks work seamlessly with messaging applications. For example, Google Dialogflow framework integrates with Slack and Facebook Messenger, and the framework documentation breaks down the process of getting your Dialogflow-built bot onto those platforms. Others, such as Amazon Lex and Microsoft Bot Framework, offer similarly straightforward integration options.
WhatsApp, on the other hand, follows a more controlled approach to chatbots than platforms like Facebook Messenger, Kik, and Viber. None of the major frameworks integrate with it directly. To deploy your bot on WhatsApp, choose between these options:
- Build your WhatsApp bot from scratch by following the WhatsApp Business API documentation.
- Build it on a framework and integrate it with WhatsApp using a third-party API.
The first option is pretty self-explanatory. You build and deploy a WhatsApp-specific bot by following WhatsApp-specific documentation. The second option offers more versatility, but it involves a little more effort.
To get a sense of how it might work, consider this WhatsApp bot tutorial from Twilio, which shows you how to build a WhatsApp bot with Dialogflow and then integrate it using the Twilio API for WhatsApp. The process breaks down like this:
1. Gather all of your tools. For the tutorial, Twilio uses a PHP developer environment, as well as Composer, a PHP-dependency-management tool. In the real world, you can create an environment that suits your preferences. Twilio also uses ngrok.
2. Set up your environment and the Twilio API WhatsApp Sandbox. In the sandbox, you can prototype a bot for WhatsApp—even while you’re waiting for approval to access the WhatsApp Business API. Keep in mind that you can only message other users who join your sandbox.
3. Integrate Twilio with Dialogflow. In your Dialogflow account, create a new agent and give it a name. In the tutorial, Twilio shows you how to build a weather bot, so the agent is named weather. Next, in Integrations, type your Twilio credentials. Finally, add your Dialogflow credentials to Twilio in that app’s console.
4.Create your webhook, and add it to Dialogflow. The tutorial provides an example of a webhook in PHP. You can do the same thing using another language in your own developer environment. After that, return to Dialogflow and add the unique URL for your webhook (the tutorial uses ngrok to generate this).
5. Add an intent in Dialogflow. The intent is an indicator of the user’s motivation behind a particular request. One of the advantages of using a true bot-building framework is that your bot can learn user intents, process natural language, and get “smarter” over time. Since the tutorial example is a weather bot, Twilio suggests simple phrases like, “weather in [name of city].”
6.Save and test the webhook. And that’s it! You can ask your bot questions in the Twilio API WhatsApp Sandbox and gauge how well it responds.
This is just how it works in one tool, but the process should give you an idea of what to expect when trying to build your bot on a separate framework.
The Gupshup Smart Messaging API for WhatsApp Business is another option for prototyping bots in a sandbox environment while you wait for WhatsApp approval. Gupshup is also a bot framework, so you can build your bot there, make the most of the framework’s natural language processing (NLP) features, and use the API to build, test, and deploy your bot to WhatsApp.
Getting started with WhatsApp bots
The first step to WhatsApp chatbot integration is to apply for access to the WhatsApp Business API. After that, take a look at the WhatsApp Getting Started guide, which runs through all the business and technical steps involved in creating your bot.
Since Twilio and Gupshup offer options for prototyping before you actually get approved, you can go ahead and start building your bot. If you aren’t granted access to the API, the work you did doesn’t have to be in vain. You can always take your bot to a different channel, so there’s little risk in working with these tools. You can also use the free trial period to build a WhatsApp bot and get some testing out of the way before gaining full access.
Creating a WhatsApp chatbot is fairly simple and has numerous benefits both for your company and your customers. By following the business and development steps outlined in this guide, you can successfully create a chatbot that can be integrated across different platforms. After building and deploying your bot on WhatsApp, you now have a new and effective way to interact with customers and bolster their perception of your brand.