21min

Twillio API for Whatsapp Plugin

Introduction

On WhatsApp, users message each other using phone numbers. To send and receive messages on WhatsApp using the Twilio Programmable Messaging API you'll need a phone number as well.

Prerequisites

You must have an account with Twilio to interact with the API for Whatsapp. Create you development account at: https://www.twilio.com/

To start using the Twilio API for WhatsApp in production, you need to enable your Twilio numbers for WhatsApp. Head over to request Twilio numbers for Whatsapp: https://www.twilio.com/whatsapp/request-access



Pricing details can be seen here: https://www.twilio.com/whatsapp/pricing/us

Twilio Sandbox for Whatsapp

Twilio Sandbox for WhatsApp allows you to prototype with WhatsApp immediately, without waiting for your Twilio number to be approved for WhatsApp. It is pre-provisioned with a Twilio phone number that is shared across all sandbox users. You can pick from a list of sandbox numbers to use when you activate the sandbox via the WhatsApp console here.

You can use the Twilio sandbox during the development period until your number is approved for Whatsapp. You can find more details on setup here.

Installation Setup

  1. Install plugin Twilio for Whatsapp
Document image





2. Enter your private key into the username and password fields in plugin settings.

Document image

The key could be found in your Twilio Console Dashboard:

Document image



3. After you've installed and set the plugin, create Webhook API for plugin to receive messages to your application and status callback.

Don't forget to save them in the database so that they can be displayed in your application.

You can create API workflows/endpoints after checking the box 'This app exposes a Workflow API' in the API section in the Settings Tab. These workflows are defined in the API Workflow page found in the Application Menu above the Palette.

More info regarding the API: https://bubble.io/reference#API

  • Create an API Workflow:
Document image



  • From settings set option “Parameter definition” to “Detect request data”.
Document image
  • Press the “Detect data” button.
Document image

If the include headers in the detected data is toggled on. Please refer to Image 7 API Workflow Request Data.

  • When the “Detecting Request Data” window pops up, copy the link provided by Bubble, and add it to the Twilio.
Document image



  • In the "Twilio Sandbox for WhatsApp" compartment you can find the Programmable SMS > Sandbox. Put the link of your app there and press the save button.
Document image
  • From your phone send a message to the sandbox number you've set in Twilio, but make sure that your phone number has already been included in the list of numbers in the sandbox.
  • After you receive a response as the example below, delete the word “initialization” from the link added in Twilio and press the save button (the same procedure you do with callback states).
Document image
Document image

In order to save the response to the database, you need to extract the data from either the ”Request Data’s body” or “Request Data’s” .

Document image

Action

Action “Send Message” - For this action it works to find the following parameters:

  • Sidtoken - AccountSid
  • From - Your Twilio for Whatsapp number.
  • To - Whatsapp destination number.
  • Body - Your message
Document image

Twilio WhatsApp - Forward to autopilot

We call this action at APIs Workflow when we receive a message from the Sandbox and send the new autopilot message with parameters that were received from the “Message” API Workflow. - The first parameter is Account ID. - The second parameter Assistant ID , can be found alongside Account ID in the link that Twilio offers, in the Autopilot menu > Channels > WhatsApp.

Document image
Document image



After the Autopilot was activated, Autopilot’s message must be sent back to the user, so that he would see the bot’s reply.

Document image

Changelogs

Update 01.12.2021 - Version 1.4.0

  • Added media field.

Demo to preview the settings



Updated 19 Apr 2022
Did this page help?
Yes
No