Implementation of Datetime picker action using line-bot-sdk-python and implementation sample of Image Carousel

Introduction

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

environment

--ngrok <-I put it in because I wanted to test it easily on localhost

Checks such as signature are omitted this time.

Datetime picker action sample

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

Screen Shot 2017-09-13 at 22.40.03.png

The mode of DatetimePickerTemplateAction can be set to date`` time datetime. See the reference below for details

Datetime picker action | LINE API Reference

Image Carousel sample

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'
                )
            )
        ]
    )
)

Screen Shot 2017-09-13 at 22.50.52.png

Recommended Posts

Implementation of Datetime picker action using line-bot-sdk-python and implementation sample of Image Carousel
Verification and implementation of video reconstruction method using GRU and Autoencoder
Implementation of TF-IDF using gensim
Explanation and implementation of SocialFoceModel
Explanation and implementation of PRML Chapter 4
Image capture of firefox using python
Benefits and examples of using RabbitMq
Explanation and implementation of ESIM algorithm
Judgment of backlit image using OpenCV
Introduction and implementation of activation function
Explanation and implementation of simple perceptron
Implementation of desktop notifications using Python
Clash of Clans and image analysis (3)
Image recognition of fruits using VGG16