Reputation: 1
I have a problem with flex message in linebot, I am trying to make multiple Flex Messages like carousel template, I follow the example and made two cases after I read the document here. And I succeeded in the first case, but case 2 doesn't work. By the way, I deploy the app in Heroku and I got the "status=200" in case 2, but nothing responds. How should I solve the problem? Here is my code below: Case 1:
if event.message.text == 'test1':
reply_header = {'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ' + 'xxx'}
reply_json = {
"replyToken": event.reply_token,
"messages": [
{
"type": "flex",
"altText": "Flex Message",
"contents": {
"type": "bubble",
"direction": "ltr",
"header": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "Header",
"align": "center"
}
]
},
"hero": {
"type": "image",
"url": "https://developers.line.me/assets/images/services/bot-designer-icon.png",
"size": "full",
"aspectRatio": "1.51:1",
"aspectMode": "fit"
},
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "Body",
"align": "center"
}
]
},
"footer": {
"type": "box",
"layout": "horizontal",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "Button",
"uri": "https://linecorp.com"
}
}
]
}
}
}
]
}
r = requests.post("https://api.line.me/v2/bot/message/reply", headers=reply_header, json=reply_json)
Case 2:
if event.message.text == 'test2':
reply_header = {'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ' + 'xxx'}
reply_json = {
"replyToken": event.reply_token,
"type": "carousel",
"contents": [
{
"type": "bubble",
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "First bubble"
}
]
}
},
{
"type": "bubble",
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "Second bubble"
}
]
}
}
]
}
r = requests.post("https://api.line.me/v2/bot/message/reply", headers=reply_header, json=reply_json)
Upvotes: 0
Views: 1290
Reputation: 11
In Flex Message, the attribute altText
, type
and contents
are required.
try below.
{
"type": "flex",
"altText": "myCausouelMessage",
"contents": {
"type": "carousel",
"contents": [put_your_carousel_array_json_contents]
}
}
Upvotes: 1