Skip to content

Commit a3c1947

Browse files
authored
Implement quick reply (#120)
* Implement quick reply * Polish
1 parent 4db3eed commit a3c1947

File tree

7 files changed

+358
-33
lines changed

7 files changed

+358
-33
lines changed

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ TemplateSendMessage - ImageCarouselTemplate
600600
)
601601
)
602602
603+
With QuickReply
604+
^^^^^^^^^^^^^^^
605+
606+
.. code:: python
607+
608+
text_message = TextSendMessage(text='Hello, world',
609+
quick_reply=QuickReply(items=[
610+
QuickReplyButton(action=MessageAction(label="label", text="text"))
611+
]))
612+
603613
Webhook
604614
-------
605615

examples/flask-kitchensink/app.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import sys
2020
import tempfile
2121
from argparse import ArgumentParser
22+
2223
from flask import Flask, request, abort
2324

2425
from linebot import (
@@ -33,13 +34,14 @@
3334
TemplateSendMessage, ConfirmTemplate, MessageAction,
3435
ButtonsTemplate, ImageCarouselTemplate, ImageCarouselColumn, URIAction,
3536
PostbackAction, DatetimePickerAction,
37+
CameraAction, CameraRollAction, LocationAction,
3638
CarouselTemplate, CarouselColumn, PostbackEvent,
3739
StickerMessage, StickerSendMessage, LocationMessage, LocationSendMessage,
3840
ImageMessage, VideoMessage, AudioMessage, FileMessage,
3941
UnfollowEvent, FollowEvent, JoinEvent, LeaveEvent, BeaconEvent,
4042
FlexSendMessage, BubbleContainer, ImageComponent, BoxComponent,
4143
TextComponent, SpacerComponent, IconComponent, ButtonComponent,
42-
SeparatorComponent,
44+
SeparatorComponent, QuickReply, QuickReplyButton
4345
)
4446

4547
app = Flask(__name__)
@@ -278,6 +280,34 @@ def handle_text_message(event):
278280
event.reply_token,
279281
message
280282
)
283+
elif text == 'quick_reply':
284+
line_bot_api.reply_message(
285+
event.reply_token,
286+
TextSendMessage(
287+
text='Quick reply',
288+
quick_reply=QuickReply(
289+
items=[
290+
QuickReplyButton(
291+
action=PostbackAction(label="label1", data="data1")
292+
),
293+
QuickReplyButton(
294+
action=MessageAction(label="label2", text="text2")
295+
),
296+
QuickReplyButton(
297+
action=DatetimePickerAction(label="label3",
298+
data="data3",
299+
mode="date")
300+
),
301+
QuickReplyButton(
302+
action=CameraAction(label="label4")
303+
),
304+
QuickReplyButton(
305+
action=CameraRollAction(label="label5")
306+
),
307+
QuickReplyButton(
308+
action=LocationAction(label="label6")
309+
),
310+
])))
281311
else:
282312
line_bot_api.reply_message(
283313
event.reply_token, TextSendMessage(text=event.message.text))

linebot/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from __future__ import unicode_literals
1818

19-
__version__ = '1.7.2'
19+
__version__ = '1.8.0'
2020
__author__ = 'LINE Corporation'
2121
__copyright__ = 'Copyright 2016, LINE Corporation'
2222
__license__ = 'Apache 2.0'

linebot/models/__init__.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
MessageAction,
2121
URIAction,
2222
DatetimePickerAction,
23+
CameraAction,
24+
CameraRollAction,
25+
LocationAction,
2326
Action as TemplateAction, # backward compatibility
2427
PostbackAction as PostbackTemplateAction, # backward compatibility
2528
MessageAction as MessageTemplateAction, # backward compatibility
@@ -47,6 +50,23 @@
4750
Beacon,
4851
Link,
4952
)
53+
from .flex_message import ( # noqa
54+
FlexSendMessage,
55+
FlexContainer,
56+
BubbleContainer,
57+
BubbleStyle,
58+
BlockStyle,
59+
CarouselContainer,
60+
FlexComponent,
61+
BoxComponent,
62+
ButtonComponent,
63+
FillerComponent,
64+
IconComponent,
65+
ImageComponent,
66+
SeparatorComponent,
67+
SpacerComponent,
68+
TextComponent
69+
)
5070
from .imagemap import ( # noqa
5171
ImagemapSendMessage,
5272
BaseSize,
@@ -86,6 +106,8 @@
86106
AudioSendMessage,
87107
LocationSendMessage,
88108
StickerSendMessage,
109+
QuickReply,
110+
QuickReplyButton,
89111
)
90112
from .sources import ( # noqa
91113
Source,
@@ -103,20 +125,3 @@
103125
ImageCarouselTemplate,
104126
ImageCarouselColumn,
105127
)
106-
from .flex_message import ( # noqa
107-
FlexSendMessage,
108-
FlexContainer,
109-
BubbleContainer,
110-
BubbleStyle,
111-
BlockStyle,
112-
CarouselContainer,
113-
FlexComponent,
114-
BoxComponent,
115-
ButtonComponent,
116-
FillerComponent,
117-
IconComponent,
118-
ImageComponent,
119-
SeparatorComponent,
120-
SpacerComponent,
121-
TextComponent
122-
)

linebot/models/actions.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def get_action(action):
3030
'postback': PostbackAction,
3131
'message': MessageAction,
3232
'uri': URIAction,
33-
'datetimepicker': DatetimePickerAction
33+
'datetimepicker': DatetimePickerAction,
34+
'camera': CameraAction,
35+
'cameraRoll': CameraRollAction,
36+
'location': LocationAction,
3437
}
3538
)
3639
return action_obj
@@ -176,3 +179,69 @@ def __init__(self, label=None, data=None, mode=None,
176179
self.initial = initial
177180
self.max = max
178181
self.min = min
182+
183+
184+
class CameraAction(Action):
185+
"""CameraAction.
186+
187+
https://developers.line.me/en/reference/messaging-api/#camera-action
188+
189+
This action can be configured only with quick reply buttons.
190+
When a button associated with this action is tapped,
191+
the camera screen in the LINE app is opened.
192+
"""
193+
194+
def __init__(self, label=None, **kwargs):
195+
"""__init__ method.
196+
197+
:param str label: Label for the action
198+
:param kwargs:
199+
"""
200+
super(CameraAction, self).__init__(**kwargs)
201+
202+
self.type = 'camera'
203+
self.label = label
204+
205+
206+
class CameraRollAction(Action):
207+
"""CameraRollAction.
208+
209+
https://developers.line.me/en/reference/messaging-api/#camera-roll-action
210+
211+
This action can be configured only with quick reply buttons.
212+
When a button associated with this action is tapped,
213+
the camera roll screen in the LINE app is opened.
214+
"""
215+
216+
def __init__(self, label=None, **kwargs):
217+
"""__init__ method.
218+
219+
:param str label: Label for the action
220+
:param kwargs:
221+
"""
222+
super(CameraRollAction, self).__init__(**kwargs)
223+
224+
self.type = 'cameraRoll'
225+
self.label = label
226+
227+
228+
class LocationAction(Action):
229+
"""LocationRollAction.
230+
231+
https://developers.line.me/en/reference/messaging-api/#location-action
232+
233+
This action can be configured only with quick reply buttons.
234+
When a button associated with this action is tapped,
235+
the location screen in the LINE app is opened.
236+
"""
237+
238+
def __init__(self, label=None, **kwargs):
239+
"""__init__ method.
240+
241+
:param str label: Label for the action
242+
:param kwargs:
243+
"""
244+
super(LocationAction, self).__init__(**kwargs)
245+
246+
self.type = 'location'
247+
self.label = label

0 commit comments

Comments
 (0)