Skip to content

Commit 8989f2d

Browse files
authored
Flex message update 3 (#375)
* Add video component * Add max width and height of a box component * Add line spacing in a text component
1 parent c9876c5 commit 8989f2d

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

linebot/models/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
ImageComponent,
8181
SeparatorComponent,
8282
TextComponent,
83-
SpanComponent
83+
SpanComponent,
84+
VideoComponent
8485
)
8586
from .imagemap import ( # noqa
8687
ImagemapSendMessage,

linebot/models/flex_message.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def __init__(self, size=None, direction=None, header=None, hero=None,
9393
:param hero: Hero block
9494
:type hero: :py:class:`linebot.models.flex_message.ImageComponent`
9595
| :py:class:`linebot.models.flex_message.BoxComponent`
96+
| :py:class:`linebot.models.flex_message.VideoComponent`
9697
:param body: Body block
9798
:type body: :py:class:`linebot.models.flex_message.BoxComponent`
9899
:param footer: Footer block
@@ -112,7 +113,8 @@ def __init__(self, size=None, direction=None, header=None, hero=None,
112113
self.hero = self.get_or_new_from_json_dict_with_types(
113114
hero, {
114115
'image': ImageComponent,
115-
'box': BoxComponent
116+
'box': BoxComponent,
117+
'video': VideoComponent
116118
}
117119
)
118120
self.body = self.get_or_new_from_json_dict(body, BoxComponent)
@@ -238,7 +240,9 @@ def __init__(self,
238240
align_items=None,
239241
background=None,
240242
width=None,
243+
max_width=None,
241244
height=None,
245+
max_height=None,
242246
flex=None,
243247
spacing=None,
244248
margin=None,
@@ -270,7 +274,9 @@ def __init__(self,
270274
:param background: Background object
271275
:type background: T <= :py:class:`linebot.models.background.Background`
272276
:param str width: Width of the box
277+
:param str max_width: Maximum width of the box
273278
:param str height: Height of the box
279+
:param str max_height: Maximum height of the box
274280
:param float flex: The ratio of the width or height of this box within the parent box
275281
and the previous component in the parent box
276282
:param str spacing: Minimum space between components in this box
@@ -303,7 +309,9 @@ def __init__(self,
303309
self.justify_content = justify_content
304310
self.align_items = align_items
305311
self.width = width
312+
self.max_width = max_width
306313
self.height = height
314+
self.max_height = max_height
307315
self.flex = flex
308316
self.spacing = spacing
309317
self.margin = margin
@@ -334,7 +342,8 @@ def __init__(self,
334342
'image': ImageComponent,
335343
'span': SpanComponent,
336344
'separator': SeparatorComponent,
337-
'text': TextComponent
345+
'text': TextComponent,
346+
'video': VideoComponent
338347
}
339348
))
340349
self.contents = new_contents
@@ -615,6 +624,7 @@ def __init__(self,
615624
align=None,
616625
gravity=None,
617626
wrap=None,
627+
line_spacing=None,
618628
max_lines=None,
619629
weight=None,
620630
color=None,
@@ -640,6 +650,7 @@ def __init__(self,
640650
:param str gravity: Vertical alignment style
641651
:param bool wrap: rue to wrap text. The default value is False.
642652
If set to True, you can use a new line character (\n) to begin on a new line.
653+
:param str line_spacing: Line spacing in a wrapping text
643654
:param int max_lines: Max number of lines
644655
:param str weight: Font weight
645656
:param str color: Font color
@@ -663,6 +674,7 @@ def __init__(self,
663674
self.align = align
664675
self.gravity = gravity
665676
self.wrap = wrap
677+
self.line_spacing = line_spacing
666678
self.max_lines = max_lines
667679
self.weight = weight
668680
self.color = color
@@ -674,3 +686,45 @@ def __init__(self,
674686
self.contents = [self.get_or_new_from_json_dict(it, SpanComponent) for it in contents]
675687
else:
676688
self.contents = None
689+
690+
691+
class VideoComponent(FlexComponent):
692+
"""VideoComponent.
693+
694+
https://developers.line.biz/en/reference/messaging-api/#f-video
695+
696+
This component renders a video.
697+
"""
698+
699+
def __init__(self,
700+
url=None,
701+
preview_url=None,
702+
alt_content=None,
703+
aspect_ratio=None,
704+
action=None,
705+
**kwargs):
706+
r"""__init__ method.
707+
708+
:param str url: URL of video file
709+
:param str preview_url: URL of preview image
710+
:param alt_content: Alternative content
711+
:type alt_content: :py:class:`linebot.models.flex_message.ImageComponent`
712+
| :py:class:`linebot.models.flex_message.BoxComponent`
713+
:param float aspect_ratio: Aspect ratio of the video
714+
:param action: Action performed when this video is tapped
715+
:type action: list[T <= :py:class:`linebot.models.actions.Action`]
716+
:param kwargs:
717+
"""
718+
super(VideoComponent, self).__init__(**kwargs)
719+
720+
self.type = 'video'
721+
self.url = url
722+
self.preview_url = preview_url
723+
self.alt_content = self.get_or_new_from_json_dict_with_types(
724+
alt_content, {
725+
'image': ImageComponent,
726+
'box': BoxComponent
727+
}
728+
)
729+
self.aspect_ratio = aspect_ratio
730+
self.action = get_action(action)

tests/models/test_flex_message.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
FillerComponent,
3131
IconComponent,
3232
SpanComponent,
33+
VideoComponent,
3334
URIAction,
3435
LinearGradientBackground,
3536
)
@@ -249,6 +250,25 @@ def test_span_component(self):
249250
SpanComponent(**arg).as_json_dict()
250251
)
251252

253+
def test_video_component(self):
254+
arg = {
255+
'type': 'video',
256+
'url': 'https://example.com/video.mp4',
257+
"preview_url": "https://example.com/video_preview.jpg",
258+
"alt_content": {
259+
"type": "image",
260+
"size": "full",
261+
"aspect_ratio": "20:13",
262+
"aspect_mode": "cover",
263+
"url": "https://example.com/image.jpg"
264+
},
265+
"aspect_ratio": "20:13"
266+
}
267+
self.assertEqual(
268+
self.serialize_as_dict(arg, type=self.VIDEO),
269+
VideoComponent(**arg).as_json_dict()
270+
)
271+
252272
def test_text_component(self):
253273
arg = {
254274
'text': 'Hello, World!',

0 commit comments

Comments
 (0)