简体   繁体   中英

Different Invocations with one Alexa Skill

I have a skill SkillIntent that when you ask it a ask about a specific game, it replies with the description of that skill. Works perfectly - What I'm trying to get it do now, however, is to reply with WHO has that Skill, if asked differently.

Below is my working code:

'use strict';

var AlexaSkill = require('./AlexaSkill'),
    descriptions = require('./descriptions');

var APP_ID = undefined;

var ZombicideSkills = function () {
    AlexaSkill.call(this, APP_ID);
};

// Extend AlexaSkill
ZombicideSkills.prototype = Object.create(AlexaSkill.prototype);
ZombicideSkills.prototype.constructor = ZombicideSkills;

ZombicideSkills.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) {
    var speechText = "You can ask a question like, what does this skill do? ... Now, what can I help you with.";

    var repromptText = "For instructions on what you can say, please say help me.";
    response.ask(speechText, repromptText);
};

ZombicideSkills.prototype.intentHandlers = {
    "SkillIntent": function (intent, session, response) {
        var skillSlot = intent.slots.Skill,
            skillName;
        if (skillSlot && skillSlot.value){
            skillName = skillSlot.value.toLowerCase();
        }

        var cardTitle = "Description for " + skillName,
            description = descriptions[skillName],
            speechOutput,
            repromptOutput;
        if (description) {
            speechOutput = {
                speech: description,
                type: AlexaSkill.speechOutputType.PLAIN_TEXT
            };
            response.tellWithCard(speechOutput, cardTitle, description);
        } else {
            var speech;
            if (skillName) {
                speech = "I'm sorry, I don't know if I know " + skillName + ". What else can I help with?";
            } else {
                speech = "I'm sorry, I currently do not know that skill. What else can I help with?";
            }
            speechOutput = {
                speech: speech,
                type: AlexaSkill.speechOutputType.PLAIN_TEXT
            };
            repromptOutput = {
                speech: "What else can I help with?",
                type: AlexaSkill.speechOutputType.PLAIN_TEXT
            };
            response.ask(speechOutput, repromptOutput);
        }
    },

    "AMAZON.StopIntent": function (intent, session, response) {
        var speechOutput = "Goodbye";
        response.tell(speechOutput);
    },

    "AMAZON.CancelIntent": function (intent, session, response) {
        var speechOutput = "Goodbye";
        response.tell(speechOutput);
    },

    "AMAZON.HelpIntent": function (intent, session, response) {
        var speechText = "You can ask questions such as, what does this skill do, or, you can say exit... Now, what can I help you with?";
        var repromptText = "You can say things like, what does this skill do, or you can say exit... Now, what can I help you with?";
        var speechOutput = {
            speech: speechText,
            type: AlexaSkill.speechOutputType.PLAIN_TEXT
        };
        var repromptOutput = {
            speech: repromptText,
            type: AlexaSkill.speechOutputType.PLAIN_TEXT
        };
        response.ask(speechOutput, repromptOutput);
    }
};

exports.handler = function (event, context) {
    var zombicide = new ZombicideSkills();
    zombicide.execute(event, context);
};

It's modeled very similarly to that of the MC Helper. Would I just implement an additional intentHandlers called 'ActorIntent' and then in the Utterences specify ActorIntent what {actors} have the {skill} skill?

I've been playing around with the idea, but I'm not quite sure how to troubleshoot with Lambda functions yet - It's kind of just 'upload and see if the endpoint is reachable'.

It would be annoying if I had to have two -different- skills for this, but I'm unsure? Is it just an issue with my code base, and I should be able to go and create an ActorIntent without issue?

Define a different Intent, for example, SkillOwnerIntent and in the interaction model in the Alexa Developer Portal, define utterances for that intent. You definitely do not need to make another skill for this.

A solution with good user experience would be the following:

  1. A user aks about a game-skill which triggers your SkillIntent

    In your code: Save this skill in a variable (eg as a string)

  2. Alexa tells your skill's description and might ask for further questions.

  3. The user can now ask: Which actors have this skill? This triggers your intent ActorIntent.

    Utterances: ActorIntent Which actors have this skill?

  4. You know which skill the user is talking about (because you stored it in a variable). Now alexa can tell the specific actors.

Intent schema example:

{
"intents": [
  {
    "intent": "ActorIntent"
  },
  {
    "slots": [
      {
        "name": "skill",
        "type": "SKILL"
      }
    ],
    "intent": "SkillIntent"
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM