Showing posts with label alexa-zipcode-lookup. Show all posts
Showing posts with label alexa-zipcode-lookup. Show all posts

Monday, August 29, 2016

Alexa Zipcode Lookup


I have been playing around with building another Alexa skill.  I mostly wanted to explore some different techniques to use in a skill.

This new skill will lookup zipcodes for you.  It does it in a few different ways:
  • If you tell it a zipcode, it will tell you what city that zipcode is for
  • If you tell it a city and state, it will tell you what zipcodes are associated with that city and state
  • It will return a card to your Alexa app with a map of the location
The skill uses a few different services.  Zippopotam.us is the service that I use to do zipcode and reverse zipcode lookups.  And I make use of Google Maps API to assist with the spelling of city names, when the Alexa Voice Service doesn't recognize the spelling.  Also, the maps are provided by Google Maps API.

I am going to write about the different parts of this skill across a few different posts.  I hope some of these techniques will help you with your next skill.

The code for this skill is up on Github...  https://github.com/chrispauly/alexa-zipcode-lookup 

Friday, August 26, 2016

NPM to the Rescue for your Alexa Skill



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.

  1. Download NodeJS and install it on your OS.
  2. 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]
  3. 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.