首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用确认时的Alexa递归意向委托

使用确认时的Alexa递归意向委托
EN

Stack Overflow用户
提问于 2020-07-11 22:26:33
回答 3查看 541关注 0票数 2

我正在写一个阿列克谢对话与意图确认。当确认被拒绝时,我希望通过委托给这个对话框来重新启动相同的对话框。我正在进行类似于堆栈溢出问题的描述。正如这个问题的解决方案所描述的那样,当dialogState仍然是IN_PROGRESS时,我进行委托。在我的例子中,Alexa总是用不太有意义的信息来回应,要求的技能的反应是有问题的。应用程序日志中没有错误消息。

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

代码语言:javascript
运行
复制
{
  "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?"
          }
        ]
      }
    ]
  }
}
代码语言:javascript
运行
复制
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();
  }
};

我错过了什么?

EN

回答 3

Stack Overflow用户

发布于 2020-07-14 20:33:53

您没有指定是否触发DeniedUserIntentHandler。如果错误是在DeniedUserIntentHandler内部生成的,那么它是由于Delegate Directive格式错误造成的。

您的回复应该是:

代码语言:javascript
运行
复制
return handlerInput.responseBuilder
  .speak('Username was not confirmed. Please try again.')
  .addDelegateDirective({
                         "type": "Dialog.Delegate",
                         "updatedIntent": {
                               name:"UserIntent",
                               confirmationStatus:"NONE",
                               slots: {
                                 UserName: {
                                 name:"UserName",
                                 confirmationStatus:"NONE",
                                 source:"USER"
                                 }
                               }
                            }
                         })
                         .getResponse();

您删除意图的前一状态的原因,因为您希望从一开始就开始您的意图操作。

您也可以像这样使用代码:引用https://forums.developer.amazon.com/questions/92334/answering-no-to-intent-confirmation.html?childToView=206243#comment-206243

代码语言:javascript
运行
复制
currentIntent.confirmationStatus = "NONE";
Object.keys(currentIntent.slots).forEach(
    (slotName) => {
      var slot = intent.slots[slotName];
      delete slot.value;
      slot.confirmationStatus = "NONE";
    }
);

var delegatedirective = {"type": "Dialog.Delegate",
                         "updatedIntent": currentIntent};
票数 1
EN

Stack Overflow用户

发布于 2020-07-15 19:15:56

你现在面临的问题是真实的。亚马逊论坛中也提到了这个问题。但是,只要稍加修改,就可以实现类似的行为。UserName激活时隙值确认,而UserIntent激活删除确认。您的交互模型类似于如下所示:

代码语言:javascript
运行
复制
{
"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 ?"
                }
            ]
        }
    ]
  }
}

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

代码语言:javascript
运行
复制
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();
    }
  }  
};
票数 1
EN

Stack Overflow用户

发布于 2020-07-15 11:51:13

多亏了@tahiat的回复,我才能解决我最初的问题。在更新的意图中,时隙对象必须包含意图的插槽(没有值)。但是他的第一个代码片段包含一个错误。醚的使用

代码语言:javascript
运行
复制
.addDirective({
  "type": "Dialog.Delegate", 
  "updatedIntent": { 
     name:"UserIntent", 
     ...
  }
})

或使用

代码语言:javascript
运行
复制
.addDelegateDirective({
  name:"UserIntent", 
  ...
})

因为addDelegateDirective希望有一个意图作为参数。

但现在我正面临着另一个问题。我在对话框中使用确认。在确认被拒绝后,当我回到UserIntent的初始状态时,我永远不会收到确认消息的提示。这是因为request.intent.confirmationStatus保留了它的值,即'DENIED',尽管我在updateIntent中将它重置为'NONE'

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62855239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档