I bet you $50 I can teach you to how to send yourself a text using Twilio and Repl.it

May 9, 2019

I bet you $50 I can teach you to how to send yourself a text with Twilio and Repl.it
You have thought about it a million times but it’s never seemed like something you needed to do ‘right now’. There really isn’t any urgency but you you’d like to do it at some-point. You’re reminded…

You have thought about it a million times but it’s never seemed like something you needed to do ‘right now’. There really isn’t any urgency but you you’d like to do it at some-point. You’re reminded of it constantly though, anytime you’re home you can’t help but be reminded of your procrastination riddled task.

When friends come over you might try to hide it, throw a jacket over the back to take away from that disgusting shade of green. You hate that green, you always wanted it blue but never found the time. Well I mean you had the time but you know, painting is a whole thing.

Obviously you know how to paint it’s nothing like that. You just paint it. A few weeks go by and one Saturday morning motivation washes over you to change that chair, forever.

Hop in the car and head towards Home-Depot but hesitate, or should I go to Lowes…? After reaffirming Home-Depot is the better choice because there is a Chick-Fil-A on the way.

Park the car and elect for grabbing a cart inside. Pushing the cart effortlessly fueled by an overwhelming radiating pride imaging how good that chair is going to look when you’re done.

Running through your mental checklist, paint, brush, … a glove maybe? Arriving at the paint section you see more combinations of paints than atoms in the observable universe and all of the paraphernalia to go with them.

One coat or two? Primer? Sanding, I definitely need to sand it. Do I clean it? Do I have to clean it if I prime it? If I sand it do I need to clean it? What if I also prime? Should I use water-based or latex-based? What about stain? And you spiral.

Combing the isles fear sets in, fast. Painting is easy but why don’t I know what to do? Asking yourself a question you have never faced before. “Am I seriously desperate enough to ask the wizard looking guy running the paint booth to help me? Gandalf definitely doesn’t want to help me with this seriously dumb question.”

Artist depiction of Home Depot wizard

That’s how I felt the first time I tried, on my own, to program. Mind you this is after spending two full months of studying programing full-time. And after a non-technical career in the technology and software space. I had to ask myself. Am I cut out for this? Or am I attempting to paint a chair for the first time?

Up to this point I had always thought, you just program it. Open up a text-compiler-thing and make it run. Similar to painting, you just paint it.

I was right, that is basically what you do. Bang on the keyboard until it works. But, I quickly discovered the barrier of entry very high due to a jargon-subset I had not yet encountered. Is sanding front end or back end? Would Ruby be a water-based paint or oil based? Do I need to run a language in a specific language text editor?

My first project I tired on my own was attempting to send a text-message through my computer using Twilio. It may sound complicated but think of Twilio as if Uber and AT&T had a cyborg baby.

After spending 5 years at AT&T and fighting for months to get a POTS phone line installed for a customer, Twilio feels as if it is akin to magic, a complete game changer and provides really any communication you can think of, as a service.

Does this sound familiar?

“Oh you just connect to the API”

Followed by you replying:

“Oh right, right of course”

With an accompanying head nod. Well today is your lucky day.

I decided to find out and wanted to show how with a couple copy/paste commands you can check “Start Programming” off your list.

The Master Plan:

We are going to use Repl.it to connect to the Twilio SMS API and send ourselves a text message. Sound unbelievable? Believe it.

Let’s break it down and take it step by step.

What do we need?

  • Something that we can write “code”
  • Twilio Account
  • Cell Phone
  • 20 mins

Something to Code With:

  • Programming in the “real world” requires a local environment. This means your computer needs to be set up to write code. Luckily for us we don’t need to go down that rabbit hole for this example.
  • We will be using Repl.it an awesome service that provides an IDE that can be accessed through a web page. Pretty cool! Think of this as a virtual computer with a blank slate. And it is self contained so you can’t break anything.

First vocab word: IDE — it is like a programming playpen.

  1. Sign up for repl.it here
  2. Once logged in, let’s create a new Repl by clicking ‘+ new repl ’ and selecting Ruby.

Let’s get started!

Type

puts “Hello World”

Into the middle section and click the Run button. BAM what’s up bill gates

What you are looking at is the most basic factory settings necessary to run Ruby. It runs our simple command but we will need more functionality. Enter GEMs.

You may have heard of GEMs in the past. Think of GEMs as expansion packs for your computer. They afford additional functionality for your code.

Ok now we are going to go from 0–100 but stay with me.

First, let’s sign up for a Twilio account.

https://www.twilio.com/try-twilio

You will have to verify the email and phone number to access what we need.

Arriving at the Console. Configure a phone number, one click.

Now that we have our phone number lets copy errr… write some code! Click this link:

https://www.twilio.com/docs/sms/send-messages#send-an-sms-with-twilios-api

Welcome to the Docs.

Copy the code on the right side plane and paste it into Repl.it middle panel where we typed:

puts Hello World

Once pasted hit run.

Oh no! An error. We need to install a GEM named ‘twilio-ruby’. As we discussed this GEM is an expansion pack for Ruby specific for Twilio so we can run our Twilio program.

Head over to packages and search for ‘twilio-ruby’, add it by clicking the ‘ + ‘ icon. This will trigger a few things. The terminal (Repl.it right side plane) will install the GEM package and create a GEM file. This allows the computer to know what GEMs are used within our program. It also gives the computer a heads up and prepare for what is coming further down the page.

Sweet, now I think we are good, hit run again. OH NO another error hmm unable to authenticate. Looks like we need to swap some parts out in our code.

Head back to the Twilio console and grab your authentication token.

While here let’s also make note of the Twilio trial phone number.

Head back to our Repl.it and add your authentication token into the code (highlighted). Do yourself a favor and don’t post these keys anywhere public. Someone WILL find them and take your account.

The ‘from:’ number will be the trial number Twilio provided. Yes, this is a real live phone number!

Put your personal phone number in the ‘to:’ field.

Also, let’s change the message. Replace ‘Body’ with ‘Hello World’ .

Once ready, hit run.

Buzz Buzz, it’s me the hacker man.

And to finish the home depot story, the chair turned out horrible and I scrapped it. That experience taught me that I’m not a painter, the jury is still out on software developer.

-Joe