我正在写一个阿列克谢对话与意图确认。当确认被拒绝时,我希望通过委托给这个对话框来重新启动相同的对话框。我正在进行类似于这堆栈溢出问题的描述。正如这个问题的解决方案所描述的那样,当dialogState仍然是IN_PROGRESS时,我进行委托。在我的例子中,Alexa总是用不太有意义的信息来回应,要求的技能的反应是有问题的。应用程序日志中没有错误消息。
我的技能模型和lambda代码如下:
{
"interactionModel": {
"languageModel": {
"invocationName": "hello",
"intents": [
{
"name": "UserIntent",
"slots": [
{
"name": "UserName",
"type": "AMAZON.FirstName",
"samples": [
"My name is {UserName}",
"I am {UserName}",
"{UserName}"
]
}
],
"samples": [
"My name is {UserName}",
"I am {UserName}"
]
}
],
"types": []
},
"dialog": {
"delegationStrategy": "SKILL_RESPONSE",
"intents": [
{
"name": "UserIntent",
"confirmationRequired": true,
"prompts": {
"confirmation": "Confirm.Intent.UserName"
},
"slots": [
{
"name": "UserName",
"type": "AMAZON.FirstName",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.UserName"
}
}
]
}
]
},
"prompts": [
{
"id": "Elicit.Slot.UserName",
"variations": [
{
"type": "PlainText",
"value": "What is your name?"
}
]
},
{
"id": "Confirm.Intent.UserName",
"variations": [
{
"type": "PlainText",
"value": "You are {UserName}. Is this right?"
}
]
}
]
}
}const DeniedUserIntentHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'UserIntent' &&
request.dialogState === 'IN_PROGRESS' &&
request.intent.confirmationStatus === 'DENIED';
},
async handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const currentIntent = request.intent;
const userName = Alexa.getSlotValue(handlerInput.requestEnvelope, 'UserName');
console.log(`DeniedUserIntentHandler:
request.dialogState=${request.dialogState}, request.intent.confirmationStatus=${request.intent.confirmationStatus}, userName=${userName}`);
return handlerInput.responseBuilder
.speak('Username was not confirmed. Please try again.')
.addDelegateDirective({
name: 'UserIntent',
confirmationStatus: 'NONE',
slots: {}
})
.getResponse();
}
};我错过了什么?
发布于 2020-07-15 11:51:13
多亏了@tahiat的回复,我才能解决我最初的问题。在更新的意图中,时隙对象必须包含意图的插槽(没有值)。但是他的第一个代码片段包含一个错误。醚的使用
.addDirective({
"type": "Dialog.Delegate",
"updatedIntent": {
name:"UserIntent",
...
}
})或使用
.addDelegateDirective({
name:"UserIntent",
...
})因为addDelegateDirective希望有一个意图作为参数。
但现在我正面临着另一个问题。我在对话框中使用确认。在确认被拒绝后,当我回到UserIntent的初始状态时,我永远不会收到确认消息的提示。这是因为request.intent.confirmationStatus保留了它的值,即'DENIED',尽管我在updateIntent中将它重置为'NONE'。
https://stackoverflow.com/questions/62855239
复制相似问题