alexa-skills-kit - 显示列表模板
问题描述
我正在尝试实现 Alexa 技能包的列表模板功能。但是,我无法以适当的格式返回响应。
我已经使用官方文档实现了该功能。但是,我不知道如何将列表模板的响应返回到我的自定义意图
'ListTemplate':function(){
var title = "This is a sample list";
var speechOutput = "Showing the sample list";
var template = {
"type":"Display.RenderTemplate",
"template":{
"type":"ListTemplate1",
"token":"ListTemplate",
"title":title,
"backButton":"VISIBLE",
"backgroundImage":{
"contentDescription":"backgroundImage",
"sources":[
{
"url":"https://democard.s3.amazonaws.com/hostel-720.jpg"
}]
},
"listItems":[{
"token":"item1",
"image":{
"sources":[{
"url":"https://democard.s3.amazonaws.com/c-v-raman-college-of-engineering-squarelogo-1534916004379+(3).jpg"
}],
"contentDescription":"first item of list"
},
"textContent":{
"primaryText":{
"type":"PlainText",
"text":"primary Text is here"
},
"secondaryText":{
"type":"PlainText",
"text":"Secondary text is here"
}
},
},
{
"token":"item2",
"image":{
"sources":[{
"url":"https://democard.s3.amazonaws.com/c-v-raman-college-of-engineering-squarelogo-1534916004379+(3).jpg"
}],
"contentDescription":"second item"
},
"textContent":{
"primaryText":{
"type":"PlainText",
"text":"primary text is here"
},
"secondaryText":{
"type":"PlainText",
"text":"secondary text"
}
}
}
]
}};
var directives =[ template ];
//return build_speechlet_response(title,speechOutput,directives, SESSION_LIST);
// 功能
build_speechlet_response(title,speechOutput,directives,phase){
const response = {
"version": "1.0",
"response": {
"outputSpeech":{
"type":"PlainText",
"text":"what else would you like to see"
},
"card":{
'type':'Simple',
'title':title,
'content':speechOutput
},
"directives":directives,
"shouldEndSession":'False'
},
"sessionAttributes":{
"template":"list_"
}
};
// return response;
this.emit(':tell',response);
},
我应该得到的响应必须是自定义列表。但我不明白
解决方案
看起来这个问题是response
一个对象。它应该类似于this.emit(':tell', speechOutput)
(speechOutput
字符串在哪里)。
如果您还想发送一张卡片,那就是this.emit(':tellWithCard', speechOutput, cardTitle, cardContent, imageObj)
.
但是,由于您正在尝试使用渲染模板,它会是这样的:
this.response.speak(speechOutput)
.cardRenderer(cardTitle, cardContent, cardImage)
.renderTemplate(template);
this.emit(':responseReady');
你可以在这里找到更多信息 - https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/tree/1.x
我确实注意到您使用的是 SDK 的 v1 - 我真的建议您使用 v2,因为它更直接。
https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs
希望有帮助。
推荐阅读
- python - 使用 sklearn 从多个数据样本中整理概率、预测、系数
- google-drive-api - 有关访问链接共享文件的新安全更改的问题
- python - 解析时输入为文本的 Pandas 数字会添加一位小数并将数据类型显示为 float64
- php - 带有 WordPress 的多个 Bootstrap 5 缩略图轮播的 PHP 增量 ID
- android - 尝试在 kotlin 中使用 .startsWith() 和 .contains() 方法时出错
- python - 终端在不应该时接受键盘输入
- c - 汇编代码返回数组中值的总和
- python - 无法部署 EB Django 应用程序
- perl - Capture::Tiny 与 Mason 不兼容?
- mysql - 防止重复插入而不插入忽略