【问题标题】:dialog state is undefined in alexa skill对话框状态在 Alexa 技能中未定义
【发布时间】:2018-10-09 01:39:32
【问题描述】:

我正在使用 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。难道我做错了什么 ?请告诉我。

谢谢

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      相关资源
      最近更新 更多