Training wheels off!

Project Revamp

I started out wanting to do a skill that tracks TSA wait times. I encountered a two issues that were show-stoppers for me:

1. TSA’s servers were flakey re: JSON returns.

  • Without changing code, I’d get different responses to the same request—sometimes it would work, sometimes it wouldn’t. There was no discernable pattern to it.

2. The data is garbage.

  • TSA’s wait time data is random data that’s reported by random people. It’s not data supplied by TSA. Sometimes it’s frequent, others it’s spread across days.

  • They throw data into 10 minute buckets that max out at 30+ minutes, so a 30+ minute wait could actually be a 1 hour wait or a 2 hour wait.

Given the lack of current, consistently good data, I determined my skill would be of marginal utility.

With that in mind, I revamped my skill to something that doesn’t require .gov servers. I created Date-Ninja to deal with something I find to be a gigantic PITA…doing date calculations.

Date-Ninja

Alexa’s documentation says it can convert a spoken date into a slot formatted as a date. Alexa can also look up holidays, but I don’t see anything regarding date calculations. I created a skill which allows the user to:

  • caculate days to/from a given date
  • return the day of the week for a given date
  • return a date a given number of days in the future or past
  • return the date a given number of weeks in the future or past
  • return the date a given number of months in the future or past
  • calculate the difference in days between two dates

Developing locally with a Node.js environment

I installed Node.js on my machine and I found an excellent post Developing Alexa Skills Locally with Node.js: Setting Up Your Local Environment by Josh Skeen.

In that post, I learned about Test Driven Development (TDD) with Chai and Mocha. I created a helperClass.js file and a test file to ensure proper returns for all the date calculation methods from my helperClass.

I also learned about the usage of npm to manage dependencies for my project. I found a really cool one for date calculations called moment that was very easy to use.

In the Big Nerd Ranch post there is link to the alexa-app package, which enables you to run a node server on your machine so you’re not monkeying around uploading code to AWS/Lambda every time you change a line.

One caveat with alexa-app is it only picks up changes to your index.js file. If you make a change to a helper class, you need to restart the node server (ctrl+c followed by node server from Terminal on a Mac), which isn’t too much of a PITA.

Utterance creation

One of the dependencies of alexa-app is a fantastic package called `alexa-utterances’ which makes creation of utterances effortless.

To create my utterances, I opened a text file and typed out all the different ways I could say something. Then I looked for commonality between the phrases and threw in tabs.

What was the date 	DAYSINTHEPAST days 	ago?
What was 			DAYSINTHEPAST days 	ago?
What day was 		DAYSINTHEPAST days	ago?
What date was 		DAYSINTHEPAST days 	ago?
										in the past?

Then, for each intent, I constructed an utterance string for each of my intents in my index.js file.

// from my index.js file w/ LOTS of code omitted
'utterances': ['{what was the date|what was|what day was|what date was} {-|DAYSINTHEPAST} {days} {ago|in the past}']

| at the beginning of a curly brace means the phrase may or be included in the utterances generated by alexa-utterance

{variation1|variation2|variation3} will create utterance variations with each of those words.

-| goes in front of your slot, which you specify in your intent declaration.

…which spits out the following in the alexa-app node server:

getDaysInThePast	what was the date {DAYSINTHEPAST} days ago
getDaysInThePast	what was {DAYSINTHEPAST} days ago
getDaysInThePast	what day was {DAYSINTHEPAST} days ago
getDaysInThePast	what date was {DAYSINTHEPAST} days ago
getDaysInThePast	what was the date {DAYSINTHEPAST} days in the past
getDaysInThePast	what was {DAYSINTHEPAST} days in the past
getDaysInThePast	what day was {DAYSINTHEPAST} days in the past
getDaysInThePast	what date was {DAYSINTHEPAST} days in the past

Running a local server makes it very easy to tweak utterances to capture the variations phrases to call an intent from the skill. Just refresh the server when you tweak your index.js file. In the first two skills I created, there was a lot of guesswork to creating utterances. Using the alexa-utternce package, the guesswork is virtually eliminated.

Anyway, that’s what I’ve learned so far. On to Google Analytics.