我正在研究一种技巧,目的是要问一个问题,然后转到意图,从用户那里得到答案并测试是对还是假,然后回到第一个意图去问另一个问题。
>当技能提出第一个问题时,它会从用户那里得到答案,然后对其进行测试并返回正确或错误
但是在下一个问题中它给出了错误
Directive \"Dialog.Delegate\" can be used only when a dialog is active and hasn't been completed
代码在这里
const askQuestionIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'askQuestion'
},
handle(handlerInput) {
const { responseBuilder } = handlerInput;
let speechText = 'nodes are loaded';
return dbHelper.getTrack('0').then((data) => {
nIndex = data.Items[0].nodeOrder
console.log("start " + nIndex)
let listNodes = data.Items[0].nodes
console.log("listNodes start " + nIndex)
while (listNodes[nIndex].node_type === 'milestone') {
nIndex++;
}
console.log("nIndex after loop " + nIndex)
speechText = listNodes[nIndex].node.activity.text
console.log("speech text " + speechText )
return dbHelper.updateTrack(nIndex).then(() => {
console.log("speech saying")
return responseBuilder
.speak(speechText)
.addDelegateDirective('takeAnswer')
.getResponse();
})
.catch((err) => {
const speechText = "error"
console.log(err)
return responseBuilder
.speak(speechText)
.getResponse();
})
})
}
};
const takeAnswerIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'takeAnswer'
},
handle(handlerInput) {
console.log("INTENT TAKE_ANSWER")
const { responseBuilder } = handlerInput;
let speechText = 'nodes are loaded';
let displayText = '';
let intent = handlerInput.requestEnvelope.request.intent;
let TOFvalue = intent.slots.TOF.value;
let TOF = intent.slots.TOF.resolutions.resolutionsPerAuthority[0].values[0].value.name;
console.log("Intent ", JSON.stringify(intent))
return dbHelper.getTrack('0').then((data) => {
nIndex = data.Items[0].nodeOrder
console.log("start2 " + nIndex)
let listNodes = data.Items[0].nodes
isTrue = listNodes[nIndex].node.activity.true
if((isTrue && (TOF === 'true')) || (!isTrue && (TOF === 'false'))) {
speechText = "true "
} else {
speechText = " false"
}
console.log("TOF slot type " + TOF)
console.log("TOF slot value " + TOFvalue)
nIndex++;
console.log("deleting tof ")
console.log(intent.slots.TOF.value)
return dbHelper.updateTrack(nIndex).then(() => {
return responseBuilder
.speak(speechText)
.addDelegateDirective('askQuestion')
.getResponse();
})
.catch((err) => {
const speechText = "error"
console.log(err)
return responseBuilder
.speak(speechText)
.getResponse();
})
})
}
};
他们当然是SkillBuilders,并且所有数据库查询都能正常工作
感谢您为我提供的帮助