首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
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

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
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62855239

复制
相关文章

相似问题

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