def button_choice_generater(description,
                            choice_list,
                            layout='2x',
                            background_color='#ecb68a',
                            button_color='#a5591b'):
    '''
    description 質問文
    choice_list 選択肢
    layout 1列か2列かを指定
    '''
    if layout == '2x':
        choice_list = np.array(choice_list).reshape(int(len(choice_list) / 2),
                                                    2)
        bubble_choice = BubbleContainer(
            direction='ltr',
            styles=BubbleStyle(
                body=BlockStyle(background_color=background_color),
                footer=BlockStyle(background_color=background_color)),
            body=BoxComponent(
                layout='vertical',
                contents=[
                    # title
                    TextComponent(text=description,
                                  weight='bold',
                                  size='md',
                                  align='center'),
                ],
            ),
            footer=BoxComponent(
                layout='vertical',
                spacing='sm',
                color='#f2cdae',
                contents=[
                    button_container_2x(choice, button_color)
                    for choice in choice_list
                ],
            ))
        return bubble_choice

    else:
        bubble_choice = BubbleContainer(
            direction='ltr',
            styles=BubbleStyle(
                body=BlockStyle(background_color=background_color),
                footer=BlockStyle(background_color=background_color)),
            body=BoxComponent(
                layout='vertical',
                contents=[
                    # title
                    TextComponent(text=description,
                                  weight='bold',
                                  size='md',
                                  align='center'),
                ],
            ),
            footer=BoxComponent(
                layout='vertical',
                spacing='sm',
                color='#f2cdae',
                contents=[
                    button_container_1x(choice, button_color)
                    for choice in choice_list
                ],
            ))
        return bubble_choice
Beispiel #2
0
def handle_message(event):
    text = event.message.text  #simplify for receove message
    sender = event.source.user_id  #get user_id
    gid = event.source.sender_id  #get group_id

    #=====[ LEAVE GROUP OR ROOM ]==========
    if text == 'profil':
        line_bot_api.reply_message(
            event.reply_token,
            ImageSendMessage(
                original_content_url=
                "https://instagram.fcgk4-2.fna.fbcdn.net/vp/c1e5737a4524bba9ef9a357c7565db45/5C80ED70/t51.2885-15/sh0.08/e35/s640x640/43986014_244038946273070_1529767450573078675_n.jpg",
                preview_image_url=
                "https://instagram.fcgk4-2.fna.fbcdn.net/vp/c1e5737a4524bba9ef9a357c7565db45/5C80ED70/t51.2885-15/sh0.08/e35/s640x640/43986014_244038946273070_1529767450573078675_n.jpg"
            ))

    if text == '/minggat':
        if isinstance(event.source, SourceGroup):
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text='bye👌'))
            line_bot_api.leave_group(event.source.group_id)
        elif isinstance(event.source, SourceRoom):
            line_bot_api.reply_message(
                event.reply_token, TextSendMessage(text='good bye vroh👌'))
            line_bot_api.leave_room(event.source.room_id)
        else:
            line_bot_api.reply_message(
                event.reply_token,
                TextSendMessage(text="Bot can't leave from 1:1 chat"))
#=====[ TEMPLATE MESSAGE ]=============
    elif text == '/template':
        buttons_template = TemplateSendMessage(
            alt_text='template',
            template=ButtonsTemplate(
                title='[ TEMPLATE MSG ]',
                text='Tap the Button',
                actions=[
                    MessageTemplateAction(label='help menu', text='/menu'),
                    MessageTemplateAction(label='bot leave', text='/minggat'),
                    MessageTemplateAction(label='flex', text='flex')
                ]))

        line_bot_api.reply_message(event.reply_token, buttons_template)
#=====[ CAROUSEL MESSAGE ]==========
    elif text == '/menu':
        message = TemplateSendMessage(
            alt_text='OTHER MENU',
            template=CarouselTemplate(columns=[
                CarouselColumn(title='ADD ME',
                               text='anu',
                               actions=[
                                   URITemplateAction(
                                       label='>TAP HERE<',
                                       uri='https://line.me/ti/p/~vekok.')
                               ]),
                CarouselColumn(title='Instagram',
                               text='FIND ME ON INSTAGRAM',
                               actions=[
                                   URITemplateAction(
                                       label='>TAP HERE!<',
                                       uri='http://line.me/ti/p/~vekok.')
                               ])
            ]))
        line_bot_api.reply_message(event.reply_token, message)
#=====[ FLEX MESSAGE ]==========
    elif text == 'flex':
        bubble = BubbleContainer(
            direction='ltr',
            hero=ImageComponent(
                url=
                'https://lh5.googleusercontent.com/VoOmR6tVRwKEow0HySsJ_UdrQrqrpwUwSzQnGa0yBeqSex-4Osar2w-JohT6yPu4Vl4qchND78aU2c5a5Bhl=w1366-h641-rw',
                size='full',
                aspect_ratio='20:13',
                aspect_mode='cover',
                action=URIAction(uri='http://line.me/ti/p/~vekok.',
                                 label='label')),
            body=BoxComponent(
                layout='vertical',
                contents=[
                    # title
                    TextComponent(text='vekok', weight='bold', size='xl'),
                    # review
                    BoxComponent(
                        layout='baseline',
                        margin='md',
                        contents=[
                            IconComponent(
                                size='sm',
                                url='https://example.com/gold_star.png'),
                            IconComponent(
                                size='sm',
                                url='https://example.com/grey_star.png'),
                            IconComponent(
                                size='sm',
                                url='https://example.com/gold_star.png'),
                            IconComponent(
                                size='sm',
                                url='https://example.com/gold_star.png'),
                            IconComponent(
                                size='sm',
                                url='https://example.com/grey_star.png'),
                            TextComponent(text='4.0',
                                          size='sm',
                                          color='#999999',
                                          margin='md',
                                          flex=0)
                        ]),
                    # info
                    BoxComponent(
                        layout='vertical',
                        margin='lg',
                        spacing='sm',
                        contents=[
                            BoxComponent(
                                layout='baseline',
                                spacing='sm',
                                contents=[
                                    TextComponent(text='Place',
                                                  color='#aaaaaa',
                                                  size='sm',
                                                  flex=1),
                                    TextComponent(text='Tangerang, Indonesia',
                                                  wrap=True,
                                                  color='#666666',
                                                  size='sm',
                                                  flex=5)
                                ],
                            ),
                            BoxComponent(
                                layout='baseline',
                                spacing='sm',
                                contents=[
                                    TextComponent(text='Time',
                                                  color='#aaaaaa',
                                                  size='sm',
                                                  flex=1),
                                    TextComponent(
                                        text="10:00 - 23:00",
                                        wrap=True,
                                        color='#666666',
                                        size='sm',
                                        flex=5,
                                    ),
                                ],
                            ),
                        ],
                    )
                ],
            ),
            footer=BoxComponent(
                layout='vertical',
                spacing='sm',
                contents=[
                    # separator
                    SeparatorComponent(),
                    # websiteAction
                    ButtonComponent(style='link',
                                    height='sm',
                                    action=URIAction(
                                        label='vekok',
                                        uri="https://line.me/ti/p/~vekok."))
                ]),
        )
        message = FlexSendMessage(alt_text="hello", contents=bubble)
        line_bot_api.reply_message(event.reply_token, message)