Alexa 自定义插槽类型:无意图价值 [英] Alexa Custom Slot Type: No value in intent

查看:27
本文介绍了Alexa 自定义插槽类型:无意图价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在亚马逊开发者论坛上发布了这个问题,但在那里没有得到答复.我想 Stackoverflow 从一开始就应该是首选:

I've already posted this question to the amazon developer forum but don't receive an answer there. I guess Stackoverflow should've been the first choice from the beginning:

根据我的理解,如果我使用自定义槽类型,即使其可能值的列表不包含口语,口语仍会传递给函数.文档说

From my understanding if I use a Custom Slot Type even if the list of its possible values does not contain the spoken word the spoken word is still passed to the function. The documentation says

自定义槽类型不等同于枚举.如果口语理解系统识别出列表之外的值,仍可能返回.

A custom slot type is not the equivalent of an enumeration. Values outside the list may still be returned if recognized by the spoken language understanding system.

现在我有一个自定义槽类型LIST_OF_PERSONS,其值为Matthias|Max 和一个语句

Now I have a Custom Slot Type LIST_OF_PERSONS with values Matthias|Max and an utterance of

EmployeeDetailsIntent {Person} 

如果我使用不在 LIST_OF_PERSONS 中的值调用此意图,则仍会调用意图,但 JSON 不包含插槽的值"键:

If I call this intend with a value not in LIST_OF_PERSONS the Intent still gets called but the JSON does not contain a "value" key for the Slot:

"request": {
    "type": "IntentRequest",
    "requestId": "EdwRequestId.a943e233-0713-4ea5-beba-d9287edb6083",
    "locale": "de-DE",
    "timestamp": "2017-03-09T14:38:29Z",
    "intent": {
      "name": "EmployeeDetailsIntent",
      "slots": {
        "Person": {
          "name": "Person"
        }
      }
    }
  }

这是按设计工作"还是错误?那么我如何访问 Intent 中的口语?由于 this.event.request.intent.slots.Person.value 未定义?

Is this "works as designed" or a bug? How do I access the spoken word in the Intent then? As this.event.request.intent.slots.Person.value is undefined?

我的代码位于 AWS lambda 中,我使用的是 nodejs alexa-sdk 1.0.7 版.我的技能语言是德语.

My code lives in AWS lambda and I'm using the nodejs alexa-sdk Version 1.0.7. The language of my Skill is German.

推荐答案

(免责声明:这篇文章总结了我自己的解决方法".它可能是也可能不是最佳方法".似乎对我有用,所以我认为我将在这里简要分享/记录)

(disclaimer: this post summarises my own "workaround". It might or might not be the "best way". Seems to have worked for me so thought I would share / document it here briefly)

我最近遇到了类似的问题,因为一个看起来像这样的话语:

I've recently bumped into similar issues for an utterance that looks like this:

告诉我关于{townName}"

如果我说告诉我关于伦敦的情况",它会起作用.

If I say "tell me about London", it works.

如果我说告诉我"(故意缺少一个{townName}),程序死亡"(并返回一个与您的类似的JSON,未定义 this.event.request.intent.slots.townName.value)

If I say "tell me about" (deliberately missing a {townName}), the program "dies" (and returns a JSON looking similar to your one, with undefined this.event.request.intent.slots.townName.value)

虽然我不能 100% 确定这是一个功能"(即我们需要编写更智能的代码来解决这个问题)还是问题"(即 Alexa 团队需要解决或修复).这种情况最近在我的认证过程中引起了真正的问题.

Though I'm not 100% sure whether this is meant to be a "feature" (i.e. we need to write smarter code to work around this) or "problem" (i.e. Alexa team needs to address or fix). This scenario has caused a real issue when it came to the certification process for me recently.

为了解决这个问题,我实施了一种解决方法(或修复,无论你怎么称呼它),以避免 Alexa 因这种极端情况而死亡".

To get through this, I've implemented a workaround (or fix, whatever you call it) to avoid Alexa from "dying" as a result of this edge case.

来自 Alexa skill-sample-nodejs-trivia index.js 文件,我发现了一个片段函数可以帮助我解决这个问题(为了简单起见,我对我的例子做了一些编辑):

From the Alexa skill-sample-nodejs-trivia index.js file, I've found a snippet function that helped me work around this (I've edited it a bit for my example for simplicity):

function isAnswerSlotValid(intent) {
    var answerSlotFilled = intent && intent.slots &&
        intent.slots.townName && intent.slots.townName.value;
    return answerSlotFilled
}

(即此函数返回 True 用于插槽 townName 的有效值和 False 用于未定义/否则).

(i.e. this function returns True for valid values for the slot townName and and False for undefined / otherwise).

在定义意图时,我可以使用这个函数来绕过"空槽值场景:

When it comes to defining the intent, I could use this function to "get around" an empty slot value scenario:

var startHandlers = Alexa.CreateStateHandler(states.START,{

  // bla bla bla//

  "AnswerIntent": function() {  

    // handel missing slot value
    var answerSlotValid = isAnswerSlotValid(this.event.request.intent);

    if (answerSlotValid && moreConditions) {
      // do something fun
    }
    else {
      // handle empty slot scenario
    }
  }

  // bla bla bla//

}

有兴趣看看是否有更好/更合适"的解决方案来更优雅地处理空/未定义的插槽.

Would be interested to see if there are better / more "proper" solutions to this to handle empty / undefined slots more elegantly.

这篇关于Alexa 自定义插槽类型:无意图价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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