Skip to content

Can't send FlexMessage with Hero block #273

@snagasawa

Description

@snagasawa

System Informations

  • Python version: 3.7.7
  • SDK version: 1.16.0
  • OS: macOS Mojave 10.14.3

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.

self.hero = self.get_or_new_from_json_dict(hero, ImageComponent)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions