Just the other day, Datetime picker action and ʻImage Carousel` were added to the LINE Messaging API, so a sample of them.
I made a PR about ʻImage Carousel`. I'm sorry to put out a shit PR ...
https://github.com/line/line-bot-sdk-python/pull/59
--ngrok <-I put it in because I wanted to test it easily on localhost
Checks such as signature are omitted this time.
https://github.com/line/line-bot-sdk-python/blob/master/tests/api/test_send_template_message.py
The above test code sample code (L129 ~ 202) did not work So with the sample that worked when I implemented it
from django.http import HttpResponse
from linebot import LineBotApi, WebhookParser
from linebot.models import TemplateSendMessage, ButtonsTemplate, DatetimePickerTemplateAction
line_bot_api = LineBotApi('LINE_CHANNEL_ACCESS_TOKEN')
parser = WebhookParser('LINE_CHANNEL_SECRET')
def webhook(request):
#Signature check, etc.
for event in events:
date_picker = TemplateSendMessage(
alt_text='Set the scheduled date',
template=ButtonsTemplate(
text='Set the scheduled date',
title='YYYY-MM-dd',
actions=[
DatetimePickerTemplateAction(
label='Setting',
data='action=buy&itemid=1',
mode='date',
initial='2017-04-01',
min='2017-04-01',
max='2099-12-31'
)
]
)
)
line_bot_api.reply_message(
event.reply_token,
date_picker
)
return HttpResponse()
When the time is sent on the LINE app side, you can get the value on the server side with PostbackEvent.
The time set by the end user could be obtained below
if isinstance(event, PostbackEvent):
event.postback.params['date'] #dict key is mode

The mode of DatetimePickerTemplateAction can be set to date`` time datetime.
See the reference below for details
Datetime picker action | LINE API Reference
from line.models import ImageCarouselTemplate, ImageCarouselColumn
image_carousel_template_message = TemplateSendMessage(
alt_text='Image carousel template',
template=ImageCarouselTemplate(
columns=[
ImageCarouselColumn(
image_url='https://example.com/item1.jpg',
action=PostbackTemplateAction(
label='postback1',
data='action=buy&itemid=1'
)
),
ImageCarouselColumn(
image_url='https://example.com/item2.jpg',
action=MessageTemplateAction(
label='message2',
text='message text2'
)
),
ImageCarouselColumn(
image_url='https://example.com/item3.jpg',
action=URITemplateAction(
label='uri1',
uri='https://example.com/1'
)
)
]
)
)

Recommended Posts