无法在单一响应中显示Alexa上的多个家庭卡显示

时间:2016-05-16 13:04:04

标签: php json amazon-web-services alexa alexa-skills-kit

我在ALEXA(Amazon Echo)上运行了一个应用程序。我用图像实现家庭卡显示。当特定呼叫时,如果响应只有一张卡。它显示完美。附上截图 enter image description here

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

上述代码不起作用。

以下是我尝试转换的内容:请参阅屏幕截图 enter image description here

对于在伦敦召唤的活动,我会获得单张卡片中5个活动的列表。对于每个事件,我想分配图像并创建其卡片。

任何人都可以帮助解决这个问题并找出在JSON响应中使用多张卡的问题。 难道alexa只支持单卡作为回应吗?

1 个答案:

答案 0 :(得分:1)

响应中的card属性使对象不是数组。

以下是亚马逊在site上使用的示例:

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

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

我认为您最好的选择是考虑与用户进行不同的互动,然后展示多张卡片。