How I Built the Best Christmas Gift Ever With Twilio, AWS, and OutSystems
By: Allen Helton
Tags: Messaging, Technology, Programming, AWS, Christmas

Where to Start?

Thinking about my master plan from a high level, it’s nothing more than a state machine. A simple state machine that will rain the fire of frustration on my brother on Christmas morning.

End to end, there were three components:

1. Sending/receiving calls and texts

2. State machine

3. File storage (for some soundbites I wanted to playback)

From an architectural point of view, it was a pretty basic flow:

1. A call or text comes in.

2. The details from the call/text get routed to a web service that manages state.

3. The service processes the message in response to the state and returns a message, sound, or a flag to follow up to get more information.

4. The message or follow up is returned back to the user.

Messaging

My decision for messaging was easy. There’s really only one answer when you’re a developer and you need to make a text or a phone call: Twilio.

Twilio has a design feature called Twilio Studio that lets you build workflows via a drag and drop user interface. It has specific routes for a call versus a text and gives you the ability to call into a web API for special logic. This is exactly what I needed.

I assembled a generic flow that passes in the contact type (call or text), phone number, and message into an API I was going to write. Based on the response, it will do one of three things:

1. Say/text a message from the response of the API

2. Play a sound

3. Ask a question and gather input from my brother

In lieu of going into specifics of the workflow, here is the JSON of the flow from Twilio Studio.

The Phone Numbers

Next, I had to acquire some phone numbers. I went to Twilio and purchased eight phone numbers, one for each gift. With Twilio, phone numbers only cost $1/month per number, so I felt like I was getting a steal.

After the numbers were purchased, I had to bind them up to my Flow. So, I went to the dashboard for each phone number, told it to use my Christmas Flow, and then boom. Done.

Messaging dashboard for the phone numbers

Online Storage

There were a few sound bites I wanted to play back when some phone numbers were called. I decided to go with AWS and use S3 (Simple Storage Service) to host the files. For the number of files I wanted to host, it wouldn’t cost a penny.

I uploaded the sound files to S3, made them publicly accessible, and took note of the URLs.

The State Machine

This was easily the most complicated part of the project. I wanted something that was elegant but as small as possible. And didn’t make a fuss when I went to deploy.

Enter OutSystems.

OutSystems is a company focused on low-code/no-code development that manages everything for you. They take away the hassles of deployment, writing extraneous code, and manipulating HTML by providing you with a rich experience through their service studio and designer. Plus, it’s free to use if you’re doing non-production development. Win-win!

This is definitely where you could veer off the path I took and go with a full AWS solution. I did consider that initially, but I wanted to keep my development time down to a minimum, so I opted for OutSystems instead.

Below is the entity-relationship diagram for the state machine.

Call — Used for tracking/humiliating my brother. This shows me every attempt he makes at trying to figure out which present to open. It was initially used for debugging purposes but ended up with a funny use so I can tell him how many times he contacted his presents. This is entirely optional.

NumberState — The response for each phone number at any given state. As the gifts get opened, the state progresses and the phone numbers change their responses and call/text preferences. This is the real meat of the state machine.

Number — The phone number assigned to a gift.

ContactType — Hardcoded list, CALL or TEXT.

State — Represents which gift my brother was on. This Christmas he was lucky enough to get eight gifts, so there were eight states.

Progress — This is a singleton that represents the current progress through the state machine. It was responsible for looking up the appropriate NumberState given the parameters passed into the service.