Lessons learned from working with Amazon Echo
So the Amazon Echo has been on the market for a while now and I recently got the opportunity to hack away a bit at one and I learned quite a bit from the experience. Â
First and foremost I do not get out of my standard Front End Web code stack all that often and while this was not too much of a departure using node.js to program a simple application it still was nice to get out. Â That being said you can pretty much define most of you need to do with Alexa with node and not really need too much else.
Now before I go to far into these lessons I used aws to host all of my code as lambda functions. Â This can be done in other ways but for sake of time this is the route that was taken. Â Basic code and instructions on how to do this can be found here. Â
Lesson 1: File structure: So following the sample demo provided above it is easy to create a simple lambda function using the AWS inline editor. Â However this method breaks down when you have need for more than one file or folder. Â AWS covers this by allowing you to upload a compressed folder of files to run against. Â So in theory this should be rather simple. Â However, this was my first time working with AWS in such a way. Â So in order to do this with an Echo Skill, one must upload the files with an index.js file. Â Echo will try to run index.js, so if this file is missing the whole skill will break down. Â
You can have more than one file that gets used by index.js but these files must be compressed together and uploaded as a compressed folder. Â This is where I ran into my first issue. Â You cannot compress the folder containing these items. Â If you do so the process will fail. Â Instead you must select the files and folders you want included and then compress them, not the folder containing them.
Lesson 2: NPM:Â So the basics of the Echo Skill I was writing called for it to make a simple REST call to a cloud hosted api. Â This sounds like it should be easy, but in my green state with node I actually ran into a few problems with this. Â So in order to make efficient REST calls an npm package was added for restler a REST based library for node. Â From another blog post online, it seemed that the lamdba function should force an npm install before execution of the Echo Skill, but upon further inspection this was not happening. Â This may have been a wiring issue, but I found zipping up the node modules folder along with the rest of my code solved this issue. Â
Lesson 3: Sample Utterances and Slots: Â Once a lambda function is all ready to go the Echo Skill is wired up in the Amazon Developer console. Â Here a developer has to define a few things. Â A developer needs to point to the code for the skill, wire up the phrase to run the skill, as well as wire up any utterances and slots to accept from the user to trigger specific functionality. Â I could go on for a while about many different take aways from here but I will break it down to two key things learned.
First crafting both your utterances and run phrase is very important and some thoughts need to be kept in mind
Keep wording simple and short where possible.  Echo’s speech recognition is good, but longer phrases generate more room for error.  In addition hard to pronounce words can be misspoken easily or misheardÂ
Avoid using words key to Echo’s functionality.  So often times when a word such as ‘order’ needed to be said Echo seemed to forget the skill and jump into its amazon shopping mode trying to order somethings. Some words to avoid are:
Order
Play
To Do
Remind
Purchase
Make sure to test your phrases audibly. Â Its easy to test whether your function runs from the developer console just by typing the phrase, but just because it works there does not mean it will be easy for the Echo to understand your phrasing so be sure to test it in the console first but run a few device tests too.
The other major take away I had involves using slot parameters with Echo utterances. So Echo will allow someone to write an utterance like:
ApplicationIntent add the following to my achievements {achievement|Achievement}
So what this translates to is when a user says ‘Echo run YOURAPPLICATION to add the following to my achievements climbed the Tooth of Time.’  you have created a parameter that collects what is said after ‘add the following to my achievements’.  So one would expect ‘climbed the Tooth of Time’ to be passed into your Lambda function.  However, in this example only ‘Time’ would have been passed through.  This is because if inside the ‘{...}’ only one word is before the ‘|’ Echo will only pass the last word that is said.  In orde to capture everything said simply add as second word before the ‘|’ like below
 ApplicationIntent add the following to my achievements {cool achievement|Achievement}
Now ‘climbed the Tooth of Time’ would be passed through to your inner functions. Â
Hopefully these few lessons are helpful to someone else working with an echo and will save some of the frustration in learning them the harder way. Â I plan to continue to experiment with the Echo so hopefully I will be sharing more useful information in the future. Â














