An Alexa Skill in JavaScript – Part 1

So I finally decided to stop fighting it…  Building Alexa Skills in C# is just difficult.  With the newly released Visual Studio Code plugin for Alexa ( ) the language of choice is JavaScript.  Ugh.  But, it turns out that Google is still my friend (even though the Google Home is a horrible platform for voice skill development).  A quick search turned up all sorts of free JavaScript training.  A few hours of interaction later and I’m a pro beginning to be barely capable in JavaScript.  So, what’s a Microsoft Developer to do to code an Alexa Skill?

Getting the Tools

Step 1 – From the command line (Start | cmd in Windows), run npm to install the ASK CLI:

npm install -g ask-cli

snip_20180915064344

This command takes 2-5 minutes to run and doesn’t appear to be doing anything while it’s running.

TIP:  It’s a good idea to run that npm command every month or so to get the latest version of the ASK-CLI.  It is updated quite frequently.

Step 2 – Install Git, if you haven’t already.

Step 2 – Install Visual Studio Code if you haven’t already.  (I recommend the 64-bit User version for Windows developers.)

Step 3 – In VS Code, select the Help | Welcome menu.  On the right-hand side, under Customize, under Tools and languages, install support for JavaScript.

Step 4 – In VS Code, select the View | Extensions menu.  Search for Alexa Skills Kit (currently – 09/15/18 – in beta).  Install it.

I think that’s all I had to do to get the tools.

Configuring for Alexa Skill Development

AWS Lambda Credentials

Since we will be using an AWS Lambda function as the back-end for our skill, we need to set up the credentials in AWS IAM.

Add a User.  Give the user a name.  Select Programmatic access.  Click Next.

snip_20181101181244

For this example, I’m going to Attach existing policies directly and select Administrator Access, but this is NOT best practice.  (I should create a user group that has the specific policies this account needs, but that’s a different blog entry.)  Click Next.

snip_20181101181336

Click Create User.

snip_20181101181404

Download the .csv.  Do this.

IMPORTANT:  This is the ONLY time you can Download the .csv, so do it now.

snip_20181101181516

Click Close.

Initialize ASK CLI

In VS Code, view the Command Palette (Ctrl-Shift-P) or select the View | Command Palette menu.  Enter:  ASK in the palette and choose the “ASK: Initialize / Configure the ASK CLI” option.

snip_20180915060653

Accept the default profile name.  Sign in to Amazon in the browser provided USING THE ACCOUNT YOU JUST CREATED ABOVE.  It should say “Profile [default] initialized successfully.”

snip_20180915072056

If not, go here for assistance.

Starting the Alexa Skill

Create a folder for Alexa Skills.

View the Command Palette (Ctrl-Shift-P) or select the View | Command Palette menu.

Enter:  ASK in the palette and choose the “ASK: Create a basic skill package” option.

snip_20181101174552

It should come back with an option to select your AWS profile.  Choose the profile you created above.  This profile needs to be linked to an IAM user who has the right to publish Lambda functions.  (Which is why I cheated above and gave it AdministratorAccess.)

snip_20180915071206

Now it will ask you to enter a skill name.  I’ll be calling mine “OMWTM Roll A Dice”.

snip_20181101174716

 

ASK will then create and run a command in the Terminal window at the bottom right of VS Code:

snip_20181101175829

Once it’s finished, VS Code will open a folder with your basic skill defined:

snip_20181101180914

In the next blog entry, we’ll go through the basic skill definition and customize it.

Bye for now.

2 thoughts on “An Alexa Skill in JavaScript – Part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.