Phone Notifications with Twilio
Overview
Even if you push incident alerts to email or Slack, people rarely check work-related messages on their days off.
So, to make alerts harder to miss,
we decided to introduce Twilio for phone notifications.
First, here is a simple walkthrough of how to get started.
- Twilio’s site includes code samples, which made it easy to get up and running.
Steps
1. Access Twilio
Access Twilio from the link below.
2. Sign Up
Enter your name, email, and password (with upper- and lower-case alphanumeric characters),
select what you want to use it for and in which language,
and click “Get Started.”
The Japanese phrase “始めましょう” (Let’s get started) isn’t quite from the user’s point of view, so it feels a bit off.
3. Account Verification
There are two verification methods.
- Have a confirmation code sent to your phone number via SMS
- Receive a call from Twilio at your phone number and enter the confirmation code on the dial pad.
With the latter, a text-to-speech robot from Twilio calls you,
so if you want to try out what the notification feels like, definitely choose the latter.
The intonation isn’t exactly smooth, but it conveys its message with more heart than anyone.
4. Make a Call from Twilio
After account verification, I was taken to the top of the “Programmable Voice” page for the Twilio product.
From the menu, click Tools to go to the Tools page.
Specifying To
In the API Explorer under Voice Calls > Calls > Make a Call,
enter your verified phone number in the required To field.
Note that for Japanese numbers (+81),
a number like 090********
should have its leading 0 removed and +81 added as a prefix,
becoming +8190********, so be careful.
Specifying the URL
In the optional Url field, you can specify, as a URL,
the behavior that occurs when Twilio’s call is received and when a dial key is pressed.
If you don’t have a suitable URL handy,
any arbitrary URL like the following will do.
http:/hogehoge.hogehoge.co.jp
Triggering the Notification
Click the Make Request button at the bottom of the page.
Although it says * Charges will apply, you won’t actually be billed during the Trial.
When you upgrade the same account, you’ll also be charged for the calls you made, so once testing is complete, we recommend obtaining a separate account.
Receiving the Call
You should receive a call from Twilio.
When you enter a dial key, the program specified by the URL runs, but
since we entered an arbitrary URL,
you should hear the notificationAn application error has occurred. Ending the call.
When you actually use this from a program,
the flow is to receive the key input at the specified URL and then control the subsequent behavior.
A Real-World Example
In a project I worked on, I built a mechanism that uses Twilio to report (escalate) incidents detected by Zabbix to the person in charge by phone.
Example) You can implement behavior like the following.
Zabbix detects an incident
↓
Twilio
↓ call
Responder
↓ Responder presses “1”
The program at the specified URL runs
↓ Receives “1” and notifies Zabbix that the incident can be handled
Zabbix (incident in progress)
Zabbix & Twilio Reference
If you follow the zabbix-twilio integration steps on the site above,
after entering a dial key in twilio, the following error occurs and the event cannot be registered.API error -32602: The "user.login" method must be called without the "auth" parameter
This is because the Zabbix_API class in zabbix-twilio.php is outdated.
Download the above, generate the following two files with php build.php,
then call these and change Zabbix_Api to ZabbixApi.
ZabbixApi.class.php
ZabbixApiAbstract.class.php
/var/www/html/zabbix-twilio/zabbix-twilio.php
1 | + require_once 'ZabbixApi.class.php'; |
ZabbixApi also handles the case where Basic authentication is configured.
1 | // Example) |
Test Environment
- Amazon Linux AMI release 2015.09
- Zabbix 2.5 (3.0α)
- PHP 5.6.14
- MySQL 5.5.46
That’s all.

