Twillio API for Whatsapp Plugin

Demo to preview the settings

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.
Note: 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
Image without caption
2. Enter your private key into the username and password fields in plugin settings.
Image without caption
The key could be found in your Twilio Console Dashboard:
Image without caption
3. After you've installed and set the plugin, create Webhook API for the 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
3.1 Create an API Workflow:
Image without caption
3.2 From settings set option “Parameter definition” to “Detect request data”. Make sure that all three checkboxes are checked off: Expose as a public API workflow, This workflow can be run without authentication, Ignore privacy rules when running the workflow.
Image without caption
3.3 Press the “Detect data” button.
3.4 When the “Detecting Request Data” window pops up, copy the link provided by Bubble, and go to Twilio Dashboard.
Image without caption
3.5 In Dashboard Twilio go to Messaging > Try it out > WhatsApp sandbox settings. Enter the links that lead to your endpoint in Bubble.
Image without caption
3.6 Go to Twilio Sandbox for WhatsApp. To begin testing connect to your sandbox by sending a WhatsApp message from your device to the sandbox number. Send the secret word from WhatsApp to the sandbox number you found on this page. Further, you will have to follow 4 steps.
Image without caption
3.7 After you have finished all 5 steps, go back to page "Twilio Sandbox for WhatsApp" and delete the word “initialize” from the endpoint link, save and go to your bubble backend, where your endpoint was initialized.
Image without caption
Image without caption
Image without caption
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”.
In this case, add the action “Create a new thing” in the backend workflow.
Image without caption

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
Image without caption
Twilio WhatsApp - Forward to autopilot
‼️
Support for Autopilot will be discontinued on February 25, 2023, and the product will no longer be accessible starting August 25, 2023. For full details, including migration options, see https://support.twilio.com/hc/en-us/articles/8279929323547-Autopilot-Support-at-Twilio.
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.
Image without caption
Image without caption
After the Autopilot was activated, Autopilot’s message must be sent back to the user, so that he would see the bot’s reply.
Image without caption

Migrating to a real number

  1. Go to page WhatsApp enabled senders and get approval from Whatsapp
Image without caption
  1. Once you have an approved Whatsapp sender, you can enter the bubble endpoint URL without “initialize” in the Webhook URL for incoming messages.
Image without caption
  1. Replace the sandbox number from the bubble workflow with your real number.
Image without caption
In order to be able to send messages, it is necessary for your user to give his consent, for this it is necessary for the user to send a message to your WhatsApp number.
Now the user will be able to receive messages for 24 hours. We recommend you use message templates
Messages that initiate a conversation with a contact need to be sent in the form of a Message Template. Use WhatsApp Message Templates to initiate promotional and notification campaigns. Send proactive messages via Flows, LiveChat, and Broadcasts.

What's a Message Template

WhatsApp message templates are specific message formats that businesses use to reach contacts:
  1. You want to engage in communication outside the 24-hour messaging window.
  1. Who shared their phone number but never communicated previously with your business account via WhatsApp.
In both cases, make sure the contact gives their prior consent to receive your message in compliance with WhatsApp Business Policy.
Before sending a message, WhatsApp must first approve your Message Template, which can take several minutes. After your submission is approved, you can send messages with no limitations.
Message Templates categories include but are not limited to auto-replies, appointment reminders, shipping information, issue resolution, account and payment updates, etc. Read Creating Message Templates below for a complete list of categories.

Creatine un message template needs:

To create a template, go to Twilio Console > Messaging > Senders > WhatsApp Templates. Click on Submit a message template:
Image without caption
Note: If you are not creating a template for the first time, you will see the New message template button. Click it to create additional templates.
On the next screen, you will be able to fill out the information to submit to WhatsApp. WhatsApp’s team uses the information you submit to approve or reject your template submission.
After you fill out the message template, click Submit Message Template  and the template will be sent to WhatsApp for approval.
All templates must be approved by WhatsApp before you can use them for messaging users.
Image without caption
Note: Once you submit a template, it cannot be edited through the Twilio console.
Please refer to the WhatsApp documentation to learn more about message template formatting and supported languages.

Message template approval criteria

Your template text should make it clear to the end user why they received your message. You can remind them of the reason why they originally granted you permission to send the messages.
For example: “Hi {{1}}, thanks for your order {{2}} placed on {{3}}. Your order has shipped. You can get a tracking update any time by replying TRACK.”

Changelogs

Update 01.12.2021 - Version 1.4.0
  • Added media field.
Update 22.09.2022 - Version 1.5.0
  • Updated plugin actions and deprecated Autopilot.

Helpful?