我终于想出了怎么做!问题中的响应格式不正确。正确的格式是这样的:
{
'messages': [
<message object>,
<message object>
]
}
您可以参考消息对象以了解可以使用的类型。需要注意的一点是,对于类型 4,您可以简单地使用LINE中指定的有效负载。
例如,
{
'messages': [
{
'type': 0,
'speech': 'ABC'
},
{
"type": 4,
"payload": {
"line": {
"type": "template", "altText": "This is a buttons template",
"template": {
"type": "buttons",
"thumbnailImageUrl": "https://images.justlanded.com/event_images/Tets/photo/events_original_45195_42919.jpg",
"imageAspectRatio": "rectangle",
"imageSize": "cover",
"imageBackgroundColor": "#FFFFFF",
"title": "Menu",
"text": "Please select",
"defaultAction": {
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
},
"actions": [
{
"type": "postback",
"label": "Buy",
"data": "action=buy&itemid=123"
},
{
"type": "postback",
"label": "Add to cart",
"data": "action=add&itemid=123"
},
{
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
}
]
}
}
}
}
]
}