Saturday, July 9, 2016

AWS Alexa Skill - Lou Person


AWS Alexa Skill - Lou Person

I recently published a post about how Echo, Dot, Tap and Alexa make the world a better place and improve the life of people with disabilities.  You can read it here:  http://blog.louperson.com/2016/07/amazon-echo-and-alexa-make-life-better-lou-person.html

The skill, called Dylan Day, has Alexa lookup events in history that occurred on a given date.  For example: "Alexa, ask Dylan Day what happened on July Fourth" will read out loud events which occurred in history on July Fourth.

The ingredients for the Skill are as follows:
  • An Amazon Web Services Console account.
  • JavaScript JSON for the application itself.
  • The Lambda service inside of AWS.
  • An Amazon Developer account.
To make coding easier (not required) I used the following tool set:
  • Visual Studio with the AWS Explorer installed.
  • Git for moving the code around.
Under a separate post, I describe setting up and securing (through IAM) an AWS console account.  You can read more about it here: http://blog.louperson.com/2016/01/amazon-web-services-over-cup-of-coffee.html

Amazon, for whom I work at Amazon Web Services (AWS), provides a great library of sample skills for developers.  I started with example code found here on GitHub: https://github.com/amzn/alexa-skills-kit-js/tree/master/samples/historyBuff
I cloned the files locally and opened them up in Visual Studio.


The speechAssets directory contains files related to speech utterances and Intent Schema which are entered in the Developer portal. More on this later.  The src directory contains the main application files which are uploaded to Lambda.  There are two files.  AlexaSkill.js and index.js.  AlexaSkill.js communicates with the Alexa service and is called by index.js.  This file pretty much acts as the gateway between the custom skill and the Alexa service.  I thought of it as the railroad tracks.  index.js is the engine which runs on the tracks.  This is where I made the customizations.  It contains the actual code for the skill. 

Most importantly, AlexaSkill.js contains a reference to the appID provided in the developer console.  This value is entered in index.js and passed to AlexaSkill.js This is critical from a security perspective because it will ensure ONLY the intended application can invoke the Lambda function.  In AlexaSkill.js:

function AlexaSkill(appId) {
this._appId = appId;
}

From index.js, I changed this:
var APP_ID = undefined; //replace with 'amzn1.echo-sdk-ams.app.[your-unique-value-here]';
to this (actual code obfuscated):
var APP_ID = 'amzn1.echo-sdk-ams.app.xx9bfexx-1xxf-4287-b0xx-6xx14xxf7cxx';

You can view the original code (I customized for my skill) from the GitHub link above.  I changed the invocation from History Buff to Dylan Day and changed some of the spoken text inside of the code.

I then used Visual Studio to upload the code to my Lambda function as part of AWS. 

Once uploaded, I received an ARN to reference my application in the developer portal.  This is the other side of the security feature above where I entered the appID in the Lambda code, the other side of the control is entering the Lambda ARN in the Developer portal.  Note the arrow in yellow.







Make sure that the Lambda trigger is set to Alexa Skills Kit before proceeding.

Next it was time to publish the Skill!  I logged into the developer console and selected Alexa Skills Kit. 


I then created a New Alexa Skill.  I chose Custom Interaction Model and will use Smart Home Skill API for another post when I try to integrate my Echo with my home automation system, such as my sprinkler system and HVAC.

Now comes entering the intent schema and sample utterances.  The intent schema and sample utterances are contained in the SpeechAssets folder of the Git repository discussed above. 

Up above, I mentioned that the ARN for the Lambda function in Visual Studio was needed in the developer console.  Make sure you enter the ARN name and not the ARN role. I entered the ARN information in the configuration section.   I did not use Account Linking (I selected no) because I was not linking any end user accounts with the skill.

I was able to test my Skill on my Alexa logged in with my developer account, as well as send test utterances as text through the developer console.  The results of a test are here:

Finally I entered the publishing information for the Alexa installation through the end user Alexa console and privacy information.


I submitted the Skill for certification!  It did take a few rounds back and forth with the certification team, mostly around the Publishing Information page.  Then about 9PM last night, my Skill went live on the Alexa End User console! 


I work at Amazon and the postings on this site are my own and don't necessarily represent Amazon's position. 


Post by Lou Person, I work at Amazon Web Services.




Amazon Echo and Alexa Make Life Better for People with Disabilities - Lou Person


Amazon Echo and Alexa Make Life Better for People with Disabilities - Lou Person


Amazon Echo and Alexa help people with disabilities.  Echo and the voice service which controls it, Alexa, provide the solution.  I want to share a story with you about a terrific young man named Dylan and how he uses Echo.

Our friends Karen and Jeff have a son named Dylan who is blind.  At a barbeque recently, we were talking about all the ways Dylan uses Echo in his life.  As an example, he reads Harry Potter through Echo using Alexa.  He also uses many of the applications and games available through the Amazon Alexa Console. 

Dylan's father, Jeff asked me if I could build a game for Dylan, so I wrote a small Alexa skill for Dylan called "Dylan Day".  Dylan Day will cite historical events which occurred on the day spoken.  It will pull the information from Wikipedia then read it out loud.  "Alexa, Ask Dylan Day what happened today".  "Alexa, Ask Dylan Day what happened on July 4th".  The Echo will read actual events which occurred throughout history on those days.

A skill is an application or game which Alexa runs.  In other words, developers train Alexa with specific skills they write.  In this case, "Dylan Day" will recite all the events which occurred on a certain day in history.  It will query against Wikipedia and read back the events on the date spoken.  Although the skill itself is relatively simply, hopefully Dylan feels like a rock star having his name used as the invocation phrase of a skill running through Alexa that is available to the entire world.

If you have an Echo, Dot or Tap install the skill "Dylan Day".  On your phone login to the Alexa app (on your computer go to: http://alexa.amazon.com).  Click on skills and search for "Dylan Day". 
Here are some of the interactions for the Skill:
"Alexa, Ask Dylan Day"
"Alexa, Ask Dylan Day what happened today"
"Alexa, Ask Dylan Day what happened on July Fourth"
"Alexa, Ask Dylan Day what happened on December 31"

Although the application is very simple, I hope it has a big impact for Dylan and anyone else who uses it. 

I wrote another post that is technical in nature which describes all the components that go into the Dylan application.  This includes the AWS Console, Lambda Service, Amazon Developer Console, Javascript JSON and AWS Explorer in Visual Studio.  You can view the post here:  http://blog.louperson.com/2016/07/AWS-Alexa-Skill-Lou-Person.html

Please reference the source of the initial code (which I modified slightly for Dylan Day).  The skill originated from an example skill publicly available found here: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/using-the-alexa-skills-kit-samples

I work at Amazon and the postings on this site are my own and don't necessarily represent Amazon's position.


Post by Lou Person, I work at Amazon Web Services.