DialogFlow

Build a Dialogflow-WhatsApp Chatbot

There are times where the use of Natural Language Processing (NLP) can positively impact the customer experience. One such channel is the world's most popular messaging app, WhatsApp. Therefore, this article will show you how to build a chatbot using Google’s NLP software Dialogflow in combination with our WhatsApp API.

Build Your Dialogflow Agent

First and foremost, you need to create your Dialogflow agent. In short, “agent” is Dialogflow is, essentially, the bot you are building. We have to start here:

Dialogflow - Google

Next, create the name, pick the time zone and language for your agent. Select your Google Project. It's required. This ID will be used later.

Its main building components are intents which help the agent identify what the user actually wants to do.

Each intent requires training phrases (all the different ways a user can ask for the same thing) and, of course, the responses (always create more variations to keep repeat conversations natural.

When all that is set up, go to the intents section using the menu on the left and start creating the intents.

Create phrases (as many as you can) that users will write to you:

Prepare the answers (preferably a variety of them) that the bot will use in its response:

Connecting integration in dashboard

  1. Connect any number to Whapi.Cloud.

  2. Go to your personal cabinet of Whapi.Cloud to the Integrations section and select DialogFlow there.

  3. Get the token by granting permission to our app to process your bot in DialogFlow.

  4. Use the API documentation to work with DialogFlow.

Warning, this is not a chatbot builder. This is an integration built for developers!

Principle of integration of WhatsApp API and DialogFlow

This integration does not rely on a webhook connection! Instead, it acts as a communication bridge between your WhatsApp channel and your DialogFlow bot:

  1. You receive an incoming message from the client via our webhook.

  2. You forward the message to DialogFlow through a special API request.

  3. DialogFlow generates a reply based on the conversation context.

  4. You take the bot’s reply and send it back to the client using our API.

In other words, DialogFlow only generates the reply — you are fully responsible for delivering the message to the customer via your WhatsApp API channel.

Key points to set up:

Thus, you must build your own lightweight forwarding logic to manage the flow between the client, DialogFlow, and WhatsApp.

API Endpoint

The request will require specifying a Header with the name Authorization and the value "Bearer {your_channel_token}"

Don't forget to use your authorized channel token

Body:

{
    "token": "YOUR_Google_auth_TOKEN",
    "message": "Hello",
    "session": "919984351847", // Use a session to save the context
    "bot_id": "YOUR_DialogFlow_ProjectID"
}

You can pass any value to the “session” parameter, but it makes the most sense to use the phone number of the person you are chatting with. This parameter is necessary to preserve the context in the conversation.

Response by DialogFlow

In response you will receive a result generated by DialogFlow, use it to send a message from the bot to your clients!

Last updated

Was this helpful?