line / line-bot-sdk-python

LINE Messaging API SDK for Python
https://pypi.python.org/pypi/line-bot-sdk
Apache License 2.0
1.93k stars 1.02k forks source link

Can't send FlexMessage with Hero block #273

Closed snagasawa closed 4 years ago

snagasawa commented 4 years ago

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

Hero block. Specify a box or an image.

Current Behavior

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

Steps to Reproduce

  1. change parameters and execute following script.
    
    from linebot import LineBotApi
    from linebot.models import FlexSendMessage
    from linebot.exceptions import LineBotApiError

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)



## Logs
<!-- Provide logs if possible -->
cryeo commented 4 years ago

Thank you for reporting. As you pointed out, it seems a bug. We'll handle it.

okue commented 4 years ago

Thanks, @snagasawa and @cryeo!