Day 6

Connecting to Twilio

Ryan Strickler
Little King: Daily Log
2 min readDec 2, 2016

--

I connected Prompt with Twilio today. Twilio is a service for sending text (SMS) messages, among other things. They have a really great API and if you have a need for sending texts in your application, I highly recommend them.

For a Rails application, it’s pretty easy to set up. You just include the twilio-ruby gem. In the place of your choice, you set up your Twilio client with your account variables, and start sending messages, with very little trouble. These instructions are great. I set my Twilio integration up in a class called PhoneTexter, in app/texters/phone_texter.rb, to treat it similar to the pattern of Rails mailers.

From my Phone class, I’m calling PhoneTexter.send_confirmation in an after_create action and passing in my phone object, which has the number and token ready to go. Here are the important bits:

This could possibly be improved by offloading sending the confirmation to a job queue instead of doing it immediately, but I don’t want there to be any delay and I want to keep things simple for now.

What do you think? I’d love to hear feed back or suggestions for other ways to improve this.

--

--

Ryan Strickler
Little King: Daily Log

Building something every day. Launching something new every 6 weeks. Writing about everything along the way.