Search code examples
pythonalexa-skills-kitamazon-echo

Echo Show python skill not generating display template


I am developing a skill for echo show. However i am not able to display all the display templates and stuff from python lambda skill. I am able to do the alexa skill perfectly and able to add image url's which works fine. But when display template is added,it is showing invalid response.

I have followed this tutorial https://medium.freecodecamp.org/how-to-design-and-code-alexa-skills-for-amazons-echo-show-c5716da8fee5

And this was the extra parameter to be added to the json response.

    directives: [
    {
    type: “Display.RenderTemplate”,
   template: {
       type: “BodyTemplate1”,
       token: “T123”,
       backButton: “HIDDEN”,
       backgroundImage: {
           contentDescription: “StormPhoto”,
           sources: [
               {
                  url: “https://s3.amazonaws.com/hurricane-data/hurricaneBackground.png”
               }
           ]
      },
      title: “Hurricane Center”,
      textContent: {
          primaryText: {
              text: output,
              type: “PlainText”
          }
      }
  }
}],

This is how my modified render template method looks like. def build_speechlet_response(title, output, reprompt_text, should_end_session): imgurl="https://thesweetsetup.com/wp-content/uploads/2014/10/scanbot_ico_1024.png"

return {
    'outputSpeech': {
        'type': 'PlainText',
        'text': output
    },
    'card': {
        'type': 'Standard',
        'title':  title,
        'text': output,
        "image": {
            "smallImageUrl": imgurl,
            "largeImageUrl": imgurl
        }
    },
    'reprompt': {
        'outputSpeech': {
            'type': 'PlainText',
            'text': reprompt_text
        }
    },
directives: [
    {
    type: “Display.RenderTemplate”,
   template: {
       type: “BodyTemplate1”,
       token: “T123”,
       backButton: “HIDDEN”,
       backgroundImage: {
           contentDescription: “StormPhoto”,
           sources: [
               {
                  url: “https://s3.amazonaws.com/hurricane-data/hurricaneBackground.png”
               }
           ]
      },
      title: “Hurricane Center”,
      textContent: {
          primaryText: {
              text: output,
              type: “PlainText”
          }
      }
  }
}],

    'shouldEndSession': should_end_session
}

But this gives me error as invalid response format.What am i doing wrong here.


Solution

  • This worked for me in python. But not able to render the list template.

    def build_response(session_attributes, speechlet_response,text_response,speech_response,secondary_text,teritary_text,should_end_session):
    session=should_end_session
    return {
        'version': '1.0',
        'sessionAttributes': session_attributes,
        'response': {
               "directives": [
                 {
      "type": "Display.RenderTemplate",
      "template": {
    "type": "BodyTemplate2",
    "token": "A2079",
    "backButton": "VISIBLE",
    "backgroundImage": {
      "contentDescription": "Textured grey background",
      "sources": [
        {
          "url": "https://i.pinimg.com/originals/8b/e4/cc/8be4ccbbc43b1131c59b09b6c27f2e58.jpg"
        }
      ]
       },
      "title": "Document Scanner",
      "image": {
        "contentDescription": "testing car",
        "sources": [
          {
            "url": "https://thesweetsetup.com/wp-content/uploads/2014/10/scanbot_ico_1024.png"
          }
        ]
      },
      "textContent": {
        "primaryText": {
          "text": '''<font size='6'>'''+text_response+'''</font>''',
          "type": "RichText"
        },
         "secondaryText": {
          "text": secondary_text,
          "type": "PlainText"
        },
        "tertiaryText": {
          "text": teritary_text,
          "type": "PlainText"
        }
      }
    }
     }
               ],
               "outputSpeech": {
                 "type": "SSML",
                 "ssml": '''<speak>'''+speech_response+''' </speak>'''
               },
               "reprompt": {
                 "outputSpeech": {
                   "type": "SSML",
                   "ssml": "<speak>how can i help you ?</speak>"
                 }
               },
               "shouldEndSession": session,
                "card": {
                 "type": "Standard",
                 "title": "content.simpleCardTitle",
                 "content": "content.simpleCardContent"
               }
             }
    }
    

    The text_response,speech_response,secondary_text,teritary_text are all string parameters added.