Skip to main content

WhatsApp

WhatsApp is a freeware, cross-platform messaging and Voice over IP (VoIP) service owned by Facebook, Inc. It allows users to send text messages and voice messages, make voice and video calls, and share images, documents, user locations, and other media.

WhatsApp is one of the most popular messaging apps in the world. It has over 2 billion active users and is available in 120 different languages.

WhatsApp

Before we get started

Before we get started with intergrating WhatsApp, we need a few things:

  • A Sarufi bot. If you don’t have one, you can click here to create one here.
  • A WhatsApp business account
  • An access token from your WhatsApp Cloud API

How to connect to WhatsApp Cloud API

To connect to WhatsApp Cloud API, you need to create a WhatsApp Business account. You can do this by following the instructions in Get started (Cloud API).

Here are steps to follow to get started:

  • Go to your apps.

  • Create an app.

  • Select app type >> Business.

  • You will be required to fill-in basic app information >> click create app button.

  • You will be redirected to the Product section. Add WhatsApp as your product by clicking set up.

    Getting Credentials

This section will guide you on how to obtain whatsapp cloud credentials and Sarufi credentials if you are doing custom deployment. More details on how to create a permanent token and phone number can be found here.

Whatsapp Cloud Credentials

  • On your Meta Developer dashboard, Navigate to Whatsapp-->API setup
  • There, you will see a Temporary Access Token and WhatsApp test number with its Phone Number ID.
  • Finally, verify the number you will be using for testing in the To field.

In this part of integration with WhatsApp, we will walk through the journey using either Sarufi Dashboard or self-served deployment (custom deployment) for integration.

Getting Started

All the steps shown/illustrated here assume you already created a Sarufi account and have a bot created. If you don't have an account, you can create one here.

In this guide, we are going to use Sarufi Dashboard to connect to the WhatsApp Cloud API. Sarufi is a no-code platform that allows you to build chatbots and deploy them to different channels.

  • Log into your Sarufi account.

  • Create a bot. You can follow the instructions here.

  • Navigate to settings in your bot, located at top right corner. Click on Integration >> WhatsApp

  • Add your WhatsApp token and Phone Number ID. Read on how to get WhatsApp credentials here. The system will create a random verification token for you. You can change it if you want to.

    WhatsApp creds

  • Once you have added your WhatsApp token and Phone Number ID, you are ready to deploy your bot to WhatsApp. Click on Save button then Deploy

  • Wait for your job to finish. Once done, you will have a webhook URL presented to you. Copy the URL and follow the steps at Setting up a WhatsApp webhook. You will also need to copy the verification token and paste it in your WhatsApp cloud account.

    WhatsApp webhook url

  • After setting up the webhook, you will need to subscribe to the message topic. Navigate to webhook fields --> click manage to subscribe to the message topic. Read more on webhook field subscription here.

  • When this is done, the bot is ready. Activate your bot in WhatsApp by sending it a text.

  • In case you want to change some of your credentials from WhatsApp Cloud, just update your credentials in your dashboard and click Update button. Then Re-deploy again.

  • You can view your bot logs by clicking View Logs button.

  • You can see the deployed PizzaBot in whatsapp in the GIF below.

Create Permanent token

With just few steps, you will be able to create a permanent token and add your phone number. This token will be used to authorize your bot to send messages on WhatsApp.

  1. Create a System User
  • Navigate to Meta Business Suite --> Your account --> Settings (gear icon)

    Business Settings: Users

  • Navigate to Users --> System Users --> Click on Add

  • Add name of system user --> Set role to Admin --> click Save

    Create System User

  1. Add your App to Assets
  • After creating a system user, navigate to Assign Assets

    Assign Assets

  • Naviagate to Apps --> Select your app --> Grant it full control --> Save changes

    Adding App to assets

  1. Generate Permanent Access Token

    After adding the app to your assets, the next step is to generate a permanent access token. You will have a page that looks like the one below.

    Adding permanent access token

  • Click on Generate New Token --> Select an App --> Select your token expiration time.

  • Add Permisions. Uou need to add the whatsapp_business_management and whatsapp_business_messaging permisions.

  • Click Generate Token --> Copy the token and save it somewhere safe. You will need it in your script.

    Generate permanent token

    You will have time to view your token. So make sure you copy it and save it somewhere safe. It is only shown once.

  1. Add your production phone number

    Do this if you want to use your production phone number. If you want to use your test number, you can skip this step. Follow few steps to step your phone number

  • Naviagate to your Meta Developer Account --> Your app --> WhatsApp --> API setup --> Add phone number

    Add phone number in meta app

  • Provide required details, then verify your phone number by entering the code received.

  • After adding the phone number, scroll up in Meta Developer app dashboard to send and receive section. In the From field, select your phone number.

  • You will have to copy your Phone Number ID and generate a permanent access token then paste them into Sarufi for deployment.

  1. Add payment method

You will need to add a payment method to your Meta app. This is required for you to be able to send messages in WhatsApp. You can add a payment method by navigating to your Meta App dashboard --> Products --> WhatsApp --> API setup then follow the instructions provided.

Finalizing Whatsapp setup

In this section, we are going to finalize our WhatsApp setup. We are going to setup a webhook and subscribe to message topic.

  • Setting up a WhatsApp webhook

    Navigate to your WhatsApp cloud account --> Configuration --> (Webhook) edit --> paste the URL into the Callback URL field.

    You will also need a verification token. Copy the token from either the dashboard or your script's environment variables --> paste into verify token in your whatsapp cloud --> verify and save.

    Webhook setup

  • Webhook field subscription

    After verifing and saving your WhatsApp webook, navigate to webhook fields --> click manage to subscribe to the message topic.

    Webhook fields subscription

Test your WhatsApp chatbot

Let's finish by testing our bot in WhatsApp.

Navigate to your WhatsApp cloud account >> API Setup >> scroll down to a field named To. Click manage phone number to add your phone number. Follow the instructions until the phone number is added.

Click send message to start testing your bot. You will receive a message from your test number which your will use in testing your bot.

Send test message to your number

You can test WhatsApp by sending a message to your bot.

  • Lets test our PizzaBot

    Showcasing the PizzaBot we have been working on, here are the responses of the bot deployed in WhatsApp.

    WhatsApp bot test

What you learned

In this tutorial, you learned how to connect Sarufi to the WhatsApp Cloud API. You also learned how to configure and run WhatsApp.