我为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);
}
}
}
请分享有关插槽确认的任何信息。
答案 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"
}