Growing up, my dad regaled me with stories of cutting 1/4″ tape with a razorblade to patch audio snippets together. He didn’t have GarageBand, ProTools, or Abelton. The analog world can be more unforgiving than the digital world, and requires a tremendous amount of effort and precision.

In the software world, it’s easy to forget the days of analog, too. Instead of programming motherboards, we write a few lines of code. Now, with so many APIs and third party services, instead of writing code, we use a visual development environment and we’re a few clicks away from having a back-end up and running.

Stamplay respects the days of analog, but is firmly in the “few clicks away from a deploy” camp. They offer developers a dead-simple interface they can use to create and run workflows using APIs like Mailchimp, KeenIO, Firebase, Twilio and others. Think of IFFT or Zapier, but for APIs.

In the spirit of making things incredibly simple, Isaiah Grey of Stamplay built a simple demo showing how you can create an SMS weather alert service using Twilio and Node JS. Without further adieu, here’s Isaiah’s tutorial plus a video walkthrough.

Building A Weather Service, Powered By SMS with Twilio and Stamplay

Our service will work in the following steps :

A user sends an SMS to a number provided by Twilio that will pass a city name into our Stamplay backend. A Stamplay Task will catch the SMS using the Twilio integration and pass it to a custom Code Block. Our custom Code Block will fetch weather data for a city, then assemble a response message from the data, and output the message. Another Stamplay Task will execute once the Code Block execution is complete, and using the output to respond to the intial SMS number with the weather data for that day.

Try it out by sending a text to +1 628 600 1473, with the name of a city (e.g. “New York”). You can also get a full week forecast by typing “forecast” after the name of the city (e.g. “New York forecast”).

What You’ll Need

Twilio Account

Stamplay Account

Get Started

After you have a Twilio account, navigate to your Account Settings to get your API credentials, your AccountSID and AuthToken. You can find them here.

In Stamplay, on the left hand side select Tasks then components. Choose the Twilio component within the list.

Next inside the Twilio component configuration, add the Twilio credentials to their corresponding fields. Now we are ready to start using Twilio within our Stamplay app.

First we need to initialize a Code Block within Stamplay. Code Blocks are custom RESTful endpoints within our Stamplay application. Create a new one by selecting Code Blocks on the left hand side and entering a name for our Code Block. Let’s call it weather.

Our new Code Block should look like this.

Head over to the Stamplay Tasks section and create a new Task. Configure the new task to trigger to: when a new SMS from Twilio is received, run a code block.

In Step 2, select a number from the dropdown you wish to trigger this Task when the number selected receives and SMS.

When you’ve created a Twilio account, a Twilio number will be automatically provisioned for you. You can see your numbers here. If you don’t have one, you can easily buy one.

Below the dropdown where we selected the Twilio number, copy the input field containing the callback url, and head over to your Twilio phone numbers page.

Select the number you used to trigger the Task in Stamplay.

Then in the prompt add the callback url into the Request URL input:

Now back in Stamplay, we need to finish our Task setup.

We will pass in the phone number that sent the original text as the to property on the JSON object as we will use this number after the Code Block executes to send a message back. The body property is the city name and if present the forecast option which we will explain later once we get to our Code Block.

After Step 3, name your Task and head over to the Code Block to start editing.