简体   繁体   English

检查插槽中是否设置了“值”

[英]Check if “value” is set in slot

I'm moving the first steps with the Alexa app. 我正在使用Alexa应用程序迈出第一步。 I want to develop a simple intent that answers with a person name {personName} if a "value" was set in the slot. 我想开发一个简单的意图,如果在插槽中设置了“值”,则使用人名{personName}进行回答。 However, I am not able to understand what's wrong with the following code: as the check is enabled Alexa does not understand the request, even if the input json is correct. 但是,我无法理解以下代码的问题:由于启用了检查,即使输入的json正确,Alexa也无法理解请求。

I was inspired by another StackOverflow question about input validation Alexa input validation for type AMAZON.NUMBER using dialog model 我受到另一个有关输入验证的StackOverflow问题的启发,该问题使用对话框模型对AMAZON.NUMBER类型的Alexa输入验证

const AnswerUserIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest'
            && handlerInput.requestEnvelope.request.intent.name ==='AnswerUserIntent';
    },
    handle(handlerInput) {
        var pNameObj = this.event.request.intent.slots.personName
        var testValue = pNameObj.hasOwnProperty("value");
        if (testValue) {
            var speechText = 'You entered the intent with a value!';
        }else{
            var speechText = 'You just entered the intent';
        }

        return handlerInput.responseBuilder
            .speak(speechText)
            //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
            .getResponse();
    }
};

I would do something like this: 我会做这样的事情:

 var name = handlerInput.requestEnvelope.request.intent.slots.personName.value;
 var testValue= (name != undefined) ? true : false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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