首页 > 解决方案 > Alexa 技能请求中的多个权限解决方案PerAuthority

问题描述

我一直在研究 Alexa 技能,到目前为止它运行良好,但今天我遇到了一个奇怪的问题。在其他技能中也可以看到类似的问题。问题是我在我的技能请求 JSON 的 resolutionsPerAuthority 中获得了多个权限。这些权限具有不同的状态码来匹配槽值。因此,我的代码遇到了困难,因为 resolutionsPerAuthority 应该只有一个对象。

我正在使用亚马逊官方文档中提供的代码来获取插槽值,并且由于这种情况而失败。还有其他人面临类似问题吗?有什么解决办法吗?

这是我的请求 JSON:

{
    "version": "1.0",
    "session": {
        "new": false,
        "sessionId": "amzn1.echo-api.session.f4bf3a11-f882-4732-9275-6e494e0bca4d",
        "application": {
            "applicationId": "app id"
        },
        "attributes": {
            "launchCount": 0,
            "jokeCount": 0,
            "indexes": [
                34
            ],
            "lastSpeechOutput": {
                "outputSpeech": "response",
                "reprompt": "reprompt"
            },
            "history": [
                {
                    "IntentRequest": "LaunchRequest"
                }
            ],
            "currentJokeIndex": 34,
            "lastUseTimestamp": 0
        },
        "user": {
            "userId": "amzn1.ask.account.ncsdkncsdlcnskY"
        }
    },
    "context": {
        "Display": {
            "token": "string"
        },
        "System": {
            "application": {
                "applicationId": "id"
            },
            "user": {
                "userId": ""
            },
            "device": {
                "deviceId": "",
                "supportedInterfaces": {
                    "Display": {
                        "templateVersion": "1.0",
                        "markupVersion": "1.0"
                    }
                }
            },
            "apiEndpoint": "https://api.eu.amazonalexa.com",
            "apiAccessToken": ""
        }
    },
    "request": {
        "type": "IntentRequest",
        "requestId": "amzn1.echo-api.request.824ef2fe-5a6b-45c8-96d2-a5aa0063e9b5",
        "timestamp": "2018-07-26T13:47:56Z",
        "locale": "en-IN",
        "intent": {
            "name": "TellJokeIntent",
            "confirmationStatus": "NONE",
            "slots": {
                "joke": {
                    "name": "joke",
                    "value": "joke",
                    "resolutions": {
                        "resolutionsPerAuthority": [
                            {
                                "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.a4bb9873-04fa-486f-8e1e-e30cb3c3d669.joke",
                                "status": {
                                    "code": "ER_SUCCESS_MATCH"
                                },
                                "values": [
                                    {
                                        "value": {
                                            "name": "joke",
                                            "id": "e2ff3cfd4b43876adaa5767ce93bf7d3"
                                        }
                                    }
                                ]
                            },
                            {
                                "authority": "amzn1.er-authority.dynamic.amzn1.ask.skill.a4bb9873-04fa-486f-8e1e-e30cb3c3d669.joke",
                                "status": {
                                    "code": "ER_SUCCESS_NO_MATCH"
                                }
                            }
                        ]
                    },
                    "confirmationStatus": "NONE"
                }
            }
        }
    }
}

标签: alexaalexa-skills-kitalexa-skillalexa-slotalexa-app

解决方案


问题:我们无法检索 id 和与解析相关的各种数据。

原因:之前我们只有一个分辨率数组元素,我们将其引用为resolutionsPerAuthority[0]. 不过现在不止一个。

错误:其中一个分辨率项目显示Match和其他显示No Match。我们无法仅通过直接从resolutionsPerAuthority[0]

Anubhav 的解决方案:了解不一定只有分辨率数组的第一个元素才能显示Match代码。尝试 if else 或迭代该数组以定位哪个元素可以捕获您的请求。

//Check Status Code (Match/NoMatch) in 1st Element
console.log("Zero Code===>" +request.intent.slots.SlotName.resolutions.resolutionsPerAuthority[0].status.code); 

//Check Status Code (Match/NoMatch) in 2nd Element
console.log("One Code===>" +request.intent.slots.SlotName.resolutions.resolutionsPerAuthority[1].status.code); 

//Iterate and if Match condition is satisfied update the ID variable

if((request.intent.slots.SlotName.resolutions.resolutionsPerAuthority[0].status.code) === “ER_SUCCESS_MATCH")
 { 
      console.log("in If"); 
        try 
          { 
            var SlotID = request.intent.slots.SlotName.resolutions.resolutionsPerAuthority[0].values[0].value.id;                      console.log("SlotTwoID Collected"); 
           } 
        catch(Error) 
          {  
            console.log("In Catch”);
           }
 } 

else  
   { 
        console.log("in else"); 
          try 
              { 
               var SlotID = request.intent.slots.SlotName.resolutions.resolutionsPerAuthority[1].values[0].value.id;      console.log("SlotID Collected"); 
               } 
          catch(Error) 
             { 
             console.log("In Catch"); 
              }
     }

由于类似的问题,我无法检索插槽 ID


推荐阅读