【问题标题】:Echo Show python skill not generating display templateEcho Show python技能不生成显示模板
【发布时间】:2017-09-05 06:54:29
【问题描述】:

我正在开发一种回声表演技能。但是我无法显示来自 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
}

但这给了我错误的响应格式。我在这里做错了什么。

【问题讨论】:

    标签: python alexa-skills-kit amazon-echo


    【解决方案1】:

    这在 python 中对我有用。但无法呈现列表模板。

    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都是添加的字符串参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      • 2018-10-31
      • 1970-01-01
      • 2017-03-26
      • 1970-01-01
      相关资源
      最近更新 更多