首页 > 解决方案 > 显示列表模板

问题描述

我正在尝试实现 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);


},

我应该得到的响应必须是自定义列表。但我不明白

标签: alexa-skills-kit

解决方案


看起来这个问题是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

希望有帮助。


推荐阅读