Call My Nana: Danielle Leong Sets Up Life Saving Voice Reminders For Her Grandma With Twilio

March 26, 2014
Written by

Screen Shot 2014-03-26 at 6.03.39 PM

The following post was written by Danielle Leong Front End Web Developer at Twilio, and wonderful grand-daughter to her dear Grandmother.

My grandmother is 92 years old. She has 6 children and 11 grandchildren (not counting the furry, four-legged ones). She was on the first women’s basketball team in San Francisco, served on the city’s Grand Jury, and was an avid swing dancer. She’s still fiercely independent, and insists on living in her own home without any assistance. She is, in short, a badass.

Being 92 has its drawbacks, though. “I have so many pills to take,” she sighs. “Thirteen pills every day! And one very special one on Sundays.” She shows me three massive, color-coordinated pillboxes, each labeled with the day of the month. “My daughter labels these each week,” she says proudly. She doesn’t remember which ones do what, but she knows it’s important to take them at the proper time each day. But with so many to take, it’s hard not to get overwhelmed and forget to stick to the schedule. Enter Twilio.

IMG_3303.jpg

When I started at Twilio, I thought this would be the perfect opportunity to build a reminder system for my grandma. Using a simple PHP app hosted and scheduled on Heroku, Call My Nana calls my grandma every day at 10am and plays an mp3 of my voice reminding her to take her medication. On Sundays, she hears a slightly different recording to remind her to take her special osteoporosis medication.
The code is adapted from the Twilio Call Request demo found in the docs with some logic to play a slightly different message on Sundays.
Reminder Php

<!--?php // Include the Twilio PHP library require 'Services/Twilio.php'; // Twilio REST API version $version = "2010-04-01"; // Set our Account SID and AuthToken $sid = 'AC9aXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; $token = '8fcXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // A phone number you have previously validated with Twilio $phonenumber = '415XXXXXXX'; // Instantiate a new Twilio Rest Client $client = new Services_Twilio($sid, $token, $version); $url = 'http://example.com/reminder.xml'; if(date('w') == 0) { $url = 'http://example.com/sunday.xml'; } try { // Initiate a new outbound call $call = $client--->account->calls->create(
            $phonenumber, // The number of the phone initiating the call
            '415XXXXXXX', // The number of the phone receiving call
            $url, // The URL Twilio will request when the call is answered
            array('Method' => 'GET')
        );
        echo 'Started call: ' . $call->sid;
    } catch (Exception $e) {
        echo 'Error: ' . $e->getMessage();
    }

 

Reminder.xml

<!--?xml version="1.0" encoding="UTF-8" ?-->

    http://example.com.mp3

 

To run this you’ll also need this handy helper library for Heroku. I used this to help set up a job scheduler on Heroku running my reminder.php code at 10am for a daily call.

IMG_3305.jpg

The app is still running after nearly 650 daily calls. They’ve become the highlight of my grandma’s mornings. “Every morning, your call wakes me up” she giggles to me. “And I remember to take my pills!”

After nearly two years of daily reminders, neither she nor the app have shown any signs of slowing down. Honestly, who has time for that?