ALEXA

ASK API

Intent:

For every function implemented, there should be corresponding Intent created in the development portal. If it is not implemented, we WILL NOT be able to call the function. Say you are emitting Play/Quit in your function, when there is no corresponding Play or Quit intent, execution will be thrown and will be caught in the Unhandled function.

It is good practice to have 'Unhandled' function to prevent bad user experience.

SLOTS:

Slotes are only needed if we need to pass any utterance to the script. Say, you are asking for username of the person using the skill, you can have a slot with username, and use it by calling

this.event.request.intent.slots.username.value

Session:

We can save variables in session by setting a name and a value in the attributes, which can be referred in any handler functions. There can be sessions for individual handlers as well.

this.attributes['numberoftimes'] = 0;

When 'NewSession' function is set, it is automatically called when the skill is invoked. We can use our session variables and other variables required for the skill.

Handlers:

Handlers function can be used to switch between handlers by setting the state. For using handlers the handler function should be use CreateStateHandler. Then the function can set the handler.state to the required state. This will be handy when using different functionality say PLAYMODE, GUESSMODE, STARTMODE, etc. The names of the state can have any names.

Say when we are emit and ask for 'yes','no', different handlers could have different implementation of yes/no. If we set the state of the handler before emit. The response will be sent to the appropriate state set in function.

In the below example though we have play function in different handlers, by setting the state of the handler will invoke the appropriate handler.

This is node js example

var Alexa = require('alexa-sdk');

exports.handler = function(event, context, callback){

var alexa = Alexa.handler(event, context, callback);

alexa.registerHandlers(handler,newSessionHandlers,startGameHandlers); //multiple handlers

alexa.execute();

};

var states = {

PLAYMODE: '_PLAYMODE', GUESSMODE: '_GUESSMODE', STARTMODE: '_STARTMODE'

};

var newSessionHandlers = {

'NewSession': function() {

if(Object.keys(this.attributes).length === 0) { // Check - if first time the skill invoked

this.attributes['play count'] = 0;

}

this.handler.state = states.STARTMODE;

this.emit(':ask', 'Welcome to Alexa you like to play?', 'Say play to start or exit to quit.');

}

};

var handler = Alexa.CreateStateHandler(states.STARTMODE,{

'Play': function () {

this.emit(':ask', 'Which game do yo like to play');

},

'Quit': function(){

this.emit(':tell', 'You can play other game by saying ...');

}

});

var handler = Alexa.CreateStateHandler(states.GUESSMODE,{

'Play': function () {

this.emit(':ask', 'Guess a number');

},

'Quit': function(){

this.emit(':tell', 'Good bye!');

}

} );

-------------------- LINKS -----------------

blondiebits ( this is using old api, but it is good video to learn about alexa)

Reindeers example code - video walks through the step by step process of creating the skill - Ask about reindeers and get details description about it

https://www.youtube.com/watch?v=5zsKViLKhi0

Boilder plate - template

https://drive.google.com/drive/folders/0B7TGomMdILscblZuSXM4bjJYcmc

https://github.com/blondiebits/code-in-5/tree/master/Alexa%20Part%20II/ReindeerFacts/src

Big Nerd Ranch-

Six part series which explains on the basic concepts of alexa

https://www.youtube.com/watch?v=QxgdPI1B7rg

Codes released to the video

https://github.com/bignerdranch/developing-alexa-skills-solutions/tree/master/4_persistence/solution

Memory Game - https://developer.amazon.com/blogs/post/Tx14R0IYYGH3SKT/Flask-Ask-A-New-Python-Framework-for-Rapid-Alexa-Skills-Kit-Development