WhatsApp For Business API 2022 — Complete Guide (Chapiter II)

WhatsApp For Business API 2022 — Complete Guide (Chapiter II)

Everything you need to know about WhatsApp chatbots in one place.

WhatsApp For Business Guide — Chapiter 2

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.

  1. Create your first Twilio account https://www.twilio.com/try-twilio
Step 1 : account creation page in Twilio

2. Go the console page and click on Create New Account

Step 2 : Create new account

3. Let’s give a name to our account, I used : “Medium Bot Test”

Step 3 : name your project

4. Verify your email or phone number in order to continue the process

Step 4 : verify your identity

5. Answer these questions and make sure you use the same input

Step 5 : fill out the questions

Tadaaa!! we have successfully created a free account with $15.50 credits.

6. Activate the sandbox by clicking on confirm

Successful account creation

7. Send your first message to the bot

Twilio Sandbox for WhatsApp — send your first message

To begin testing, we will send a WhatsApp message from our device to +1 415 523 8886 with code join bow-gift.

Joining private channel in WhatsApp bot

8. Channel connection confirmation

Message received on Sandbox successfully.

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.

Initiate project in JHipster via CMD

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.

Important : make sure you select the same options as shown in the image

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.

JHipster project structure

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 :

JSON structure of Twilio message

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.