使用 Alexa 的 HTTP-Endpoint 在 APL 中可视化列表

Visualizing a List in APL using HTTP-Endpoint for Alexa

我目前正在使用自己的 .NET-Backend 构建 Alexa Skill,它应该 return 一个包含来自我的服务的动态内容的 AlexaTextList。 Alexa 的请求如下所示:

{
"version": "1.0",
"session": {
    "new": false,
    "sessionId": "amzn1.echo-api.session.d5f8d9ee-bdd0-4c70-96g9-b468b6b76cd4",
    "application": {
        "applicationId": "amzn1.ask.skill.a07cbc1c-b942-47d6-8fa2-84ebb61f1b15"
    },
    "user": {
        "userId": "amzn1.ask.account.AE5FYATFIAFQF4UKWWBLICFMLP4ZV6KSNQFZJSECBBMKQFEL2UNUD46CDHO67QQPUQ4JZAG53CMBYUWVOWNVXMHRBBUT7ATRZDX6KRV4U2QU5FSHGL6JGOAHWRPS77PSB2N2MLFP2WKCCSC6SPZXVQKY45DLAXOD2OOFQLVGIZ6PCBRWZAEAKZKSMPWI4D36EUGPJDMVURI6BWY"
    }
},
"context": {
    "Viewports": [
        {
            "type": "APL",
            "id": "main",
            "shape": "RECTANGLE",
            "dpi": 160,
            "presentationType": "STANDARD",
            "canRotate": false,
            "configuration": {
                "current": {
                    "mode": "HUB",
                    "video": {
                        "codecs": [
                            "H_264_42",
                            "H_264_41"
                        ]
                    },
                    "size": {
                        "type": "DISCRETE",
                        "pixelWidth": 1024,
                        "pixelHeight": 600
                    }
                }
            }
        }
    ],
    "Viewport": {
        "experiences": [
            {
                "arcMinuteWidth": 246,
                "arcMinuteHeight": 144,
                "canRotate": false,
                "canResize": false
            }
        ],
        "mode": "HUB",
        "shape": "RECTANGLE",
        "pixelWidth": 1024,
        "pixelHeight": 600,
        "dpi": 160,
        "currentPixelWidth": 1024,
        "currentPixelHeight": 600,
        "touch": [
            "SINGLE"
        ],
        "video": {
            "codecs": [
                "H_264_42",
                "H_264_41"
            ]
        }
    },
    "Extensions": {
        "available": {
            "aplext:backstack:10": {}
        }
    },
    "System": {
        "application": {
            "applicationId": "amzn1.ask.skill.a07cbd1c-b982-47d6-8aa1-84eeb61f1b15"
        },
        "user": {
            "userId": "amzn1.ask.account.AE5FYATFIAFQF4UKWWBLICFMLP4ZV6KSNQFZJSECBBMKQFEL2UNUD46CDHO67QQPUQ4JZAG53CMBYUWVOWNVXMHRBBUT7ATRZDX6KRD4U2QU5FSHHL6JGOAHWRPS77QSB4N2MFFP2WKCCSC6SPZXVQKY45DLAXOD2OOFQLVGIZ6PCBRWZAEAKZKSMPWI4D36EUGPJDMVURI6BWY"
        },
        "device": {
            "deviceId": "amzn1.ask.device.AF7IR4TWRMUA5FWIUWMXJ7726QZIXXJJ4CF62N7S3N6Q5O3RTRGORGUCJ2IFWMKO2SYDWWCO4NH2AOGR35QTQSUVVJWJSU54YACLQJW2URDL6NIQMGTN7DGI7LX76B6Y4L45FMWMGBOCVC7JCFJOWQ4WTVYDYENBZUVMJQDZ4VU23MCWAC25Y",
            "supportedInterfaces": {}
        },
        "apiEndpoint": "https://api.eu.amazonalexa.com",
        "apiAccessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ.eyJhdWQiOiJodHRwczovL2FwaS5hbWF6b25hbGV4YS5jb20iLCJpc3MiOiJBbGV4YVNraWxsS2l0Iiwic3ViIjoiYW16bjEuYXNrLnNraWxsLmEwN2NiYzFjLWI5ODItNDdkNi04ZmExLTg0ZWViNjFmMWIxNSIsImV4cCI5MTYxMjM1MTY5MywiaWF0IjoxNjEyMzUxMzkzLCJuYmYiOjE2MTIzNTEzOTMsInByaXZhdGVDbGFpbXMiOnsiY29udGV4dCI6IkFBQUGBQUFBQVFESjl5V3BUNVYwd05XZnNmQk43YzdiS2dFQUFBQUFBQUM4WXQ3ZWNBNU4vUllSdmE1UENyM1dEUlJRQUljOWhodasd3E2Y29qckk3L01zVmFCTjl1aDRhOWd4Zmw4bFF5WEc3QU9MZTlGdjhoWjNBMUhyclpYeDBkM3A1Q2w4U3pyQ0dXQU1rSWI3eVlHL1B0dDYvT05qYW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vhNKEANKa-gVpyXdAR-uHZbfutuTW6qDy_1eVdIUdr-4ye-b2MTUbp8sJ9ag2zfR_sgQEkGEbqF5L9dGtpaWS06zivuV8gxWUkwOMihNrmv6WP8YC_Qkj_FfQ-OTcJ-2q0BpiDtURX8Ai8JW0c1qhSglJHXlqVqCLpyuDWR0QhJHzS0n5H0opoyNUAF3w4nibxPxV9jmo4jdM8Fqgz3I1rvKPa2nTsrGPJfLDFxPsxtNuUGwxbWglJu4nkzg--f2cTgZE5vmKsaJoUzt5IB3c9H07IPhwC82Iw"
    }
},
"request": {
    "type": "IntentRequest",
    "requestId": "amzn1.echo-api.request.ff4e8edd-f343-4842-82bb-79eb1c1f5c22",
    "locale": "en-GB",
    "timestamp": "2021-02-03T11:23:13Z",
    "intent": {
        "name": "RESOLVE_CONFLICT",
        "confirmationStatus": "NONE",
        "slots": {
            
        }
    },
    "dialogState": "COMPLETED"
}

}

我的服务正在响应:

{
"version": "1.0",
"response": {
    "outputSpeech": {
        "type": "PlainText",
        "text": "Please select a cat."
    },
    "directives": [
        {
            "type": "Alexa.Presentation.APL.RenderDocument",
            "token": "resolve_action",
            "document": {
                "type": "APL",
                "version": "1.4",
                "theme": "dark",
                "import": [
                    {
                        "name": "alexa-layouts",
                        "version": "1.2.0"
                    }
                ],
                "resources": [],
                "onMount": [],
                "mainTemplate": {
                    "parameters": [
                        "payload"
                    ],
                    "items": [
                        {
                            "type": "AlexaTextList",
                            "id": "peopleList",
                            "headerTitle": "${payload.textListData.title}",
                            "headerBackButton": false,
                            "headerAttributionImage": "${payload.textListData.logoUrl}",
                            "backgroundBlur": false,
                            "backgroundColorOverlay": true,
                            "listItems": "${payload.textListData.listItems}"
                        }
                    ]
                }
            },
            "datasources": {
                "textListData": {
                    "type": "object",
                    "objectId": "textList",
                    "title": "Meeting Assistant | Resolve Conflict",
                    "listItems": [
                        {
                            "primaryText": "Mr. Cat",
                            "imageAlignment": "center",
                            "imageBlurredBackground": true,
                            "imageScale": "best-fit",
                            "imageThumbnailSource": "https://ichef.bbci.co.uk/news/976/cpsprodpb/12A9B/production/_111434467_gettyimages-1143489763.jpg",
                            "primaryAction": [
                                {
                                    "type": "SetValue",
                                    "componentId": "peopleList",
                                    "property": "headerTitle",
                                    "value": "Click"
                                }
                            ]
                        }
                    ],
                    "logoUrl": "https://w3-mediapool.hm.edu/mediapool/media/fk10/fk10_lokal/02_aktuelles/02_news/wintersemester_2020/langmann_3/FirstSpirit_1606121272258Akoa-logo-gradient-AKOA_Sunrise_35cm.png"
                }
            }
        }
    ],
    "shouldEndSession": false
}

}

我没有在 Alexa 控制台的测试环境中获得漂亮的可视化效果,而是检索了以下内容:

"error": {
    "type": "INVALID_RESPONSE",
    "message": "An exception occurred while dispatching the request to the skill."
}

由于这种情况很难调试(如果您对这个问题也有任何建议,请告诉我),我花了很长时间才走到这一步,但我就是无法解决这个问题.错误消息非常通用,只是无法正确解析它。但根据文档,应该没问题 (https://developer.amazon.com/en-US/docs/alexa/alexa-presentation-language/apl-interface.html#renderdocument-directive)。

有趣的是,只有当我在响应模型中使用指令字段时才会发生这种情况。基本的卡片响应工作正常,所以我认为问题一定出在指令的某个地方......你有什么想法如何继续这个吗?还是我错过了什么?

非常感谢您!

我想通了是什么问题。我使用的是不同的 HTTP 2xx-状态代码,而 Alexa 只接受 200 (https://developer.amazon.com/en-US/docs/alexa/custom-skills/request-and-response-json-reference.html#http-header-1)。

因此,我的问题与我的请求数据或开发者控制台中的任何设置无关,而是我的 HTTP-Header。这让我有点困惑,因为我实际上返回的是可以接受的成功状态代码,但显然 Alexa 对此有严格的要求。我不知道这一点。 感谢所有试图帮助我并验证我的 JSON-response.

的人