You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无Lambda函数的Alexa Echo Show技能如何添加APL模板响应

问题解答

不需要使用官方PHP SDK,Alexa技能的运行逻辑只校验你返回的JSON是否符合响应规范,和你后端用什么语言、是否托管在Lambda上没有关系,你自建PHP服务端只要生成正确结构的JSON响应就能正常触发APL渲染。


第一步:开启技能APL权限

先到Alexa开发者控制台的对应技能配置页,找到「接口」选项,开启「Alexa Presentation Language (APL)」的开关,保存后重新构建技能模型,这一步是前提,没开的话即使返回APL字段也不会生效。

第二步:在原有响应中添加APL指令字段

你需要在原有响应的response节点下新增directives数组,数组内放入APL的渲染指令,完整的响应结构示例如下:

{
  "version": "1.0",
  "sessionAttributes": {},
  "response": {
    "outputSpeech": {
      "type": "PlainText",
      "text": "My output speech"
    },
    "card": {
      "type": "Simple",
      "title": "hELLO",
      "content": "Meetings"
    },
    "reprompt": {
      "outputSpeech": {
        "type": "PlainText",
        "text": "Can I help you with anything else?"
      }
    },
    "shouldEndSession": false,
    // 新增的APL指令部分
    "directives": [
      {
        "type": "Alexa.Presentation.APL.RenderDocument",
        "token": "any_unique_token_you_define",
        "document": {
          "type": "APL",
          "version": "1.7",
          "mainTemplate": {
            "parameters": [
              "payload"
            ],
            "items": [
              {
                "type": "Container",
                "width": "100vw",
                "height": "100vh",
                "justifyContent": "center",
                "items": [
                  {
                    "type": "Text",
                    "text": "${payload.textData.title}",
                    "fontSize": "48dp",
                    "textAlign": "center"
                  },
                  {
                    "type": "Text",
                    "text": "${payload.textData.content}",
                    "fontSize": "24dp",
                    "textAlign": "center",
                    "spacing": "20dp"
                  }
                ]
              }
            ]
          }
        },
        "datasources": {
          "textData": {
            "title": "Hello Echo Show",
            "content": "This is a custom APL page rendered without Lambda"
          }
        }
      }
    ]
  }
}

常见生效失败排查点

  • 确保APL文档的语法正确,没有字段缺失、类型错误,你可以用Alexa开发者控制台的APL作者工具先验证模板的可运行性
  • 仅在请求头的context.System.device.supportedInterfaces包含Alexa.Presentation.APL字段时返回APL指令,避免在不支持屏幕的设备上返回导致错误
  • 不要修改原有响应的必填字段结构,APL指令是增量添加的字段,不需要改动你之前已经正常运行的逻辑

内容的提问来源于stack exchange,提问作者lazyCoder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 11:06:03