Exemplo n.º 1
0
 def test_bubble_container(self):
     arg = {
         'header':
         BoxComponent(layout='vertical',
                      contents=[TextComponent(text='Header text')]),
         'body':
         BoxComponent(layout='vertical',
                      contents=[TextComponent(text='Body text')]),
         'footer':
         BoxComponent(layout='vertical',
                      contents=[TextComponent(text='Footer text')]),
         'styles':
         BubbleStyle(header=BlockStyle(background_color='#00ffff'),
                     hero=BlockStyle(background_color='#00ffff',
                                     separator=True),
                     footer=BlockStyle(background_color='#00ffff',
                                       separator=True,
                                       separator_color='#00ffff'))
     }
     heros = [
         ImageComponent(uri='https://example.com/flex/images/image.jpg'),
         BoxComponent(layout='vertical',
                      contents=[TextComponent(text='Body text')]),
     ]
     for hero in heros:
         arg['hero'] = hero
         self.assertEqual(self.serialize_as_dict(arg, type=self.BUBBLE),
                          BubbleContainer(**arg).as_json_dict())
Exemplo n.º 2
0
 def test_bubble_style(self):
     arg = {
         'header':
         BlockStyle(background_color='#00ffff'),
         'hero':
         BlockStyle(background_color='#00ffff', separator=True),
         'footer':
         BlockStyle(background_color='#00ffff',
                    separator=True,
                    separator_color='#00ffff')
     }
     self.assertEqual(self.serialize_as_dict(arg),
                      BubbleStyle(**arg).as_json_dict())
Exemplo n.º 3
0
def createBubbleContainer(station_name, what_day, time1, time2, time3):
    bubble = BubbleContainer(
        direction="ltr",
        header=BoxComponent(layout="vertical",
                            contents=[
                                BoxComponent(layout="horizontal",
                                             contents=[
                                                 TextComponent(
                                                     text=station_name,
                                                     weight="bold"),
                                                 TextComponent(text=what_day)
                                             ])
                            ]),
        body=BoxComponent(layout="vertical",
                          contents=[
                              BoxComponent(layout="horizontal",
                                           contents=[
                                               TextComponent(text="↓Campus"),
                                               TextComponent(text=time1)
                                           ]),
                              BoxComponent(layout="horizontal",
                                           contents=[
                                               TextComponent(text="↓" +
                                                             station_name),
                                               TextComponent(text=time2)
                                           ]),
                              BoxComponent(layout="horizontal",
                                           contents=[
                                               TextComponent(text="↓Campus"),
                                               TextComponent(text=time3)
                                           ])
                          ]),
        styles=BubbleStyle(body=BlockStyle(separator=True)))
    return bubble
Exemplo n.º 4
0
 def test_block_style(self):
     arg = {
         'background_color': '#00ffff',
         'separator': True,
         'separator_color': '#000000'
     }
     self.assertEqual(self.serialize_as_dict(arg),
                      BlockStyle(**arg).as_json_dict())
def arrival_timer_breaked():
    return FlexSendMessage("集合時間になりました", BubbleContainer(
        size="mega",
        body=BoxComponent(
            layout="vertical",
            separator="true",
            contents=[
                TextComponent(
                    text="集合時間になりました",
                    align="center",
                    size="lg"
                ),
            ]),
        styles=BubbleStyle(body=BlockStyle(background_color="#ffffff"))
    ))
def arrival_locationpicker():
    return FlexSendMessage("目的地設定", BubbleContainer(
        size="mega",
        body=BoxComponent(
            layout="vertical",
            contents=[ 
                TextComponent(
                    text="目的地を設定してください",
                    size="sm"
                ),
            ]
        ),
        styles=BubbleStyle(body=BlockStyle(background_color="#ffffff"))
    ),
    quickreply=QuickReply(items=[
        QuickReplyButton(action=LocationAction(label="label"))
        ]))
def member_text(arrival_date):
    return FlexSendMessage("参加者入力", BubbleContainer(
        size="mega",
        header=BoxComponent(
            layout="vertical",
            separator="true",
            contents=[
                TextComponent(
                    text=arrival_date.strftime("%m月%d日 %H時%M分"),
                    align="center",
                    size="lg"
                ),
            ]),
        body=BoxComponent(
            layout="vertical",
            contents=[
                TextComponent(
                    text="あなた以外の参加者を,",
                    align="center",
                    size="md"
                ),
                TextComponent(
                    text="@john @michael ...",
                    align="center",
                    color="#888822",
                    size="sm"
                ),
                TextComponent(
                    text="という形で入力してください.",
                    align="center",
                    size="md"
                ),
            ]
        ),
        action=PostbackAction(
            label="到着",
            display_text="到着",
            data="data not served"
        ),
        styles=BubbleStyle(body=BlockStyle(background_color="#ffffff"))
    ))
def arrival_datepicker(destination_name):
    now_date = datetime.datetime.now().isoformat()
    regex  = re.findall(r"[0-9]{4}-[0-9]{2}-[0-9]{2}|[0-9]{2}:[0-9]{2}", now_date)
    tstr = regex[0] + "T" + regex[1]

    return FlexSendMessage("集合時間", BubbleContainer(
        size="mega",
        header=BoxComponent(
            layout="vertical",
            contents=[
                TextComponent(
                    text=destination_name,
                    align="center",
                    size="lg"
                ),
            ]),
        body=BoxComponent(
            layout="vertical",
            contents=[
                TextComponent(
                    text="集合時間を入力してください",
                    align="center",
                    size="sm"
                ),
                ButtonComponent(
                    style="link",
                    height="sm",
                    action=DatetimePickerTemplateAction(
                        label="集合時間設定",
                        data="action=buy&itemid=2&mode=datetime",
                        mode="datetime",
                        initial=tstr,
                        min=tstr,
                        max="2099-12-31T23:59"
                    )
                )
            ]
        ),
        styles=BubbleStyle(body=BlockStyle(background_color="#ffffff"))
    ))
def arrival_button():
    return FlexSendMessage("到着", BubbleContainer(
        size="mega",
        body=BoxComponent(
            layout="vertical",
            contents=[
                ButtonComponent(
                    style="link",
                    height="sm",
                    action=PostbackAction(
                        label="到着",
                        display_text="到着",
                        data="data not served"
                    )
                )
            ]
        ),
        action=PostbackAction(
            label="到着",
            display_text="到着",
            data="data not served"
        ),
        styles=BubbleStyle(body=BlockStyle(background_color="#ffffff"))
    ))
Exemplo n.º 10
0
def sendFexMessage(event,place,time,pref,StayTime):
    contents =[]
    boxc = BoxComponent(
        layout='baseline',
        spacing='sm',
        contents=[
            TextComponent( text='Start  :'+'0h : 0m ',color='#aaaaaa',size='sm')
        ]
    )
    contents.append(boxc)

    sumTravelTime = StayTime
    for i in range(len(place)):
        print(place[i])
        boxc = BoxComponent(
            layout='baseline',
            spacing='sm',
            contents=[
                TextComponent( text='Place',color='#aaaaaa',size='sm',flex=2),
                IconComponent(url='https://linebot-ryotei-kun.herokuapp.com/static/icon.png',size='sm'),
                TextComponent( text=place[i],wrap=True,color='#444444',size='sm',flex=8)
            ]
        )
        contents.append(boxc)
        if (i < len(place) - 1):
            box = BoxComponent(
                layout='baseline',
                spacing='sm',
                contents=[
                    TextComponent( 
                        # text='↓\n↓   ' + str(int(time[i]/3600) ) +'h : ' + str(int(time[i]/60)%60 ) +'m \n↓',
                        text='↓ move  ' + str(int(sumTravelTime/3600) ) +'h : ' + str(int(sumTravelTime/60)%60 ) + 'm  ~ '+ \
                        str(int((sumTravelTime+time[i])/3600) ) +'h : ' + str(int((sumTravelTime+time[i])/60)%60 ) +'m',
                        color='#aaaaaa',size='sm',flex=1,wrap=True
                    ),
                ]
            )
            contents.append(box)
            sumTravelTime += int(time[i])
            sumTravelTime += StayTime


    boxc = BoxComponent(
        layout='baseline',
        spacing='sm',
        contents=[
            TextComponent( text='End    :'+ str(int(sumTravelTime/3600) ) +'h : ' + str(int(sumTravelTime/60)%60 ) + 'm ',color='#aaaaaa',size='sm')
        ]
    )
    contents.append(boxc)



    headerImage = ImageComponent(# 画像ヘッダ
                    url='https://linebot-ryotei-kun.herokuapp.com/static/background.jpg',
                    size='full',
                    aspect_ratio='20:13',
                    aspect_mode='cover',
                )

    #--------------------------------------------------
    # コンテナ作成
    #--------------------------------------------------
    title = str(pref) +'旅行'
    bubble = BubbleContainer(
                direction='ltr',
                hero=headerImage,
                body=BoxComponent(
                    layout='vertical',
                    contents=[
                        # titles
                        TextComponent(text= title , weight='bold', size='xl'),
                        # # info
                        BoxComponent(
                            layout='vertical',margin='lg',spacing='sm',contents=contents
                        )
                    ]
                ),
                styles = BubbleStyle(
                    header = BlockStyle(separator = True, backgroundColor='#bbffff'),
                    hero = BlockStyle(separator = True, backgroundColor='#bbffff'),
                    body = BlockStyle(separator = True, backgroundColor='#bbffff'),
                    footer = BlockStyle(separator = True, backgroundColor='#bbffff')
                )
            )



    message =[]
    message.append(FlexSendMessage(alt_text="旅程を作成したよ!", contents=bubble))
    message.append(TextSendMessage(text='これでどうかな?',
                                   quick_reply=QuickReply(items=[
               QuickReplyButton(action=MessageAction(type = "message",label="OK", text="OK")),
               QuickReplyButton(action=MessageAction(type = "message",label="もう一回!", text="もう一回!"))
           ]))
        )

    line_bot_api.reply_message(
        event.reply_token,
        message
    )
Exemplo n.º 11
0
    def makeBubbleContainer(self, result):
        date = result['date']
        future_price = result['price']
        future_tag = result['tag']
        bagColor = result['bagColor']
        Unleaded_Gasoline_98 = result['98 Unleaded Gasoline']
        Unleaded_Gasoline_95 = result['95 Unleaded Gasoline']
        Unleaded_Gasoline_92 = result['92 Unleaded Gasoline']
        CPC_Gas_Stations = result['Premium Diesel']
        header_contents = [
            BoxComponent(layout='vertical',
                         contents=[
                             TextComponent(size='md',
                                           color='#3C3C3C',
                                           text='%s 油價' % (date),
                                           align='center',
                                           weight='bold'),
                             TextComponent(size='xxl',
                                           color='#3C3C3C',
                                           text='%s %s' %
                                           (future_tag, future_price),
                                           align='center',
                                           weight='bold'),
                         ])
        ]

        body_contents = [
            BoxComponent(layout='horizontal',
                         contents=[
                             TextComponent(size='sm',
                                           color='#6C6C6C',
                                           flex=1,
                                           text='98無鉛',
                                           align='center'),
                             TextComponent(size='sm',
                                           color='#6C6C6C',
                                           flex=1,
                                           text='95無鉛',
                                           align='center'),
                             TextComponent(size='sm',
                                           color='#6C6C6C',
                                           flex=1,
                                           text='92無鉛',
                                           align='center'),
                             TextComponent(size='sm',
                                           color='#6C6C6C',
                                           flex=1,
                                           text='超級柴油',
                                           align='center'),
                         ]),
        ]

        footer_contents = [
            BoxComponent(layout='horizontal',
                         paddingAll='lg',
                         contents=[
                             TextComponent(size='sm',
                                           color='#6C6C6C',
                                           flex=1,
                                           text='%s' % (Unleaded_Gasoline_98),
                                           align='center'),
                             TextComponent(size='sm',
                                           color='#6C6C6C',
                                           flex=1,
                                           text='%s' % (Unleaded_Gasoline_95),
                                           align='center'),
                             TextComponent(size='sm',
                                           color='#6C6C6C',
                                           flex=1,
                                           text='%s' % (Unleaded_Gasoline_92),
                                           align='center'),
                             TextComponent(size='sm',
                                           color='#6C6C6C',
                                           flex=1,
                                           text='%s' % (CPC_Gas_Stations),
                                           align='center'),
                         ])
        ]

        # footer_contents.append(SpacerComponent(separator = 'true'))

        return BubbleContainer(
            # direction='ltr',
            styles=BubbleStyle(header=BlockStyle(background_color=bagColor), ),
            size='mega',
            header=BoxComponent(layout='vertical', contents=header_contents),
            body=BoxComponent(layout='vertical',
                              contents=body_contents,
                              padding_all='12px'),
            footer=BoxComponent(
                layout='vertical',
                spacing='md',
                contents=footer_contents,
            ),
        )
Exemplo n.º 12
0
    def think_reply_message(self, received_message, option=None):
        if 'ボタンテンプレート' in received_message:
            sending_message = TemplateSendMessage(
                alt_text='Buttons template',
                template=ButtonsTemplate(
                    thumbnail_image_url=
                    'https://placehold.jp/565656/151x100.png',
                    title='Menu',
                    text='Please select',
                    actions=[
                        PostbackAction(label='postback',
                                       text='postback text',
                                       data='action=buy&itemid=1'),
                        MessageAction(label='message', text='message text'),
                        URIAction(label='uri', uri='http://example.com/')
                    ]))

        elif '確認テンプレート' in received_message:
            sending_message = TemplateSendMessage(
                alt_text='Confirm template',
                template=ConfirmTemplate(text='Are you sure?',
                                         actions=[
                                             PostbackAction(
                                                 label='postback',
                                                 text='postback text',
                                                 data='action=buy&itemid=1'),
                                             MessageAction(label='message',
                                                           text='message text')
                                         ]))

        elif '画像カルーセルテンプレート' in received_message:
            sending_message = TemplateSendMessage(
                alt_text='ImageCarousel template',
                template=ImageCarouselTemplate(columns=[
                    ImageCarouselColumn(
                        image_url='https://placehold.jp/ababab/150x150.png',
                        action=PostbackAction(label='postback1',
                                              text='postback text1',
                                              data='action=buy&itemid=1')),
                    ImageCarouselColumn(
                        image_url='https://placehold.jp/565656/150x150.png',
                        action=PostbackAction(label='postback2',
                                              text='postback text2',
                                              data='action=buy&itemid=2'))
                ]))

        elif 'カルーセルテンプレート' in received_message:
            sending_message = TemplateSendMessage(
                alt_text='Carousel template',
                template=CarouselTemplate(columns=[
                    CarouselColumn(
                        thumbnail_image_url=
                        'https://placehold.jp/ababab/100x151.png',
                        title='this is menu1',
                        text='description1',
                        actions=[
                            PostbackAction(label='postback1',
                                           text='postback text1',
                                           data='action=buy&itemid=1'),
                            MessageAction(label='message1',
                                          text='message text1'),
                            URIAction(label='uri1', uri='http://example.com/1')
                        ]),
                    CarouselColumn(thumbnail_image_url=
                                   'https://placehold.jp/565656/100x151.png',
                                   title='this is menu2',
                                   text='description2',
                                   actions=[
                                       PostbackAction(
                                           label='postback2',
                                           text='postback text2',
                                           data='action=buy&itemid=2'),
                                       MessageAction(label='message2',
                                                     text='message text2'),
                                       URIAction(label='uri2',
                                                 uri='http://example.com/2')
                                   ])
                ]))

        elif 'フレックス' in received_message:
            sending_message = FlexSendMessage(
                alt_text='ImageCarousel template',
                contents=BubbleContainer(
                    header=BoxComponent(
                        layout='vertical',
                        contents=[TextComponent(text='header')]),
                    hero=ImageComponent(
                        url='https://placehold.jp/ababab/1024x1024.png',
                        size='full'),
                    body=BoxComponent(layout='vertical',
                                      contents=[TextComponent(text='body')]),
                    footer=BoxComponent(
                        layout='vertical',
                        contents=[TextComponent(text='footer')]),
                    styles=BubbleStyle(header=BlockStyle(),
                                       hero=BlockStyle(),
                                       body=BlockStyle(),
                                       footer=BlockStyle())))

        elif 'ログイン' in received_message:
            url = "{provider_url}/link_account?linkToken={link_token}".format(
                provider_url=PROVIDER_URL, link_token=option)
            sending_message = TemplateSendMessage(
                alt_text='Account Link',
                template=ButtonsTemplate(
                    thumbnail_image_url=
                    'https://placehold.jp/565656/100x151.png',
                    title='Menu',
                    text='Link your account',
                    actions=[URIAction(label='Account Link', uri=url)]))

        elif 'ログアウト' in received_message:
            pass

        elif 'クイックリプライ' in received_message:
            sending_message = TextSendMessage(
                text='Hello, world',
                quick_reply=QuickReply(items=[
                    QuickReplyButton(
                        action=MessageAction(label="label01", text="text01"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=01"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label02", text="text02"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=02"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label03", text="text03"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=03"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label04", text="text04"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=04"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label05", text="text05"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=05"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label06", text="text06"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=06"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label07", text="text07"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=07"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label08", text="text08"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=08"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label09", text="text09"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=09"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label10", text="text10"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=10"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label11", text="text11"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=11"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label12", text="text12"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=12"
                    ),
                    QuickReplyButton(
                        action=MessageAction(label="label13", text="text13"),
                        image_url=
                        "https://placehold.jp/24/ffffff/000000/50x50.png?text=13"
                    )
                ]))
        else:
            sending_message = TextSendMessage(received_message)

        return sending_message
Exemplo n.º 13
0
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