Lukasz Krysiewicz
Published © GPL3+

Invisible Dice

Tutorial on how to build an Alexa Amazon Skill.

BeginnerFull instructions provided2 hours1,639
Invisible Dice

Things used in this project

Hardware components

Echo Dot
Amazon Alexa Echo Dot
×1

Software apps and online services

AWS Lambda
Amazon Web Services AWS Lambda
Alexa Skills Kit
Amazon Alexa Alexa Skills Kit

Story

Read more

Schematics

schematic

Code

Invisible Dice

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

// Used when a user asks for help.
const helpMessage    = "If you want run a skill you should say: Throw a dice. Give me a result. Roll a dice. " +
                       "If you want close a skill you should say: Stop or Cancel. " +
                       "For repeat please say help me.";

// Used when a user opens skill.
const welcomeMessage  = "Welcome to Invisible Dice.  " +
                        "Tell a command or please say help me.";

// Used when a user says cancel.
const cancelMessage = "Ok, see you next time!";

// Used when a user says stop.
const stopMessage   = "Bye, bye, see you next time!";



// Used to randomise numbers
const t_numbers = [
      "one",
      "two",
      "three",
      "four",
      "five",
      "six"];


// Attaching handlers
// Here we have added the following handlers:
// HelpIntent: envoked when a user asks for help.
// StopIntent/CancelIntent: envoked when a user asks to end the skill.
// ThrowADiceIntent: envoked when a user ask about number.


const handlers = {
/*
  Launch Request ( no intent )

  <invocation name>
  Ask <invocation name>
  Begin <invocation name>
  Do <invocation name>
  Launch <invocation name>
  Load <invocation name>
  Open <invocation name>
  Play <invocation name>
  Play the game <invocation name>
  Resume <invocation name>
  Run <invocation name>
  Start <invocation name>
  Start playing <invocation name>
  Start playing the game <invocation name>
  Talk to <invocation name>
  Tell <invocation name>
  Use <invocation name>
*/
   'LaunchRequest': function () {
        this.emit(':ask', welcomeMessage, welcomeMessage);
   },
/*
<some action>

<some action> <connecting word> <invocation name>
where the <connecting word> is one of the following: by, from, in, using, with

Ask <invocation name> <connecting word> <some action>
where the <connecting word> is one of the following: to, about, for

Tell <invocation name> <connecting word> <some action>
Where the <connecting word> is one of the following: to, that

Use <invocation name> <connecting word> <some action>
Where the <connecting word> is one of the following: and, to

Ask <invocation name> <some action>
Tell <invocation name> <some action>
Search <invocation name> for <some action>
Open <invocation name> for <some action>
Talk to <invocation name> and <some action>
Open <invocation name> and <some action>
Launch <invocation name> and <some action>
Start <invocation name> and <some action>
Resume <invocation name> and <some action>
Run <invocation name> and <some action>
Load <invocation name> and <some action>
Begin <invocation name> and <some action>
*/
   'ThrowADiceIntent': function () {
        var sNumber = t_numbers[Math.floor(Math.random() * t_numbers.length)];
        var sOutput = "The result is:" + "  "+ sNumber;

        this.emit(':tell', sOutput, sOutput);
   },

    'AMAZON.HelpIntent': function () {
        this.emit(':ask',helpMessage, helpMessage);
    },

    'AMAZON.StopIntent': function () {
        this.emit(':tell', stopMessage, stopMessage);
    },

    'AMAZON.CancelIntent': function () {
        this.emit(':tell', cancelMessage, cancelMessage);
    }

}

exports.handler = function (event, context, callback) {
    var alexa = Alexa.handler(event, context);
    alexa.registerHandlers(handlers);
    alexa.execute();
};

Intent Schema

JSON
{
  "intents": [
    {
      "name": "AMAZON.CancelIntent",
      "samples": [
        "Cancel"
      ]
    },
    {
      "name": "AMAZON.HelpIntent",
      "samples": []
    },
    {
      "name": "AMAZON.StopIntent",
      "samples": [
        "Stop"
      ]
    },
    {
      "name": "ThrowADiceIntent",
      "samples": [
        "Ask invisible dice {Action}",
        "Tell invisible dice {Action}",
        "Search invisible dice for {Action}",
        "Talk to invisible dice and {Action}",
        "Open invisible dice and {Action}",
        "Launch invisible dice and {Action}",
        "Start invisible dice and {Action}",
        "Resume invisible dice and {Action}",
        "Run invisible dice and {Action}",
        "Load invisible dice and {Action}",
        "Begin invisible dice and {Action}",
        "Ask invisible dice to {Action}",
        "Ask invisible dice about {Action}",
        "Ask invisible dice for {Action}",
        "Tell invisible dice to {Action}",
        "Tell invisible dice that {Action}",
        "Use invisible dice to {Action}",
        "Use invisible dice and {Action}",
        "{Action} by invisible dice",
        "{Action} from invisible dice",
        "{Action} in invisible dice",
        "{Action} using invisible dice",
        "{Action} with invisible dice",
        "{Action}"
      ],
      "slots": [
        {
          "name": "Action",
          "type": "LIST_OF_ACTIONS",
          "samples": []
        }
      ]
    }
  ],
  "types": [
    {
      "name": "LIST_OF_ACTIONS",
      "values": [
        {
          "id": null,
          "name": {
            "value": "throw a dice",
            "synonyms": []
          }
        },
        {
          "id": null,
          "name": {
            "value": "give me a result",
            "synonyms": []
          }
        },
        {
          "id": null,
          "name": {
            "value": "roll a dice",
            "synonyms": []
          }
        }
      ]
    }
  ]
}

Credits

Lukasz Krysiewicz

Lukasz Krysiewicz

8 projects • 21 followers
Embedded Software Engineer

Comments