1

我有一个在 ALEXA (Amazon Echo) 上运行的应用程序。我正在用图像实现家庭卡片显示。如果响应只有一张卡,则何时用于特定呼叫。它显示得很好。附上截图 在此处输入图像描述

"Response": {
  "version" : "1.0",
  "sessionAttributes": {
    "UserCityId": "1",
    "UserCity": "London",
    "latitude": "51.50735090",
    "longitude": "-0.12775830",
    "categoryID": "900",
    "company_id": "1154916",
    "first_name": "User FName",
    "yes_no_for": "",
    "cat_start_limit": "0",
    "categoryName": "music",
    "total_cat_events": "2178",
    "show_rec": "5"
  },
  "response": {
    "outputSpeech": {
      "type": "PlainText",
      "text": "This is what alexa speaks out"
    },
    "card": {
      "type": "Standard",
      "title": "Music events in London",
      "text": "The speech passed to alexa",
      "image": { 
        "smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
        "largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
      }
     },
    "reprompt": {
      "outputSpeech": {
        "type": "PlainText",
        "text": "Would you like to know events for music ,sports, or something else. Please select one category"
      }
    },
     "shouldEndSession": false
  }
}

上面的代码有效

下面列出了问题:但是如果相同的响应具有卡数组(多张卡),则 alexa 无法给出错误。

"Response": {
  "version": "1.0",
  "sessionAttributes": {
    "UserCityId": "1",
    "UserCity": "London",
    "latitude": "51.50735090",
    "longitude": "-0.12775830",
    "categoryID": "900",
    "customer_id": "1154916",
    "first_name": "UserFNAME",
    "yes_no_for": "",
    "cat_start_limit": "0",
    "categoryName": "music",
    "total_cat_events": "2178",
    "show_rec": "5"
  },
  "response" : {
    "outputSpeech" : {
      "type": "PlainText",
      "text": "5th. Baba Yaga's Hut Presents Jambinai, at Corsica Studios, on Monday, May 16th , 7 30 pm"
    },                
    "card": [{
      "type": "Standard",
      "title": "Music events in London",
      "text": "1. Dove Jones Blues Jam!, at Phoenix Artist Club, on Monday, May 16th , 7pm",
      "image": {
        "smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
        "largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
      }
    }, {
      "type": "Standard",
      "title": "Music events in London",
      "text": "2. The Hillbilly Moon Explosion, at The Borderline, on Monday, May 16th, 7pm",
      "image": {
        "smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
        "largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
      }
    }, {
      "type": "Standard",
      "title": "Music events in London",
      "text": "3. Sian Evans Of Kosheen, at 100 Club, on Monday, May 16th , 7 30 pm",
      "image": {
        "smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
        "largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
      }
    }, {
      "type": "Standard",
      "title": "Music events in London",
      "text": "4. Rinocerose, at The Water Rats, on Monday, May 16th , 7 30 pm",
      "image": {
        "smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
        "largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
      }
    }, {
      "type": "Standard",
      "title": "Music events in London",
      "text": "5. Baba Yaga's Hut Presents Jambinai, at Corsica Studios, on Monday, May 16th , 7 30 pm",
      "image": {
        "smallImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg",
        "largeImageUrl": "https:\/\/xyz.com\/version\/sports-car-1374425_960_720.jpg"
      }
    }],
    "reprompt": {
      "outputSpeech": {
        "type": "PlainText",
        "text": "Would you like to know events for music ,sports, or something else. Please select one category"
      }
    },
    "shouldEndSession" : false
  }
}

上面的代码不起作用。

这是我要转换的东西:请看截图 在此处输入图像描述

对于伦敦电话中的事件,我会在单张卡片中获得 5 个事件的列表。我想为每个事件分配图像并创建它的卡片。

任何人都可以帮助解决该方法并找出在 JSON 响应中使用多张卡的问题。是不是Alexa只支持单卡响应?

4

1 回答 1

1

响应中的 card 属性采用对象而不是数组。

这是亚马逊在其网站上使用的示例:

{
  "version": "string",
  "sessionAttributes": {
    "string": object
  },
  "response": {
    "outputSpeech": {
      "type": "string",
      "text": "string",
      "ssml": "string"
    },
    "card": {
      "type": "string",
      "title": "string",
      "content": "string",
      "text": "string",
      "image": {
        "smallImageUrl": "string",
        "largeImageUrl": "string"
      }
    },
    "reprompt": {
      "outputSpeech": {
        "type": "string",
        "text": "string",
        "ssml": "string"
      }
    },
    "shouldEndSession": boolean
  }
}

如果您想尝试制作多张卡片,您可以尝试发送多个回复,但我不确定这是否可行。

我认为您最好的选择是针对您的问题考虑与用户进行不同的交互,然后出示多张卡片。

于 2016-05-16T13:45:36.357 回答