Показать список шаблонов - PullRequest
0 голосов
/ 03 июля 2019

Я пытаюсь реализовать функцию списка шаблонов набора навыков 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);


},

Ответ, который я должен получить, должен быть пользовательским списком. Но я не понимаю

Ответы [ 2 ]

0 голосов
/ 09 июля 2019
I tried the following code yet the response was not rendered. 

const DisplayListIntentHandler = {
    canHandle(handlerInput){
        return handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'DisplayList';
    },

    handle(handlerInput){
        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"
                }
            }
            }
        ]
        }};

        return handlerInput.responseBuilder
        .addRenderTemplateDirective(template)
        .getResponse();

    }
};
0 голосов
/ 04 июля 2019

Похоже, это проблема в том, что 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

Я заметил, что вы используете v1 SDK - Iочень рекомендую использовать v2, так как это намного более прямо вперед.

https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs

Надеюсь, это поможет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...