Twilio SMS Text Alerts

Use Twilio to Programmatically Text Yourself!

Twilio SMS Text Alerts
Screenshot from my Android phone of the SMS Text Messages I sent myself from Twilio (full URLs are redacted)

built a little program that checks book prices and alerts me if the price is low enough.  Recently, I integrated Twilio with it, so that I receive an SMS alert when my program finds a match.  This was surprisingly easy to do.

I’m a PHP wizard, so I wrote it in PHP, and here’s the code to do it.  That’s a github gist, and I had to alter it a bit as not to reveal any top secret code, so you’ll have to finish it a bit to meet your goals, but it should give you a good idea.  It’s fun to implement, because all you have to do is something like this:

$twilio_gateway = new Twilio_Gateway();
$twilio_gateway->text_me( 'This is an alert!' );

I love when code reads like that. So easy to understand what’s going on!

If you’ve never heard of Twilio, you should check them out.  They have APIs for incorporating text messaging, video and voice into your app.  Their developer docs are super easy to follow and they offer a free trial account!  I’m still unsure of how many text messages you get to use with a free trial account, but it’s way more than a handful.

If you’re on their trial account, text messages will include a notice that they were sent from a trial account.  You also can only send messages to phone numbers that you have verified.  That said, if you want to send alerts to yourself for free, Twilio makes that possible.  And if you decide to upgrade to a paid account, it seems that the cost is still going to be pretty cheap for personal use.  I first heard of Twilio while listening to a Software Engineering Daily podcast, and the ad said it was something like a penny a message.  You do have to buy a phone number to send the messages from, but that’s also super cheap.

SMS is a great option for sending alerts, because modern smartphones allow you to designate different notification sounds for each number, so I have a unique sound for when it’s an alert from my program.  The trick is to make sure that the alert only comes in when it’s actually important, as when alerts happen too often, the human brain tends to tune them out.  So the next step is optimizing my program to get better at figuring out when something really is a deal!

Leave a Reply

Your email address will not be published. Required fields are marked *

*