Alexa自定义广告位类型:意图中没有值

编程入门 行业动态 更新时间:2024-10-05 05:12:05
本文介绍了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 该Intent仍被调用,但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.

为了解决这一问题,我最近实现了一个真正的问题。

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自定义广告位类型:意图中没有值

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

发布评论

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

>www.elefans.com

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