alexa - 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"
}
}
}
}
}
解决方案
问题:我们无法检索 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
推荐阅读
- c# - EntityFramework - 虚拟 ICollection 查询
- python - 当视频即将结束时,函数 'cv::resize' 中出现错误!ssize.empty()
- javascript - 元素类中的 CSS @media - 使用 CSS 变量
- laravel - Laravel 的总 SUM 输入表单值
- visual-studio-code - 在 vscode 扩展 webview 中使用本地 .ttf
- google-apps-script - 在 Dialog flow fullfillment 中调用 Google sheet 宏
- python - 更改 seaborn 箱线图线彩虹颜色
- node.js - 如何修复 node.js 应用程序中的 cairo 错误:断言失败:(angle_max >= angle_min)
- python - 有没有办法在两个单独的 csv 文件中找到数据的标准偏差?
- python - 使用beautifulsoup解析得到准确的单词