I started writing Alexa Skills in AWS Lambda using the example blueprint and online code editor.
Recently, using the new code samples that Amazon has on Github, I've graduated to writing my code locally in VS Code, and then zipping up the files and uploading them into my Lambda function.
Now, I'm taking it one step further, and instead of writing all the code, I am leveraging NPM to provide functions for tasks that would be tedious and/or difficult to write myself.
I wasn't sure how difficult it would be to start using NPM, like what config settings I would need or how to use them in my skills. I found out it is as easy as 1-2-3.
- Download NodeJS and install it on your OS.
- Open a Command Prompt and go into the ./src folder of your skill (the folder where index.js lives). Run the command npm install [package name]
- Refer to the examples provided for your package and incorporate that in your code.
That's it!
My main concerns were having to worry about directory paths or unfamiliar javascript configuration files. But I had none of those issues. I just zipped up my code and uploaded it into my Lambda function and everything worked!
I stumbled upon how easy this process was when I needed to write a function to translate digits into words. When I wanted to ask for a city name in my service, I found that certain city names did not come in as expected. For example, my hometown, Two Rivers, WI, when the CityName slot was populated by AVS with my spoken words, it came into the skill service as "2 Rivers". I needed to use the actual city name in my skill service. It required the actual spelling of the city name, so I needed to translate the number 2 into the word Two.
I found that there are other cities with numbers in their name, so I decided that I should build a more generic function that could translate numbers into words. But before I wrote that function, I Google'd for javascript functions that do that. NPM had a number of packages that would work for me, but I settled on number-to-words. I followed the 1-2-3 steps above and was so happy it worked without any extra effort.
No comments:
Post a Comment