Навык Echo Show python не создает шаблон отображения

Развиваю навык эхо-шоу. Однако я не могу отобразить все шаблоны отображения и прочее из навыков Python Lambda. Я могу отлично использовать навык Alexa и могу добавить URL-адрес изображения, который отлично работает. Но когда добавляется шаблон отображения, он показывает неверный ответ.

Я следовал этому руководству https://medium.freecodecamp.org/how-to-design-and-code-alexa-skills-for-amazons-echo-show-c5716da8fee5

И это был дополнительный параметр, который нужно было добавить в ответ json.

    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”
          }
      }
  }
}],

Вот как выглядит мой модифицированный метод шаблона рендеринга. def build_speechlet_response (название, вывод, 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
}

Но это дает мне ошибку как недопустимый формат ответа. Что я здесь делаю неправильно.


person lost Coder    schedule 05.09.2017    source источник


Ответы (1)


Это сработало для меня в питоне. Но не удалось отобразить шаблон списка.

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"
           }
         }
}

Text_response,speech_response,secondary_text,teritary_text — все это добавленные строковые параметры.

person lost Coder    schedule 07.09.2017