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 you WhatsApp, We'll 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 the Get started-cloud API.

Here are steps to follow for you to get started:

  • Go to your apps.

  • Create an app.

  • Select app type >> Business.

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

  • You will be redirected to 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 permanet token and phone number can be found at creating permanet token

Whatsapp cloud creds

  • On your Meta Developer dashboard, Navigate to Whatsapp-->API setup
  • Right there you will see a your Tempoarary Access Token and WhatsApp test number with its Phone number ID.
  • Lastly verify the number you will be using for testing on 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 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 creds. The system will create random verify 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 simple steps at Setting 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 webhook, you will need to subscribe to message topic. Navigate to webhook fields --> click manage to subscribe to message topic. Read on webhook field subscription.

  • When done ,you are good to go... fire up your bot in whatsapp by sending 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 Pizza bot 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 to whatsapp.

  1. Create System user
  • Navigate to Meta business suite --> Your account --> Setting gear icon

    Business settings: Users

  • Navigate to users --> system users --> Click on Add --> Read policy(if it pops up)

  • Add name of system user --> Set role to admin --> click save

    Create system user

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

    Assign Assets

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

    Adding App to assets

  1. Generate Permanent Access token

    After adding app to your assets, the next step is to generate 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. Basically you need to add 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 filling in the code sent.

  • After adding 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 phone number ID and generate permanent acess token then paste them to sarufi for deployment.

  1. Add payment method

You will need to add payment method to your meta app. This is required for you to be able to send messages to whatsapp. You can add payment method by following the steps by navigating to your meta App dashboard --> Products --> Whatsapp --> API setup then follow instructions provided

Finalizing Whatsapp set-up

In this section, we are going to finalize our whatsapp set-up. We are going to set webhook and subscribe to message topic.

  • Setting whatsapp webhook

    Navigate to your whatsapp cloud account --> configuration -->(Webhook) edit --> then paste the url into callback url.

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

    Web hook setup

  • Webhook field subscription

    After veryfing and saving whatsapp webook, navigate to webhook fields --> click manage to subscribe to message topic.

    Webhook fields subscription

Test Your WhatsApp ChatBot

Lets finish up by testing our bot in whatsapp.

Navigate to your whatsapp cloud account >> API setup >> scroll down to a field written To. Click manage phone number to add you phone number. Follow instructions till you finish

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

    With the Pizza bot we have been working through, here is the bot responses deployed in whatsapp.

    WhatsApp bot test

What you learned

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