Hacking a bot

Here at Zuto we recently had a hackday. For anyone not familiar with the concept it simply meant we had a day to work on projects outside of our day to day. The only steer we had was use AWS as our cloud provider where appropriate.

Several of us decided we would try writing a bot which could be integrated with via different channels (SMS, facebook messenger, voice, etc...) to get a quote for car finance.

The first step was to get a bot running in the AWS Lex platform.

Setting up the bot

AWS is a mature platform (even if elements are new) and comes with some pretty good documentation, including a good guide for building a custom bot -
http://docs.aws.amazon.com/lex/latest/dg/getting-started-ex2.html

Lambda

AWS Lambda provides the ability to run code in the cloud without the overhead of managing servers etc. This is where we can put complex business logic that can use the data captured from the user by Lex's basic request & response based conversation.

We used NodeJS for our language. Lambda provides two ways to upload your NodeJS code:

  • Inline in the AWS console

  • Upload a zip file

For us, the much faster feedback route was to use the online editor. This lead to fairly messy code, and had we had more time we would have set up a neater editing/deployment process using a zip file upload.

Testing of the lambda was done by providing a typical test message from Lex and applying this data to the function using the online console. The test data is stored with the Lambda function, so whenever we changed the Lex bot in a way the interface to the Lambda function changed, we would update our sample test data accordingly.

Lex

Lex itself is fairly straightforward to configure in simple cases. You have -

  • Utterances - These are the statements to respond to initiate any interaction (and can be changed together in more complex cases). These are simply text value which can be entered which are matched to the text/voice input. These can contains slots or not.

  • Slots - These are the parameters which are going to be supplied by the user during the interaction. E.g. in a pizza ordering example the size of the pizza. In our case we defined three. Some custom data types so using the long list of built in data types (more on this in "What we learnt")

  • Fulfilment - What to do with the result of the interaction. To use AWS Lambda as the back end you simply pick the function from a drop down. It's that easy.

There are further options but this was all we needed to get the basic bot working.

Once this is all done you can simply build your bot and use the in built test tool to try it out via voice or text.

Integration

Our bot wasn't much use without something demonstrable. Lex's test tool is fine for testing but when you're showing your work off to other people you really need to have something driving the bot otherwise the whole thing feels a little fake and unimpressive. We tried a few approaches:

Facebook

Having previously had experience with integrating Microsoft's bot framework with Facebook Messenger we thought this would be straight forward. Unfortunately we were wrong.

We found a guide and followed it closely but despite entering all the correct keys in the correct boxes (as far as we can tell - the guide was not entirely clear and out of date from a facebook point of view), we had no luck. The worst part was there is no easy way to gain insight into what was going wrong. We could see no requests hitting our Lex bot but had no way to determine why.

This combined with the time limitations of a hack day meant we decided to move on.

SMS

Unfortunately this integration also proved fruitless. Lex provides a Twilio integration, but after signing up for a Twilio account the console just hung on connecting Lex to the account. Without this fundamental step there was no chance we would get this working so dropped the SMS integration.

Voice

Amazon makes it exceptionally easy to create a mobile app for your bot. In literally a couple of clicks you can generate a basic unbranded Android or iOS app which adds voice and natural language interface to your bot.

Mobile App

We found this overview and followed these steps:

  1. Headed over to the AWS Mobile Hub
  2. Chose QuoteCalculator from the list of our projects.
  3. Clicked on the Integrate link.
  4. Selected the type of app we wanted (Android/iOS Swift/iOS Obj-C/JavaScript)
  5. Clicked on the Download your example mobile app project link
  6. Built the project. We created an Android app - additional info on getting started with this here
  7. Copied the APK to our device and talked to our bot!

We aren't mobile app experts by any means but it was trivial to get this up and running. We spent a few minutes ammending some of the assets to add some Zuto branding and ended up with a pretty kickass demo!

AWS hackday

What we learnt

  • Slot types - there is a long list of slot types predefined in AWS, such as cities, actors etc. One glaring omission for us though was currency. In a natural conversation, the user will say something like "five hundred pounds", but in a text input field they would expect the currency to be there and just enter 500. Lex does not support currency at all currently, so the closest we could get was integers. The second slot type we had issues with was time duration. It's impressive in the way it can take a variety of phrases that mean the same thing (such as 1 year and 12 months) and produce an ISO standard time duraton, but the voice recognition just seemed to be a bit weak and caused us more misreadings than any of the other slot types we used.
  • The first time we built the Lex bot we could not understand why all the controls are now read only. There is an irritating feature which means each time you builds it switches to the built version and you need to pick "Latest" from the version drop down - Selecting a Lex Version
  • The integrations with third parties are still unreliable with little to no feedback available if everything does not work.
  • The number of integrations is very limited right now - Twilio, Slack and Facebook Messenger being the only ones. We expect this to improve with time.

Simon Kirkham

Read more posts by this author.

Subscribe to Zuto Tech Blog

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!