def price(): mes = BubbleContainer( header=BoxComponent(layout='baseline', contents=[ TextComponent(text='Q5:價格預算', weight='bold', size='xxl', flex=2, align='center') ]), body=BoxComponent( layout='vertical', spacing='xs', contents=[ ButtonComponent(style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='100~350元', text='100~350元')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='351~600元', text='351~600元')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='600元以上', text='600元以上')) ])) message = FlexSendMessage(alt_text="hello", contents=mes) return message
def build_rabbit_adopt_content(): container = BubbleContainer( direction='ltr', body=BoxComponent( layout='vertical', contents=[ TextComponent(text='你還沒有兔子', weight='bold', size='xl'), SeparatorComponent(), BoxComponent(layout='horizontal', spacing='sm', contents=[ ButtonComponent( style='primary', height='sm', color='#95B9B4', action=MessageAction(label='領養兔子', text='領養兔子'), ), ButtonComponent(style='primary', height='sm', color='#95B9B4', action=MessageAction( label='沒事了', text='沒事了')) ]) ], ), ) return container
def chain(): mes = BubbleContainer( header=BoxComponent(layout='baseline', contents=[ TextComponent(text='Q4:想購買的通路', weight='bold', size='xxl', flex=2, align='center') ]), body=BoxComponent( layout='vertical', spacing='xs', contents=[ ButtonComponent(style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='家樂福', text='家樂福')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='全聯', text='全聯')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='Costco', text='Costco')) ])) message = FlexSendMessage(alt_text="hello", contents=mes) return message
def test_template(): conn = model.Conn() # get all subject by class_id query_select_subject = 'SELECT * FROM subject WHERE id = %s' conn.query(query_select_subject, '2') row_subject = conn.cursor.fetchone() # get all topic by subject_id query_select_topic = 'SELECT * FROM topic WHERE subject_id = %s' conn.query(query_select_topic, '1') rows_topic = conn.cursor.fetchall() if len(rows_topic) == 0: # topic is empty line_bot_api.reply_message(event.reply_token, [TextMessage(text=constant.TOPIC_EMPTY)]) else: # topic exist contents = [] for row in rows_topic: contents.append( BubbleContainer( direction='ltr', body=BoxComponent( layout='vertical', contents=[ TextComponent(text=str(row['name']), margin='md', size='xl', align='center', gravity='center', weight='bold'), ButtonComponent(action=PostbackAction( label='Belajar', text='Belajar', data='action=material_learn&subject_id=' + str(row_subject['id']) + '&topic_id=' + str(row['id']))), ButtonComponent(action=PostbackAction( label='Diskusi', text='Diskusi', data='action=material_discussion&subject_id=' + str(row_subject['id']) + '&topic_id=' + str(row['id']))), ButtonComponent(action=PostbackAction( label='Latihan Soal', text='Latihan Soal', data='action=material_quiz&subject_id=' + str(row_subject['id']) + '&topic_id=' + str(row['id']))) ]))) flex_message = FlexSendMessage( alt_text='Carousel Topik', contents=CarouselContainer(contents=contents)) print('HERE, contents:', contents) print('HERE, flex_message:', flex_message) return 'OK'
def single(set1): for x in set1: mes = BubbleContainer( hero=ImageComponent(url=set1[x], size='full', align='center', aspect_ratio='13:13', aspect_mode='cover'), body=BoxComponent(layout='vertical', contents=[ TextComponent(margin='md', text=x, weight='bold', size='md', align='center'), SeparatorComponent(margin='xl', color='#0000FF'), BoxComponent(margin='md', layout='horizontal', spacing='xs', contents=[ ButtonComponent( style='link', color='#84C1FF', flex=1, height='sm', action=MessageAction( label="我的最愛", text='SeeMyLove')) ]) ])) return FlexSendMessage(alt_text="hello", contents=mes) else: return TextSendMessage(text="None img")
def integer_word(word): content = look_up(word) if content != '查無此字': content = [ TextComponent(text='🔍英文單字查詢', weight='bold', align='center', size='md', wrap=True, color='#000000'), SeparatorComponent(margin='lg'), TextComponent(text=content, size='sm', wrap=True, color='#000000') ] audio_button = [ SeparatorComponent(), ButtonComponent(style='link', height='sm', action=PostbackAction( label='📢 美式發音', data='audio/{}'.format(word))) ] bubble = get_total_flex(content, audio_button) message = FlexSendMessage(alt_text="hello", contents=bubble) else: message = TextSendMessage(text=content) return message
def res_user_status(event): profile = line_bot_api.get_profile(event.source.user_id) status_msg = profile.status_message if status_msg != "None": # LINEに登録されているstatus_messageが空の場合は、"なし"という文字列を代わりの値とする status_msg = "なし" message=FlexSendMessage( alt_text='ユーザー情報', contents=BubbleContainer( header=BoxComponent( layout="vertical", contents=[ TextComponent( text='text', align='center', gravity='center', contents=[ SpanComponent(text='ユーザー情報') ] ) ] ),#Header hero=ImageComponent( url=profile.picture_url, size="full", aspect_mode="fit", action=None ), body=BoxComponent( layout="vertical", contents=[ TextComponent( text='text', align='center', gravity='center', contents=[ SpanComponent(text=f'User Id: {profile.user_id}') ] ), TextComponent( text='text', align='center', gravity='center', contents=[ SpanComponent(text=f'Status Message: {status_msg}') ] ) ] ),#Body footer=BoxComponent( layout="vertical", contents=[ ButtonComponent( action=MessageAction(label="成功", text="?") ) ] )#Footer ) ) line_bot_api.reply_message(event.reply_token, messages=message)
def add_video(template, title, url, thumbnails): bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url=thumbnails, size='full', aspect_ratio='20:13', aspect_mode='cover', gravity='center'), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text=title, wrap=True, weight='bold', size='xxl', align='center') ]), footer=BoxComponent(layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='link', height='sm', action=URIAction(label='點擊查看', uri=url), ) ]), ) template.contents.append(bubble) return template
def get_greeting_carousel(parts: list): buttons = [] elements = [] for i, part in enumerate(parts): elements.append( ButtonComponent(color='#097AC5', action=MessageAction(label=part, text=part))) if i % 2 == 1: buttons.append( BoxComponent(layout="horizontal", color='#097AC5', contents=list(elements))) elements = [] return CarouselContainer(contents=[ BubbleContainer( size='mega', body=BoxComponent( layout="vertical", background_color='#f8f8f8', contents=[ TextComponent( align='start', color='#222E38', text= '😇If wanna know me more, please click your interested section below!', size='md', weight='regular', wrap=True) ]), footer=BoxComponent(layout="vertical", padding_all='none', background_color='#F8F8F8', contents=list(buttons))) ])
def intro(self, name): bubble = BubbleContainer( # body body=BoxComponent( layout='vertical', spacing='md', contents=[ TextComponent(text='Hello {0},\n\n'.format(name), weight='bold', size='lg'), # main info TextComponent(text='我是呂明聲,現在就讀中央資管所碩一,熱愛開發、嘗試新技術,喜歡透過資訊科技解決問題 !\n\n如履歷所述,我曾擔任過資源教室助教及銀行資訊部實習生,喜歡協助同學也喜歡團隊合作解決問題,相信是TechFRESH不可或缺的Hack, everything 精神 !\n\n很高興能在這相遇,期望這是我們認識的開始!\n\nRegards,\nMing-Sheng,Lyu', size='md', wrap=True, color='#272727'), SeparatorComponent(margin='xl'), BoxComponent( layout = 'vertical', contents = [ SpacerComponent(size='md'), ButtonComponent( style='primary', height='sm', action=MessageAction(label="SAM's Skill", text='你會什麼?'), ) ] ) ] ) ) message = FlexSendMessage(alt_text="SAM's Intro", contents=bubble) return message
def construct_multiple_choice(data): actions = [] for button in data.get("buttons"): actions.append( ButtonComponent( style="primary", height="sm", margin="md", action=MessageAction(label=button.get("title"), text=button.get("title")), )) bubble = BubbleContainer( direction="ltr", body=BoxComponent( layout="vertical", contents=construct_mc_header(data) + [ TextComponent( text=data.get("text"), size="md", margin="lg", wrap=True, ) ], ), footer=BoxComponent(layout="vertical", contents=actions), ) return bubble
def test_button_component(self): arg = { 'action': URIAction(label='Tap me', uri='https://example.com'), 'style': 'primary', 'color': '#0000ff' } self.assertEqual(self.serialize_as_dict(arg, type=self.BUTTON), ButtonComponent(**arg).as_json_dict())
def button(choice, button_color): button = ButtonComponent( style='primary', color=button_color, height='sm', action=PostbackAction(label=choice, data=choice, text=choice), ) return button
def feedback(event): bubble = BubbleContainer(direction='ltr', body=BoxComponent(layout='vertical', contents=[ # title TextComponent(text='笑話回饋', weight='bold', size='xl'), # info BoxComponent(layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent(layout='baseline', spacing='sm', contents=[ TextComponent( text='請問您覺得這個笑話好笑嗎?', color='#aaaaaa', size='sm', flex=1 ), ], ) ], ) ],), footer=BoxComponent(layout='vertical', spacing='sm', contents=[ # callAction ButtonComponent( style='link', height='sm', action=MessageAction(label='好笑', text= '好笑'), ), ButtonComponent( style='link', height='sm', action=MessageAction(label='有點好笑', text= '有點好笑'), ), ButtonComponent( style='link', height='sm', action=MessageAction(label='不好笑', text= '不好笑'), ), ] ), ) message = FlexSendMessage(alt_text="笑話回饋", contents=bubble) return message
def taste(): mes = BubbleContainer( header=BoxComponent(layout='baseline', contents=[ TextComponent(text='Q3:想要的口感', weight='bold', size='xxl', flex=2, align='center') ]), body=BoxComponent(layout='vertical', spacing='xs', contents=[ ButtonComponent(style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='清香', text='清香')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='甜', text='甜')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='圓潤', text='圓潤')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='酸', text='酸')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='濃厚', text='濃厚')) ])) message = FlexSendMessage(alt_text="hello", contents=mes) return message
def aroma(): mes = BubbleContainer( header=BoxComponent(layout='baseline', contents=[ TextComponent(text='Q2:喜歡的香氣', weight='bold', size='xxl', flex=2, align='center') ]), body=BoxComponent( layout='vertical', spacing='xs', contents=[ ButtonComponent(style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='花香 (ex:玫瑰花...)', text='花香')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='漿果 (ex:櫻桃...)', text='漿果')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='柑橘 (ex:檸檬...)', text='柑橘')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='熱帶水果 (ex:鳳梨...)', text='熱帶水果')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='淺色水果 (ex:杏桃...)', text='淺色水果')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='香料 (ex:胡椒...)', text='香料')), ButtonComponent(margin='xl', style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='土木 (ex:橡木桶...)', text='土木')) ])) message = FlexSendMessage(alt_text="hello", contents=mes) return message
def create_bubble_container(thumbnail_image_url, video_url): return BubbleContainer( direction='ltr', hero=ImageComponent(url=thumbnail_image_url, size='full', aspectRatio='16:9', aspectMode='cover'), body=BoxComponent( layout='vertical', contents=[ ButtonComponent(action=URIAction(label='觀看影片', uri=video_url), style='primary', color='#29D90C', margin='lg'), ButtonComponent(action=URIAction( label='分享影片', uri='https://line.me/R/msg/text/?' + video_url), style='primary', color='#29D90C', margin='lg') ]))
def ask(txt, event): bubble = BubbleContainer(direction='ltr', body=BoxComponent(layout='vertical', contents=[ # title TextComponent(text='是否有達到破冰效果?', weight='bold', size='xl'), # info BoxComponent(layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent(layout='baseline', spacing='sm', contents=[ TextComponent( text='在特定場合使用是否有達到破冰效果呢?', color='#aaaaaa', size='sm', flex=1 ), ], ) ], ) ],), footer=BoxComponent(layout='vertical', spacing='sm', contents=[ # callAction ButtonComponent( style='link', height='sm', action=MessageAction(label='有', text= '有達到破冰效果'), ), ButtonComponent( style='link', height='sm', action=MessageAction(label='沒有', text= '沒有達到破冰效果'), ), ] ), ) message = FlexSendMessage(alt_text="是否破冰", contents=bubble) return message
def more(txt, event, userID): bubble = BubbleContainer(direction='ltr', body=BoxComponent(layout='vertical', contents=[ # title TextComponent(text='是否再來一個笑話?', weight='bold', size='xl'), # info BoxComponent(layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent(layout='baseline', spacing='sm', contents=[ TextComponent( text='是否再來一個相同關鍵字的笑話?', color='#aaaaaa', size='sm', flex=1 ), ], ) ], ) ],), footer=BoxComponent(layout='vertical', spacing='sm', contents=[ # callAction ButtonComponent( style='link', height='sm', action=MessageAction(label='再來一個', text= intxt[userID]), ), ButtonComponent( style='link', height='sm', action=MessageAction(label='不用', text= '不用'), ), ] ), ) message = FlexSendMessage(alt_text="再來一個", contents=bubble) return message
def get_total_flex(body_content,footer_content=[ButtonComponent(style='link',action=URIAction(label='My github', uri='https://github.com/kevin1061517?tab=repositories'))]): bubble = BubbleContainer( body=BoxComponent( layout='vertical', contents=body_content ), footer=BoxComponent( layout='vertical', spacing='sm', contents= footer_content ) ) return bubble
def showimg(): mes = BubbleContainer(body=BoxComponent( layout='vertical', spacing='xs', contents=[ ButtonComponent(style='secondary', color='#FFEE99', height='sm', action=MessageAction(label='ShowImg', text='showImg')) ])) message = FlexSendMessage(alt_text="hello", contents=mes) return message
def create_response(self): contents = [ TextComponent(text=self._context['text'], wrap=True, size='sm'), ] contents.append( ButtonComponent(style='primary', color=Colors['primary'], action=URIAction( label=self._context['button']['text'], uri=self._context['button']['uri']))) return FlexSendMessage( alt_text=self._context['text'], contents=BubbleContainer(body=BoxComponent( layout='vertical', contents=contents, spacing='md')))
def get_tests_for_concern(req): diseases = req.get('queryResult').get('parameters').get('diseases', '') print('disease is {}'.format(diseases)) if not diseases: return None tests = [] q = prepareQuery( ('SELECT ?testname ?tcode WHERE { ?a rdfs:label ?disease .' '?test lab:screenFor ?a .' '?test lab:code ?tcode .' '?test rdfs:label ?testname .}'), initNs={ 'lab': labn, 'foaf': FOAF, 'rdfs': RDFS }) for row in graph.query(q, initBindings={'disease': diseases}): print(row.testname) tests.append({'name': row.testname, 'code': row.tcode}) instruction = 'กรุณาพิมพ์รหัสในวงเล็บสำหรับรายละเอียดของรายการตรวจ' message = 'ควรตรวจ {} {}'.format( join_and([t['name'] for t in tests], sep=" "), instruction) bubbles = [] for t in tests: bubbles.append( BubbleContainer( body=BoxComponent(layout='vertical', contents=[ TextComponent( text=u'{}'.format(t['name']), weight='bold', size='xl', gravity='center', align='center', ) ]), footer=BoxComponent( layout='vertical', contents=[ ButtonComponent(action=MessageAction( label='detail', text=u'{}'.format(t['code']))) ]))) return bubbles
def welcome(self): bubble = BubbleContainer( # header header=BoxComponent( layout='horizontal', contents=[ TextComponent(text='哆哆歡迎您', weight='bold', size='lg', color='#00BE00') ] ), #hero hero=ImageComponent(url='https://i.imgur.com/onXQU46.png', size='full', aspect_ratio='16:9', aspect_mode='cover'), # body body=BoxComponent( layout='vertical', spacing='md', contents=[ # main info TextComponent(text='嗨,我是哆哆,感謝您加我為好友,我會回答您的問題讓您更進一步了解明聲。讓我們開始吧!\n\n您可以直接輸入:\n\n可以介紹一下嗎?\n你會什麼?\n你有什麼作品?\n有拿過什麼認證嗎?\n\n當不知道如何使用時,請輸入help\n我會出來為您引導。', size='md', wrap=True, color='#6c6c6c'), SeparatorComponent(margin='xl'), BoxComponent( layout = 'vertical', contents = [ SpacerComponent(size='md'), ButtonComponent( style='primary', height='sm', action=MessageAction(label="Let's Start", text='可以介紹一下嗎?'), ) ] ) ] ) ) message = FlexSendMessage(alt_text="Welcome", contents=bubble) return message
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 tenMod(dset): contents = [] if len(dset): for x in dset: contents.append( BubbleContainer( hero=ImageComponent(url=x, size='full', align='center', aspect_ratio='13:13', aspect_mode='cover'), body=BoxComponent( layout='vertical', contents=[ TextComponent(margin='md', text=dset[x], weight='bold', size='md', align='center'), SeparatorComponent(margin='xl', color='#0000FF'), BoxComponent(margin='md', layout='horizontal', spacing='xs', contents=[ ButtonComponent( style='link', color='#84C1FF', flex=1, height='sm', action=MessageAction( label="加入最愛", text='MyLove:' + dset[x])) ]) ]))) Carousel = CarouselContainer(contents=contents) message = FlexSendMessage(alt_text="hello", contents=Carousel) else: message = TextSendMessage(text='無符合您輸入的葡萄酒'+chr(0x100010)+"\n"\ +"請重新選擇"+chr(0x10008D)) return message
def get_bugua_flex_message(megDict, to, reply=True): bubble = BubbleContainer( direction='ltr', header=BoxComponent(layout='baseline', margin='md', contents=[ TextComponent(text=megDict['title'], weight='bold', size='xl'), ]), body=BoxComponent(layout='horizontal', margin='sm', spacing='sm', contents=[ ImageComponent( size='sm', url=megDict['img'][1], ), TextComponent(text=megDict['explanation'], wrap=True, color='#666666', size='sm', flex=5), ]), footer=BoxComponent(layout='vertical', spacing='sm', contents=[ SeparatorComponent(), ButtonComponent(style='link', height='sm', action=URIAction( label=megDict['btn_word'], uri=megDict['url'])) ]), ) message = FlexSendMessage(alt_text=megDict['title'], contents=bubble) if reply: line_bot_api.reply_message(to, message) else: line_bot_api.push_message(to, message)
def create_location_flex_message(): bubble=BubbleContainer( body=BoxComponent( layout='vertical', contents=[ TextComponent( text='告訴我你在哪裡呀👉👈', weight='bold', size='xl', ) ] ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ ButtonComponent( style='primary', height='sm', action=URIAction( label='送出我的位置', uri='https://line.me/R/nv/location/', ), color="#EA8244" ), SpacerComponent( size='sm' ) ], flex=0, ) ) return FlexSendMessage(alt_text="送出位置", contents=bubble)
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")) ))
def get_video_menu(): return BubbleContainer( direction='ltr', #hero=ImageComponent( # url='https://previews.123rf.com/images/galinadarla/galinadarla1610/galinadarla161000124/67174940-web-site-menu-icon-flat-style-made-in-vector-black-and-white-icon.jpg', # size='full', # aspectRatio='16:9', # aspectMode='cover' #), body=BoxComponent( layout='vertical', contents=[ ButtonComponent(action=MessageAction(label='最新上傳', text='最新上傳'), style='primary', color='#29D90C', margin='lg'), ButtonComponent(action=MessageAction(label='熱門影片', text='熱門影片'), style='primary', color='#29D90C', margin='lg'), ButtonComponent(action=MessageAction(label='最多喜歡', text='最多喜歡'), style='primary', color='#29D90C', margin='lg'), ButtonComponent(action=MessageAction(label='相關影片', text='相關影片'), style='primary', color='#29D90C', margin='lg'), ButtonComponent(action=MessageAction(label='標題順序', text='標題順序'), style='primary', color='#29D90C', margin='lg'), ButtonComponent(action=MessageAction(label='影片上傳次數', text='影片上傳次數'), style='primary', color='#29D90C', margin='lg') ]))