Alexa ASK Lambda bug

问题描述 投票:1回答:1

我试图在LaunchRequest之后创建一个技能,在StartGame函数中播放初始欢迎消息,询问用户他们的学校,然后用户在SetSchool意图中说他们的学校,然后技能说出一条消息。现在最后一部分有一个错误,我不知道如何调试它。

错误:enter image description here

我的代码:

/* 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();
};

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

amazon-web-services aws-lambda alexa alexa-skills-kit alexa-skill
1个回答
0
投票

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

那说你的问题似乎是国家的意图定义问题。您已经将状态设置为START,但startStateHandlers没有定义SetSchool Intent。

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

© www.soinside.com 2019 - 2024. All rights reserved.