Alexa ASK Lambda 漏洞

Alexa ASK Lambda bug

我正在尝试制作一项技能,在 LaunchRequest 之后,在 StartGame 函数中播放初始欢迎消息,询问用户他们的学校,然后用户在 SetSchool 意图中说出他们的学校,然后技能说了一个信息。现在最后一部分有bug,不知道怎么调试

错误:

我的代码:

/* eslint-disable  func-names */
/* eslint-disable  dot-notation */
/* eslint-disable  new-cap */
/* eslint quote-props: ['error', 'consistent']*/
/**
 * This sample demonstrates a simple skill built with the Amazon Alexa Skills
 * nodejs skill development kit.
 * This sample supports en-US lauguage.
 * The Intent Schema, Custom Slots and Sample Utterances for this skill, as well
 * as testing instructions are located at https://github.com/alexa/skill-sample-nodejs-trivia
 **/

'use strict';

const Alexa = require('alexa-sdk');
const questions = require('./question');

const ANSWER_COUNT = 4; // The number of possible answers per trivia question.
const GAME_LENGTH = 10;  // The number of questions per trivia game.
const GAME_STATES = {
    TRIVIA: '_TRIVIAMODE', // Asking trivia questions.
    START: '_STARTMODE', // Entry point, start the game.
    HELP: '_HELPMODE', // The user is asking for help.
};
const APP_ID = undefined; // TODO replace with your app ID (OPTIONAL)

const languageString = {
    'en': {
        'translation': {
            'QUESTIONS': questions['HS_QUESTIONS_EN_US'],
            'GAME_NAME': 'Science Bowl',
            'HELP_MESSAGE': 'I will ask you %s multiple choice questions. Respond with the number of the answer. ' +
                'For example, say one, two, three, or four. To start a new game at any time, say, start game. ',
            'REPEAT_QUESTION_MESSAGE': 'To repeat the last question, say, repeat. ',
            'ASK_MESSAGE_START': 'Would you like to start playing?',
            ...
        },
    },
};

const newSessionHandlers = {
    'LaunchRequest': function () {
        this.handler.state = GAME_STATES.START;
        this.emitWithState('StartGame', true);
    },
    'SetSchool': function() {
        this.handler.state = GAME_STATES.START;
        this.emitWithState('School', true);
    },
    'AMAZON.StartOverIntent': function () {
        this.handler.state = GAME_STATES.START;
        this.emitWithState('StartGame', true);
    },
    'AMAZON.HelpIntent': function () {
        this.handler.state = GAME_STATES.HELP;
        this.emitWithState('helpTheUser', true);
    },
    'Unhandled': function () {
        const speechOutput = this.t('START_UNHANDLED');
        this.emit(':ask', speechOutput, speechOutput);
    },
};

...

const startStateHandlers = Alexa.CreateStateHandler(GAME_STATES.START, {
    'StartGame': function (newGame) {
        let speechOutput = newGame ? this.t('NEW_GAME_MESSAGE', this.t('GAME_NAME')) + this.t('WELCOME_MESSAGE', GAME_LENGTH.toString()) : '';

        this.handler.state = GAME_STATES.START;
        this.emit(':ask', speechOutput, speechOutput);
    },
    'School': function(newGame) {           
        this.handler.state = GAME_STATES.START;
        this.response.speak('test');
        this.emit(':responseReady');
    }
});

exports.handler = function (event, context) {
    const alexa = Alexa.handler(event, context);
    alexa.appId = APP_ID;
    // To enable string internationalization (i18n) features, set a resources object.
    alexa.resources = languageString;
    alexa.registerHandlers(newSessionHandlers, startStateHandlers, triviaStateHandlers, helpStateHandlers); // these were defined earlier
    alexa.execute();
};

我排除了大部分代码,所以它适合这里。我想尝试调试它,但我什至不知道如何查看错误消息。我该怎么办?

如果您在 AWS 上托管,可以在 CloudWatch 中找到 Lambda 日志。 从 AWS 控制台打开 cloudwatch,然后单击左侧菜单中的日志 link。您应该能够从那里找到您的 Lambda 服务。

也就是说,您的问题似乎是国家对 Intent 定义的问题。 您已经将状态设置为开始,但 startStateHandlers 没有定义 SetSchool 意图。

要解决此问题,您要么必须将 SetSchool 意图定义添加到 startStateHandlers,要么将状态重置为包含 SetSchool 意图的状态,然后再在 StartGame 处理程序中发出响应。