使用确认时的Alexa递归意图委派

编程入门 行业动态 更新时间:2024-10-08 10:26:26
本文介绍了使用确认时的Alexa递归意图委派的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写带有意图确认的Alexa对话框.当确认被拒绝时,我想通过委托该对话框再次重新启动同一对话框.我按照此堆栈中所述进行操作溢出问题.如该问题的解决方案中所述,当dialogState仍为IN_PROGRESS时,我进行委派.在我的情况下,Alexa总是以不太有意义的消息为响应所请求的技能的响应存在问题.应用程序日志中没有错误消息.

I am writing an Alexa dialog with intent confirmation. When confirmation is denied I want to restart the same dialog again by delegating to this very dialog. I am proceeding like described in this stack overflow question. As described in the solution to this question I do the delegation when the dialogState is still IN_PROGRESS. In my case Alexa always responds with the not very meaningful message There was a problem with the requested skill's response. No error message in the application log.

我的技能模型和lambda代码如下:

My skill model and the lambda code are as follows:

{ "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(); } };

我想念什么?

推荐答案

您现在面临的问题是真实的.亚马逊论坛. 但是,您可以稍作修改即可实现类似的行为. UserName 激活插槽值确认,UserIntent 删除确认. 您的互动模型如下所示:

The problem you are facing now is real one. This issue is also mentioned in amazon forum. However you can achieve similar behavior with slight modification. Activate slot value confirmation for UserName and remove confirmation for UserIntent. Your interaction model would be similar like below:

{ "interactionModel": { "languageModel": { "invocationName": "demo app", "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}" ] }, { "name": "AMAZON.NavigateHomeIntent", "samples": [] } ], "types": [] }, "dialog": { "intents": [ { "name": "UserIntent", "delegationStrategy": "SKILL_RESPONSE", "confirmationRequired": false, "prompts": {}, "slots": [ { "name": "UserName", "type": "AMAZON.FirstName", "confirmationRequired": true, "elicitationRequired": true, "prompts": { "confirmation": "Confirm.Slot.247378890994.1277345498514", "elicitation": "Elicit.Slot.UserName" } } ] } ], "delegationStrategy": "ALWAYS" }, "prompts": [ { "id": "Elicit.Slot.UserName", "variations": [ { "type": "PlainText", "value": "What is your name?" } ] }, { "id": "Confirm.Slot.247378890994.1277345498514", "variations": [ { "type": "PlainText", "value": "your name is {UserName} , right ?" } ] } ] } }

您可以添加以下单个代码处理程序:

you can add this single code handler:

const UserIntenStartedHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'IntentRequest' && request.intent.name === 'UserIntent'; }, async handle(handlerInput) { const request = handlerInput.requestEnvelope.request; const currentIntent = Alexa.getIntentName(handlerInput.requestEnvelope); const slot = Alexa.getSlot(handlerInput.requestEnvelope, 'UserName'); if (slot.confirmationStatus !== 'CONFIRMED') { return handlerInput.responseBuilder .addDelegateDirective(request.intent) .getResponse(); } else { return handlerInput.responseBuilder .speak('your Final name is ' + slot.value + '. cheers') .withShouldEndSession(true) .getResponse(); } } };

更多推荐

使用确认时的Alexa递归意图委派

本文发布于:2023-11-28 06:28:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641297.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   意图   Alexa

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!