Scott Barstow on Hacking with Amazon Lex

amazon lexA few weeks back I jumped into my 3rd TADHack event to compete. I’d been doing a good bit of work in the run up to the event using Amazon Lex, so I decided to build a simple interface from the PSTN (or old telephone network for you telecom newbs) to a Lex chatbot.

Lex supports a few interfaces, or Channels as they call them, out of the gate including Twilio, but I wanted to roll my own interface built on RestComm by Telestax for the demo.

The process for building the Lex chatbot was pretty straightforward. The hardest part was getting Amazon to give me access to Lex! They’ve now made the service publicly accessible to everyone, so that hurdle is no longer there.

After configuring the Lex bot (I used one of their examples as the basis for my demo), I needed to build a simple bridge app to pass SMS messages from the telephone network to Lex and then from Lex back out to the telephone network.

I built a NodeJS app (available on my Github) that takes messages from RestComm and sends them to the bot, gets the response from the bot and routes the reply back to the user. It took a bit to get the Amazon JS API to work with Lex (this was the first time I’d used the Amazon API for anything other than EC2), but once I figured out the syntax it came together pretty quickly.

If you’d like to run the demo app yourself, here’s what you’ll need:

  • Get an Amazon AWS account if you don’t already have one
  • Add the Lex service to your account
  • Read through the Lex documentation on how to set up an IAM role for Lex and configure it with the proper permissions. This takes a bit of fiddling, particularly to make the bot accessible via API.
  • Download my ChatbotRelay app from Github and follow the README on getting the app installed and running. You’ll have to have a publicly accessible IP for RestComm to deliver the SMS messages to.
  • Download RestComm and follow the instructions to get it running on your machine. If you’re not familiar with compiling Java apps from source, grab the binaries. The documentation link is in the README at the link above.
  • Configure a number in RestComm to forward all SMS messages to the URL for your relay server
  • Configure the Amazon credentials for the app (you’ll find a template config in the ./config file of the app)

Once you’ve got all of that configured, you can test by sending an SMS to your RestComm instance and watching it bounce through to your Lex bot and back.

There’s a lot more I want to do with this Relay app, and I’d welcome anyone wanting to work on it together.

It was fun competing in another TADHack event, and I’m looking forward to TADHack Global in the fall.

You can watch the demo of the app in action below, and thanks for reading! Hit me up on Twitter if you need help or have any questions.