【发布时间】:2019-01-07 05:14:23
【问题描述】:
我正在尝试使用Alexa Presentation Language。我想知道如何在 node.js 中合并动态字符串(如 Output Speech 和 Title)(具体来说是Binding)。
如果我为outputSpeech 使用一些静态字符串并将其放入apl_template_export.json,那么技能可以正常运行,我可以在设备显示中看到输出。但是当我尝试使用binding时,技能失败了。虽然没有错误,但我在设备显示中也看不到任何输出(见图)。
这是我迄今为止一直在尝试的:
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: require('./apl_template_export.json'),
dataSources: {
"bodyTemplate1Data": {
"type": "object",
"objectId": "bt1Sample",
"title": urlParams.type,
"textContent": {
"primaryText": {
"type": "PlainText",
"text": outputSpeech
}
}
}
}
})
.speak(outputSpeech)
.getResponse();
apl_template_export.json:
{
"type": "APL",
"version": "1.0",
"import": [
{
"name": "alexa-layouts",
"version": "1.0.0"
}
],
"mainTemplate": {
"parameters": [
"payload"
],
"items": [
{
"type": "Text",
"text": "${dataSources.bodyTemplate1Data.textContent.primaryText.text}"
}
]
}
}
如果我将 ${dataSources.bodyTemplate1Data.textContent.primaryText.text} 替换为实际文本(如 “Hello World”),该技能将按预期工作。
我参考了here和here,原始存储库:https://github.com/alexa-labs/skill-sample-nodejs-level-up-riddles
谁能告诉我这里出了什么问题?
更新
我将text 变量更改为:
"items": [
{
"type": "Text",
"text": "Type: ${type}\nDatasources: ${dataSources != null} \nBodyTemplate: ${dataSources.bodyTemplate1Data != null}"
}
]
我得到这个作为输出:
Type: undefined
Datasources: false
BodyTemplate: false
所以问题不在于渲染输出,而是模板无法加载dataSources,这是实际问题。
它甚至无法加载其值已在模板中定义的type 变量。
【问题讨论】:
-
您能否捕获 cloudwatch 错误并将其发布在您的问题中?
-
没有错误。我收到一个输出(见图)。但 Alexa 显示设备无法呈现它。
-
请在日志中确认...获得输出并不意味着没有错误。我遇到了同样的错误,查看日志进一步帮助了我(输出可见但 ui 为空白)您是否也定义了 SessionEndedRequestHandler ?尝试评论它
-
我检查了日志中的最后 5 个条目,没有错误。我确实定义了我的
SessionEndedRequestHandler。但我认为这不是SessionEndedRequestHandler的问题,因为我正在启动技能并终止它。 (shouldEndSession是False) -
@AmodGokhale 请查看问题中的更新。
标签: node.js alexa alexa-skill alexa-presentation-language