WhatsApp For Business API 2022 — Complete Guide (Chapiter II)
Everything you need to know about WhatsApp chatbots in one place.
1 — Setup your WhatsApp For Business account
In this tutorial, we will use Twilio as our main provider for this use-case.
The biggest advantage using Twilio is the ability to perform tests using their shared WhatsApp For Business phone number. Once we create our account we will be able to join a channel and start messaging the chatbot.
- Create your first Twilio account https://www.twilio.com/try-twilio
2. Go the console page and click on Create New Account
3. Let’s give a name to our account, I used : “Medium Bot Test”
4. Verify your email or phone number in order to continue the process
5. Answer these questions and make sure you use the same input
Tadaaa!! we have successfully created a free account with $15.50 credits.
6. Activate the sandbox by clicking on confirm
7. Send your first message to the bot
To begin testing, we will send a WhatsApp message from our device to +1 415 523 8886 with code join bow-gift.
8. Channel connection confirmation
2 — Generate your back-end application
The main component of this project is the back-end, it’s where all the processing occures. For this particular exercice, we will use JHipster to generate our back-end application in Spring Boot. It will speed up the development for a first MVP.
JHipster requirements :
- Node.js (LTS)
- Java 11 (JDK)
Make sure you have Node.js and Java 11 already downloaded and installed properly and then go to this tutorial to install JHipster : https://www.jhipster.tech/installation/
We will consider in this tutorial that you have already installed all requirements alongside with JHipster.
Once you launch Node.js command line, create a folder called MediumBotBundle or whatever name that suits you, after that, run this command to start JHipster :
cmd -> jhipster
After that, the generator will ask you about the type of application, select Monolithic application.
After few minutes, the application will be generated and you will be able to start development. I personally use Intellij Community Edition as my main IDE and I highly recommand it for your future projects.
Create a class named “WhatsAppBusinessController” in web.rest package. The purpose of this class is to intercept all requests sent by Twilio to our WebHook when a user communicates with the bot.
Below is the JSON received in our interceptor :
We have 3 main attributes from this JSON message :
- From : The phone number of the sender
- To : The phone number of the receiver
- Body : the content of the message
To be continued..
WhatsApp For Business API 2022 — Complete Guide (Chapiter II) was originally published in Chatbots Life on Medium, where people are continuing the conversation by highlighting and responding to this story.