alexa技能中的多轮对话错误

Errors with multi turn dialog in alexa skills

我创建了一个名为 "BuyDog" 的技能,它的调用名称是 "dog app"

也就是说,只有听到调用名称后,我才能使用里面定义的意图。 (正确吗?)

然后我将带有插槽的 Intents 定义为:

"what is {dog} price."

"Tell me the price of {dog}."

其中插槽 {dog} 的插槽类型为 "DogType"。 我已将此插槽标记为需要履行

然后我将端点添加到 AWS lambda 函数中,我在 node.js 中使用了 factskills 项目的蓝图代码,并做了一些小改动以查看工作情况。

const GET_DOG_PRICE_MESSAGE = "Here's your pricing: ";

const data = [
    'You need to pay 00.',
    'You need to pay Rs2000.',
    'You need to pay 00.',
    'You need to pay INR 3000.',

];
const handlers = {
//some handlers.......................
'DogIntent': function () {
        const factArr = data;
        const factIndex = Math.floor(Math.random() * factArr.length);
        const randomFact = factArr[factIndex];
        const speechOutput = GET_DOG_PRICE_MESSAGE + randomFact;
}
//some handlers.......................
};

根据我在

时期待的关于代码

I say: "Alexa open dog app"

它应该准备好听取意图 "what is {dog} price." 和另一个。相反,它表示来自 node.js 代码的 data[] 数组的随机字符串。在 Intent 被说出后,我期待这个响应,因为 intent 需要插槽才能完成。

而当

I say: "open the dog app and Tell me the price of XXXX."

它要求 "which breed" (这是我定义的问题) 但它工作正常并显示定价

Alexa says: "Here's your pricing: You need to pay 00."

(或数据数组中的其他值)对于任何 XXXX(即狗或非狗类型)。 为什么 alexa 不确认单词是否在插槽集中?

而当

I say: "open the dog bark".

我原以为 alexa 不会理解这个问题,但它 给了我一个关于吠叫的事实 为什么?那是怎么发生的?
Alexa 是否有一套默认的技能?比如搜索 google/amazon 等等...

我很困惑。请帮助我了解发生了什么?

您没有 post 很多代码,因此很难准确地说出您的意思,但通常要处理不完整的事件,您可以使用这样的不完整偶数处理程序:

const IncompleteDogsIntentHandler = {
// Occurs when the required slots are not filled
canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'DogIntent'
        && handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED'
},
async handle(handlerInput) {
    return handlerInput.responseBuilder
        .addDelegateDirective(handlerInput.requestEnvelope.request.intent)
        .getResponse();
}

您通常在 lambda 的 index.js 文件中将此处理程序添加到实际处理程序的正上方 这可能无法解决您的所有问题,但可以帮助您处理用户未提及狗的事件。

如果您没有完整的代码来确切了解发生了什么并提供代码答案,我希望对您的 problems/questions 的解释能为您指明正确的方向。


1。发射技能

I say: "Alexa open dog app"
It should just be ready to listen to the intent...

你希望 Alexa 只是倾听,但实际上,Alexa 打开了你的技能,并希望你在这一点上有一个通用的欢迎回应。 Alexa 将向您的 Lambda 发送 Launch Request。这与 IntentRequest 不同,因此您可以通过检查 request.type 来确定这一点。通常找到:

this.event.request.type === 'LaunchRequest'

我建议您向 Lambda 添加一些日志记录,并使用 CloudWatch 查看来自 Alexa 的传入请求:

console.log("ALEXA REQUEST= " + event)

2。槽值识别

I say: "open the dog app and Tell me the price of XXXX."
Why is alexa not confirming the word is in slot set or not?

Alexa 不会将 slot 限制为 slotType 中设置的插槽值。您给 slotType 的值用作指导,但也接受其他值。

由您在您的 Lambda 函数中验证这些槽值以确保它们被设置为您接受的值。有很多方法可以做到这一点,所以首先要检测插槽中填充了什么。通常找到:

this.event.request.intent.slots.{slotName}.value;

如果您选择在slotType中设置同义词,那么Alexa也会提供她推荐的槽值解析。例如,您可以将 "Rotty" 作为 "Rottweiler" 的同义词,Alexa 将用 "Rotty" 填充该插槽,但也建议您将其解析为 "Rottweiler".

var resolutionsArray = this.event.request.intent.slots.{slotName}.resolutions.resolutionsPerAuthority;

同样,使用 console.log 和 CloudWatch 查看 Alexa 接受和填充的槽值。


3。故意不启动技能

I say: "open the dog bark".
I expected alexa to not understand the question but it gave me a fact about barking.

您必须在您的技能之外执行此操作,Alexa 将接受任何输入并尝试识别启用的技能,或者使用她对默认能力的最佳猜测来处理。

Alexa 确实有默认的 built-in 能力(实际上不是技能)来回答一般问题,并且很有趣和友好。你可以在这里看到她自己能做什么:Alexa - Things To Try

所以我的猜测是,Alexa 认为您问的是关于狗叫的问题,因此提供了答案。你可以试着问问她"What is a dog bark",看看她的回答是否和"open the dog bark"一模一样,以证实这些怀疑。


要真正理解开发 Alexa 技能,您应该花时间非常熟悉此文档: Alexa Request and Response JSON Formats