使用确认时的Alexa递归意图委派 [英] Alexa Recursive Intent Delegation when using Confirmations

查看:151
本文介绍了使用确认时的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();
  }
};

我想念什么?

推荐答案

您现在面临的问题是真实的.亚马逊

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递归意图委派的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆