You will be creating a workflow in Twilio which queries the requested email data, according to a given search criteria, and sends their details to WhatsApp.
You will be creating a workflow in Twilio which queries the requested email data, according to a given search criteria, and sends their details to WhatsApp.
Emails have become one of the most used digital communication mediums. But, sad truth, that since they are so aggressively used, it's quite difficult to keep up with them. Moreover, people keep on subscribing to new newsletters every now and then, which also adds to this cause.
So, in order to make our life a little bit easier, we can build a tool which will fetch us the various details from our mail box on query. Twilio is an efficient platform which provides us with the features needed to accomplish this. It's a message, email, call and notification automation tool/platform. We'll be utilizing some of it's features through this project.
Working principle of the project is as follows:
Setup WhatsApp Sandbox in Twilio
Inside Twilio Functions Create New Service -> New Function
Complete the Code in Functions and Save and Deploy them. This will create a REST API endpoint which will be used by WhatsApp Sandbox to operate.
Configure WhatsApp Sandbox with functions URL
Test it on WhatsApp.
You will be creating a workflow in Twilio which queries the requested email data, according to a given search criteria, and sends their details to WhatsApp.
Emails have become one of the most used digital communication mediums. But, sad truth, that since they are so aggressively used, it's quite difficult to keep up with them. Moreover, people keep on subscribing to new newsletters every now and then, which also adds to this cause.
So, in order to make our life a little bit easier, we can build a tool which will fetch us the various details from our mail box on query. Twilio is an efficient platform which provides us with the features needed to accomplish this. It's a message, email, call and notification automation tool/platform. We'll be utilizing some of it's features through this project.
Working principle of the project is as follows:
Setup WhatsApp Sandbox in Twilio
Inside Twilio Functions Create New Service -> New Function
Complete the Code in Functions and Save and Deploy them. This will create a REST API endpoint which will be used by WhatsApp Sandbox to operate.
Configure WhatsApp Sandbox with functions URL
Test it on WhatsApp.
The Twilio Sandbox for WhatsApp is a pre-configured environment available through the Twilio Console in which you can prototype sending outbound messages, replying to incoming messages, and configuring things like message delivery callbacks.
Go to Try WhatsApp
in Programmable Messaging
Section. You should see something like this
After sending "join want-development" to the number, you should receive a confirmation like this
You will see 2 sections. The first is "Send a One-Way WhatsApp Message" and second is "Two-Way Messaging". We highly recommend trying them out and take a look at the code used in those examples. (To skip use Next button).
When you are in Twilio Sandbox Configuration make sure that your WhatsApp number is in Sandbox Participants.
You will need to configure WhatsApp sandbox every 3 days, If you want to avoid this:
It is expected that you'll be able to set up the WhatsApp Sandbox. We highly recommend going through the code for one-way and two-way messaging.
DEPTH_ZERO_SELF_SIGNED_CERT
, there's a work around for that: add tlsOptions: { rejectUnauthorized: false }
property in the config
object along with user, password...etc.App Passwords
(recommended) or disable 2 way auth and turn on less secure access.
App Passwords
.App Passwords
or Less Secure Access
, you must not put password in the main code file (In case your intent is to put code on GitHub or anywhere else publicly).On using your local machine for coding the functions you must see the emails corresponding to the search criteria as output of the function.
Twilio Functions is a serverless environment where developers can directly write code and access the code from an API endpoint for free.
First create a Twilio service in Twilio Functions available under Runtime section in Main Menu.
After creating a Twilio service, you can add functions in it, which will be separate endpoints for the API.
In the image you can see 2 endpoints (/todayisawesome
, /chips
) and 1 asset (Seagull.png
).
You will need to add all the required libraries in Dependencies
from the Settings
section.
We strongly recommend adding sensitive information like passwords into Environment Variables (You need to find out yourself how to access ENV variables in the code).
As you can see the above image that the URL of service is mongoose-8911.twil.io, and suppose the function we created is /chips
, so we need to put mongoose-8911.twil.io/chips in When a message comes in
input box of WhatsApp Sandbox Configuration (Don't forget to SAVE).
Write a code in the function which will send "Hello How are you?" back if the user messages "Hello", other wise send "Not Found" back.
If you are facing any problems, jump to the last task to know how debugging works, then come back.
After completion of this task it is expected to have the functionality that when you send the message "Hello" on WhatsApp to the Twilio number, it sends back "Hello How are you", other wise it sends back "Not Found".
From
, To
and Subject
data, as there is a 1600 character limit on the message text.After successful completion of this task you should be able to get the Email details on your WhatsApp.
You can see the Debugger icon ("Bug") in the top right corner of Twilio function window
It looks like this
You can see Response and Request body of every event.
You are expected to efficiently debug Twilio Functions if required.