Receive phone calls for important emails
In business life, it is very important to read some emails in time. This is especially important when you are monitoring a system / application and need to respond quickly to possible error emails. At this point, sometimes it is not enough just to get the error mail. You also need something to wake you up, like a phone call.
If you work as a part of a DWH team, you may need to check the ETL runs every night.
We can use Twilio and Gmail to convert incoming error emails to phone calls, but how? Here it is.
Set up Twilio
After registering at Twilio and passing a few verification steps, you will see a screen like below. Tip: As you can see in the screenshot, you will have a $ 15.50 balance for opening your first account so you can make your first calls using this balance.
Then by clicking on the “Get a Trial Number” button, you will have a US line that Twilio has reserved for us. You can make the calls through this number.
Okay, we got our number, so what do we do now? We will write an automation application by blending little programming knowledge and twilio documents. Now, go to this link and select your preferred programming language and get the sample code that twilio provides us. I chose Python and added the sample code below. After adding our own number to the “from_” section and the number to be called to the “to” section, we finalize the things that we have to do for Twilio setup.
Remember to add the numbers we want to call as verified phone numbers in here, otherwise you will not be able to call them.
Set up Gmail
We will use the imaplib library to track our emails, but the mail account needs to be less secure to use this library. Tip: I recommend opening a new gmail account that will only be used for phone calls. Then, we add the parameters of the imaplib library to track which e-mail addresses or which topics should be tracked. (We don’t want to be called for every incoming email)
The sample code below checks whether there is a new e-mail from a particular address, if any, the person identified by the twilio number will be called. The caller needs to mark the e-mail as read after taking the necessary action so that twilio does not make a phone call again.
Final
We have completed Gmail and Twilio setup. Now we can add small details.
For example, what if the person in charge did not read the email despite the phone call? We can also create a backup number (another member on the team). This ensures that twilio will make a phone call to that backup number when the person in charge does not answer the phone. Finally we can trigger this script with a task scheduler periodically and control our important emails. Here you can find the final script to cover all these mentioned above.
You can do much more using Twilio and Gmail. I hope this article gives you an insight, thank you for reading.