在alexa技能中多圈对话槽确认?

时间:2018-06-08 07:08:14

标签: amazon-web-services dialog aws-lambda alexa slot

我为lambda中的单个插槽确认写了代码。但是,这不起作用。只会调用名称槽而不是限定槽。

// Confirm slot: name
                if(intentObj.slots.name.name == "name") {
                    if (intentObj.slots.name.confirmationStatus !== 'CONFIRMED') {
                        if (intentObj.slots.name.confirmationStatus !== 'DENIED') {
                            // slot status: unconfirmed
                            const slotToConfirm = 'name';
                            const speechOutput = 'Your name is ' + intentObj.slots.name.value + ', is that right?';
                            //  const repromptSpeech = speechOutput;
                            this.emit(':confirmSlot', slotToConfirm, speechOutput);
                        } else {
                            // slot status: denied => ask again
                            const slotToElicit = 'name';
                            const speechOutput = 'What is your name?';
                            //const repromptSpeech = 'Please tell me what is your name';
                            const updatedIntent = 'DialogIntent';
                            this.emit(':elicitSlot', slotToElicit, speechOutput, updatedIntent);
                        }
                    }
                }

            // Confirm slot: qualification
            if(intentObj.slots.qualification.qualification == "qualification") {
                    if (intentObj.slots.qualification.confirmationStatus !== 'CONFIRMED') {
                        if (intentObj.slots.qualification.confirmationStatus !== 'DENIED') {
                            // slot status: unconfirmed
                            const slotToConfirm = 'qualification';
                            const speechOutput = 'Your qualification is ' + intentObj.slots.qualification.value + ', is that right?';
                            //  const repromptSpeech = speechOutput;
                            this.emit(':confirmSlot', slotToConfirm, speechOutput);
                        } else {
                            // slot status: denied => ask again
                            const slotToElicit = 'qualification';
                            const speechOutput = 'What is your qualification?';
                            //const repromptSpeech = 'Please tell me what is your qualification';
                            const updatedIntent = 'DialogIntent';
                            this.emit(':elicitSlot', slotToElicit, speechOutput, updatedIntent);
                        }
                    }
                }

请分享有关插槽确认的任何信息。

1 个答案:

答案 0 :(得分:0)

您的第一个广告位的if语句将始终为真。

  

if(intentObj.slots.name.name ==“name”){...}

这是因为slots.slotName.name将始终是广告位的名称。这是一个无用的if陈述 您可能想要检查插槽是否已设置且值是否为空。然后你可以改变你的逻辑。

if(intentObj.slots.name && intentObj.slots.name.value !== null) { 
    // check if confirmed or not
} else {
    // elicit slot "name"
}

您的第二个广告位的if语句将始终为false。

  

if(intentObj.slots.qualification.qualification ==“qualification”){

这是因为qualification数组中没有slots.slotName个键。所以只需将其更改为与上面的类似,检查qualification槽是否已设置且值是否为空。

if(intentObj.slots.qualification && intentObj.slots.qualification.value !== null) { 
    // check if confirmed or not
} else {
    // elicit slot "qualification"
}