对话状态在Alexa技能中未定义

时间:2018-10-07 15:44:44

标签: node.js alexa alexa-skills-kit

我正在使用nodejs ask sdk v2开发alexa技能。我正在遵循planMyTrip技能来了解多匝对话框。但是对话框状态是不确定的。请在下面找到代码:

'use strict';
const Alexa = require('ask-sdk-core');

const { HelpIntentHandler, CancelAndStopIntentHandler, SessionEndedRequestHandler, ErrorHandler } = require('./commonHandlers');

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
    },
    handle(handlerInput) {
        const speechText = "Welcome to IFSC Code Finder, let me know ifsc code for which bank are you looking for ?";
        return handlerInput.responseBuilder
            .speak(speechText)
            .reprompt(speechText)
            .withShouldEndSession(false)
            .getResponse();
    }
};

const InProgressIfscCodeIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
            handlerInput.requestEnvelope.request.intent.name === 'ifscCode' &&
            handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED' &&
            handlerInput.requestEnvelope.request.dialogState !== 'IN_PROGRESS';            
    },
    handle(handlerInput) {
        console.log('in progress intent handler', handlerInput.requestEnvelope.request.dialogState);
        const currentIntent = handlerInput.requestEnvelope.request.intent;
        return handlerInput.responseBuilder
            .addDelegateDirective(currentIntent)
            .getResponse();
    }
};

const CompletedIfscCodeIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
            handlerInput.requestEnvelope.request.intent.name === 'ifscCode'           
    },
    handle(handlerInput) {
        console.log("in completed intent handler");
        const speechText = "TEST TEST TEST";
        return handlerInput.responseBuilder
            .speak(speechText)
            .reprompt(speechText)
            .withShouldEndSession(false)
            .getResponse();        
    }
};

// register handlers
exports.handler = Alexa.SkillBuilders
    .custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        InProgressIfscCodeIntentHandler,
        CompletedIfscCodeIntentHandler,
        HelpIntentHandler,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler
    )
    .addErrorHandlers(ErrorHandler)
    .lambda();

执行流到达InProgress处理程序,但之后退出并显示“请求的技能响应有问题”。流永远不会到达完成的意图处理程序。我们想对开始对话状态进行哪些更改?请注意,我使用的所有插槽都没有要求确认设置为true。难道我做错了什么 ?请让我知道。

谢谢

1 个答案:

答案 0 :(得分:0)

上面的lambda代码没有任何问题。问题在于技能的交互模型。要启用对话框,我们需要将至少一个插槽的“是否需要此插槽”属性更新为true。