Messing around with Twilio, Shopify & Heroku
Toby Allen
Solving your customer identity challenges with Auth0 - Senior Solutions Engineer | CISSP | CCSP
I can see clearly that APIs are transforming the business world. In my part of the woods this means that CPaaS is disrupting the traditional vendors and starting to cause them pain. Perhaps today the platforms won't replace a whole contact center but they will be used to enhance and extend it. This means that I need to understand the platforms, the joys and the pains, the highs and the lows, so that I can better talk to my customers about them all. Here is how I pulled together my first somewhat useful Application. I'm writing this as much for my own benefit as yours.
After looking around for a few days I decided that I would use Twilio to notify me of orders on the Honeybell Love Shopify store. Shopify already has a great iOS application that I use regularly so its not strictly needed but it was complex enough to be interesting. In order to integrate the two systems I needed to find somewhere to host my application. I have zero interest in running my own web server so I was quite pleased to discover Heroku which lets you host small applications in the ? for free. You don't get a heap of compute but its perfectly adequate for me.
I forgot how frustrating development can be
I admit that it is the first time in a couple of years I have done more than hacking a shell script or modifying an existing application, usually web based, however I forgot (or perhaps blocked out) how frustrating it is sometimes.
In this case I had multiple challenges getting a development environment up and running on my Windows 10 PC. The environment of choice for me was Ruby as Shopify is built on this and a lot of the hacking I've been doing for Honeybell is in Liquid which is based off Ruby. I started with the standard Ruby install and ran into issues because the twilio-ruby library needs libxml and it doesn't work on windows at the moment. So after half a day of messing around trying to get that to work I decided to try out the new Windows Linux Subsystem (WSL). This gives you a Ubuntu powered Bash Shell on Windows.
Setting up WSL was actually pretty easy I followed the instructions here. Again I ran into a hurdle whereby the install hangs at the Extracting Filesystem stage, this is a known issue. Did I mention I had forgotten how frustrating development can be sometimes? Fortunately a reboot seemed to sort everything out and I had a functioning environment. I then followed the guide a Go Rails to setup Ruby and Rails on Windows 10.
Twilio offers a collection of Communications API in the cloud such as SMS, Voice, IP messaging, Video. Perhaps their most well known customer is Uber, which uses it for driver to rider communication. After mucking around with some of the quick start guides on Twilio. I sent some messages and made some calls to try out the APIs. Super simple to follow the sample code and get things going in minutes. Its a pity the development environment setup isn't the same!
Once I sorted out Twilio I headed over to figure out Shopify. Shopify is a great E-commerce platform which makes building a online store really quite simple. It comes with a host of great features already, inventory management, customizable pages and payment gateway integration. Additionally, it is extensible via a developer partner program with an extensive App Store. I'm going to leverage this partner program to develop this little application. After several false starts with some Shopify apps like "shopify_app" and "shopify-sinatra-app" which both turned out to be overkill for my objective. I settled upon the Shopify App Tutorial which implemented a simple webhook and allowed me to drop in the code to send SMS via Twilio.
Now, in order to capture and process the webhooks from Shopify I needed a publicly reachable host for my little application. If you're not familiar with webhooks they are essentially a special HTTP callback triggered by an event. When the even occurs the source site (Shopify in this case) makes a request to the specific URI. After a little digging I discovered Heroku, which lets you deploy and host small applications for free. There are other similar services out there like AWS Lambda. It was pretty simple to follow the Heroku getting started guide for Ruby and get things up and running. Heroku will return a URL like https://pacific-cliffs-120324.herokuapp.com/ which you can then go and load. Now, when someone places an order on the Shopify site. A webhook is sent to the Ruby Sinatra application running on Heroku which in turn leverages the Twilio APIs to to send me a text.
I must admit that despite all the frustrations this has been a fun little experience and I am looking forward to playing around some more with additional APIs on Twilio such as the IP messaging as well as getting something similar running somewhere on the Oracle Cloud. If you want to check out my application I put it up on Github. I will hopefully get some time to build a proper readme file so that others can run it easily. In the mean time please don't hesitate to reach out for instructions if you want to get it running as well.
Views are my own and do not necessarily reflect those of my employer Oracle.