1

我创建了一个小示例项目来结合 OnPageChanged 事件测试 AutoPage 命令。但是,似乎只有当我自己触摸屏幕并更改页面时才会触发该事件。该事件不是由自动分页触发的。我在官方文档中找不到任何相关信息:https ://developer.amazon.com/de/docs/alexa-presentation-language/apl-pager.html#pager_on_page_changed_property 这是我的文档:

{
  "type": "APL",
  "version": "1.1",
  "settings": {},
  "theme": "dark",
  "import": [],
  "resources": [],
  "styles": {},
  "onMount": [],
  "graphics": {},
  "commands": {},
  "layouts": {},
  "mainTemplate": {
    "parameters": [
      "payload"
    ],
    "items": [
      {
        "type": "Pager",
        "id": "pagerComponentId",
        "onPageChanged": [
          {
            "type": "SendEvent"
          }
        ],
        "navigation": "wrap",
        "height": "100%",
        "width": "100%",
        "item": [
          {
            "type": "Container",
            "height": "200dp",
            "width": "300dp",
            "paddingTop": "16dp",
            "paddingLeft": "16dp",
            "paddingRight": "16dp",
            "paddingBottom": "16dp",
            "items": [
              {
                "type": "Image",
                "height": "200dp",
                "width": "300dp",
                "source": "https://d2o906d8ln7ui1.cloudfront.net/placeholder_image.png"
              }
            ]
          },
          {
            "type": "Container",
            "items": [
              {
                "type": "Image",
                "height": "200dp",
                "width": "300dp",
                "source": "https://d2o906d8ln7ui1.cloudfront.net/placeholder_image.png"
              }
            ]
          },
          {
            "type": "Container",
            "items": [
              {
                "type": "Image",
                "height": "200dp",
                "width": "300dp",
                "source": "https://d2o906d8ln7ui1.cloudfront.net/placeholder_image.png"
              }
            ]
          }
        ]
      }
    ]
  }
}

这就是我在代码中启动它的方式

return handlerInput.responseBuilder
        //.speak(speechText)
        .addDirective({
            type: 'Alexa.Presentation.APL.RenderDocument',
            token: 'pagerToken',
            version: '1.0',
            document: require('./aplu/main2.json'),
            datasources: {
                data: {
                },
            }
        })
        .addDirective({
            type: 'Alexa.Presentation.APL.ExecuteCommands',
            token: 'pagerToken',
            commands: [

                        {
                            'type': 'AutoPage',
                            'componentId': 'pagerComponentId',
                            'delay': 3000,
                            'duration': 2000,
                        }
                    ]
        })
        .getResponse();

这是我的事件处理程序:

const test = {
    canHandle(handlerInput){
        return (handlerInput.requestEnvelope.request.type === 'Alexa.Presentation.APL.UserEvent') },
    handle(handlerInput) {
        return handlerInput.responseBuilder
            .speak("Test")
            .getResponse();
    }

};

正如我所说,只有当我自己触摸屏幕时,语音输出测试才有效。自动分页本身可以工作。它打算以这种方式工作吗?还是我做错了什么?

4

0 回答 0