Closed snagasawa closed 4 years ago
The docs say that box or image can be used for hero block. https://developers.line.biz/en/reference/messaging-api/#bubble
Hero block. Specify a box or an image.
I tried to send FlexMessage with box block, but got an error.
e.status_code: 400 e.error.message: A message (messages[0]) in the request body is invalid e.error.details: [{"message": "must be specified", "property": "/hero/url"}]
Hero seems to be initialized with ImageComponent if I pass in a json. https://github.com/line/line-bot-sdk-python/blob/9e9b1f9fd0dc577fe79dd288d9234407f0f25470/linebot/models/flex_message.py#L112
Probably this question also has the same error. https://www.line-community.me/question/5e7b039a851f7402cd963e3c
from linebot import LineBotApi from linebot.models import FlexSendMessage from linebot.exceptions import LineBotApiError
#
messages = [{ 'type': 'flex', 'altText': 'altText', 'contents': { 'type': 'bubble', 'hero': { 'type': 'box', 'layout': 'vertical', 'contents': [ { 'type': 'text', 'text': 'Brown Cafe' } ] } } }]
user_id = '' channel_access_token = ''
line_bot_api = LineBotApi(channel_access_token) flex_messages = [FlexSendMessage(alt_text=message['altText'], contents=message['contents']) for message in messages]
try: line_bot_api.push_message(user_id, flex_messages) except LineBotApiError as e: print('e.status_code:', e.status_code) print('e.error.message:',e.error.message) print('e.error.details:',e.error.details)
## Logs <!-- Provide logs if possible -->
Thank you for reporting. As you pointed out, it seems a bug. We'll handle it.
Thanks, @snagasawa and @cryeo!
System Informations
Expected Behavior
The docs say that box or image can be used for hero block. https://developers.line.biz/en/reference/messaging-api/#bubble
Current Behavior
I tried to send FlexMessage with box block, but got an error.
Hero seems to be initialized with ImageComponent if I pass in a json. https://github.com/line/line-bot-sdk-python/blob/9e9b1f9fd0dc577fe79dd288d9234407f0f25470/linebot/models/flex_message.py#L112
Probably this question also has the same error. https://www.line-community.me/question/5e7b039a851f7402cd963e3c
Steps to Reproduce
fail and output following
#
e.status_code: 400
e.error.message: A message (messages[0]) in the request body is invalid
e.error.details: [{"message": "must be specified", "property": "/hero/url"}]
messages = [{ 'type': 'flex', 'altText': 'altText', 'contents': { 'type': 'bubble', 'hero': { 'type': 'box', 'layout': 'vertical', 'contents': [ { 'type': 'text', 'text': 'Brown Cafe' } ] } } }]
success if change "hero" to "body"
#
messages = [{
'type': 'flex',
'altText': 'altText',
'contents':
{
'type': 'bubble',
'body': {
'type': 'box',
'layout': 'vertical',
'contents': [
{
'type': 'text',
'text': 'Brown Cafe'
}
]
}
}
}]
success if change hero's child element from "box" to "image"
#
messages = [{
'type': 'flex',
'altText': 'altText',
'contents':
{
'type': 'bubble',
'hero': {
'type': 'image',
'url': 'VALID URL',
}
}
}]
user_id = '' channel_access_token = ''
line_bot_api = LineBotApi(channel_access_token) flex_messages = [FlexSendMessage(alt_text=message['altText'], contents=message['contents']) for message in messages]
try: line_bot_api.push_message(user_id, flex_messages) except LineBotApiError as e: print('e.status_code:', e.status_code) print('e.error.message:',e.error.message) print('e.error.details:',e.error.details)