def getRate(rate): if rate < 0: return [ TextComponent(text="RATING UNKNOW", size='sm', color='#aaaaaa', flex=1, margin='md') ] component = [] _rate = int(rate) for i in range(_rate): component.append( IconComponent( size='sm', url= 'https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png' )) for i in range(5 - _rate): component.append( IconComponent( size='sm', url= 'https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gray_star_28.png' )) component.append( TextComponent(text=str(rate), size='sm', color='#aaaaaa', flex=1, margin='md')) return component
def test_icon_component(self): arg = { 'url': 'https://example.com/icon/png/caution.png', 'size': 'lg', 'aspect_ratio': '1.91:1' } self.assertEqual(self.serialize_as_dict(arg, type=self.ICON), IconComponent(**arg).as_json_dict())
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 )
def handle_message(self, event): self._message_data_save(event) text = event.message.text if text == 'finished': try: user_data = LineInputData.objects.filter(user_id=event.source.user) user = User.create( first_name=user_data.object.filter(question='first_name').answer, last_name=user_data.object.filter(question='last_name').answer, ) user_info = UserInfo.create( user=user, motive=user_data.object.filter(question='motive').answer, ) job_histories_count = user_data.filter(question__startwith='job_history').count for i in range(job_histories_count): JobHistory.create( user_info=user_info, start_date=user_data.object.filter(question=f'start_date_{i}').answer, end_date=user_data.object.filter(question=f'end_date_{i}').answer, history=user_data.object.filter(question=f'job_history_{i}').answer, ) logger.info(f'Create user:{user.id} user_info:{user_info.id}') except Exception: raise DataError elif text == 'profile': if isinstance(event.source, SourceUser): profile = self.line_bot_api.get_profile(event.source.user_id) self.line_bot_api.reply_message( event.reply_token, [ TextSendMessage(text='Display name: ' + profile.display_name), TextSendMessage(text='Status message: ' + profile.status_message) ] ) else: self.line_bot_api.reply_message( event.reply_token, TextSendMessage(text="Bot can't use profile API without user ID")) elif text == 'bye': if isinstance(event.source, SourceGroup): self.line_bot_api.reply_message( event.reply_token, TextSendMessage(text='Leaving group')) self.line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): self.line_bot_api.reply_message( event.reply_token, TextSendMessage(text='Leaving group')) self.line_bot_api.leave_room(event.source.room_id) else: self.line_bot_api.reply_message( event.reply_token, TextSendMessage(text="Bot can't leave from 1:1 chat")) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!'), ]) template_message = TemplateSendMessage( alt_text='Confirm alt text', template=confirm_template) self.line_bot_api.reply_message(event.reply_token, template_message) elif text == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) template_message = TemplateSendMessage( alt_text='Buttons alt text', template=buttons_template) self.line_bot_api.reply_message(event.reply_token, template_message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), CarouselColumn(text='hoge2', title='fuga2', actions=[ PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage( alt_text='Carousel alt text', template=carousel_template) self.line_bot_api.reply_message(event.reply_token, template_message) elif text == 'image_carousel': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn(image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn(image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) self.line_bot_api.reply_message(event.reply_token, template_message) elif text == 'imagemap': pass elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label') ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent( style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com") ) ] ), ) message = FlexSendMessage(alt_text="hello", contents=bubble) self.line_bot_api.reply_message( event.reply_token, message ) elif text == 'quick_reply': self.line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply( items=[ QuickReplyButton( action=PostbackAction(label="label1", data="data1") ), QuickReplyButton( action=MessageAction(label="label2", text="text2") ), QuickReplyButton( action=DatetimePickerAction(label="label3", data="data3", mode="date") ), QuickReplyButton( action=CameraAction(label="label4") ), QuickReplyButton( action=CameraRollAction(label="label5") ), QuickReplyButton( action=LocationAction(label="label6") ), ]))) elif text == "liff": self.line_bot_api.reply_message( event.reply_token, [ TextSendMessage( text='https://line.me/R/app/1615588360-p4vKyQMV'), ] ) elif text == "purchase": previous_bot_message = "question" self.line_bot_api.reply_message( event.reply_token, [ TextSendMessage(text='商品の購入ですね!\nそれではいくつか質問させてもらいますね。'), TextSendMessage(text='これから購入のための情報をお聞きしますが、'), ConfirmTemplate( action=[ MessageAction( label='chat', text='ちゃっとで答える' ), MessageAction( label='webpage', text='Webページで入力する' ), ] ) ] ) elif previous_bot_message == "question" and text == "chat": previous_bot_message = "name" self.line_bot_api.reply_message( event.reply_token, [ TextSendMessage(text='ありがとうございます!!'), TextSendMessage(text='さっそくお名前を教えてもらえますか?'), ] )
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 == 'byebot': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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='Culum 1', text='/Boy-FirA'), MessageTemplateAction(label='CULUM 2', text='/Boy-FirA'), MessageTemplateAction(label='CULUM 3', text='/Boy-FirA') ])) line_bot_api.reply_message(event.reply_token, buttons_template) #=====[ CAROUSEL MESSAGE ]========== elif text == 'Addme': message = TemplateSendMessage( alt_text='OTHER MENU', template=CarouselTemplate(columns=[ CarouselColumn( title='ADD ME LINE ME', text='Contact Boy-FirA', actions=[ URITemplateAction( label='>TAP HERE<', uri='https://line.me/R/ti/p/~limbizkids') ]), CarouselColumn(title='smule', text='FIND ME ON SMULE', actions=[ URITemplateAction( label='>TAP HERE!<', uri='https://smule.com/boy_IVE_GBSA') ]) ])) line_bot_api.reply_message(event.reply_token, message) #=====[ FLEX MESSAGE ]========== elif text == '/boy': bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url= 'http://resizeimage.net/viewimg/JdQCC49kMpIvjPHI/ye65D/1523427347605.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='https://line.me/R/ti/p/~limbizkids', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Boy-FirA', 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='Sorong, 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='Boy-FirA', uri="https://line.me/R/ti/p/~limbizkids")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message)
def handle_text_message(event): text = event.message.text if text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Display name: ' + profile.display_name), TextSendMessage(text='Status message: ' + str(profile.status_message)) ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Bot can't use profile API without user ID")) elif text == 'quota': quota = line_bot_api.get_message_quota() line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='type: ' + quota.type), TextSendMessage(text='value: ' + str(quota.value)) ]) elif text == 'quota_consumption': quota_consumption = line_bot_api.get_message_quota_consumption() line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='total usage: ' + str(quota_consumption.total_usage)), ]) elif text == 'push': line_bot_api.push_message(event.source.user_id, [ TextSendMessage(text='PUSH!'), ]) elif text == 'multicast': line_bot_api.multicast([event.source.user_id], [ TextSendMessage(text='THIS IS A MULTICAST MESSAGE'), ]) elif text == 'broadcast': line_bot_api.broadcast([ TextSendMessage(text='THIS IS A BROADCAST MESSAGE'), ]) elif text.startswith('broadcast '): # broadcast 20190505 date = text.split(' ')[1] print("Getting broadcast result: " + date) result = line_bot_api.get_message_delivery_broadcast(date) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Number of sent broadcast messages: ' + date), TextSendMessage(text='status: ' + str(result.status)), TextSendMessage(text='success: ' + str(result.success)), ]) elif text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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")) elif text == 'image': url = request.url_root + '/static/logo.png' app.logger.info("url=" + url) line_bot_api.reply_message(event.reply_token, ImageSendMessage(url, url)) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), CarouselColumn(text='hoge2', title='fuga2', actions=[ PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'image_carousel': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction( label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'imagemap': pass elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'flex_update_1': bubble_string = """ { "type": "bubble", "body": { "type": "box", "layout": "vertical", "contents": [ { "type": "image", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/flexsnapshot/clip/clip3.jpg", "position": "relative", "size": "full", "aspectMode": "cover", "aspectRatio": "1:1", "gravity": "center" }, { "type": "box", "layout": "horizontal", "contents": [ { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "Brown Hotel", "weight": "bold", "size": "xl", "color": "#ffffff" }, { "type": "box", "layout": "baseline", "margin": "md", "contents": [ { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png" }, { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png" }, { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png" }, { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png" }, { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gray_star_28.png" }, { "type": "text", "text": "4.0", "size": "sm", "color": "#d6d6d6", "margin": "md", "flex": 0 } ] } ] }, { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "¥62,000", "color": "#a9a9a9", "decoration": "line-through", "align": "end" }, { "type": "text", "text": "¥42,000", "color": "#ebebeb", "size": "xl", "align": "end" } ] } ], "position": "absolute", "offsetBottom": "0px", "offsetStart": "0px", "offsetEnd": "0px", "backgroundColor": "#00000099", "paddingAll": "20px" }, { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "SALE", "color": "#ffffff" } ], "position": "absolute", "backgroundColor": "#ff2600", "cornerRadius": "20px", "paddingAll": "5px", "offsetTop": "10px", "offsetEnd": "10px", "paddingStart": "10px", "paddingEnd": "10px" } ], "paddingAll": "0px" } } """ message = FlexSendMessage(alt_text="hello", contents=json.loads(bubble_string)) line_bot_api.reply_message(event.reply_token, message) elif text == 'quick_reply': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply(items=[ QuickReplyButton( action=PostbackAction(label="label1", data="data1")), QuickReplyButton( action=MessageAction(label="label2", text="text2")), QuickReplyButton(action=DatetimePickerAction( label="label3", data="data3", mode="date")), QuickReplyButton(action=CameraAction(label="label4")), QuickReplyButton(action=CameraRollAction(label="label5")), QuickReplyButton(action=LocationAction(label="label6")), ]))) elif text == 'link_token' and isinstance(event.source, SourceUser): link_token_response = line_bot_api.issue_link_token( event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='link_token: ' + link_token_response.link_token) ]) elif text == 'insight_message_delivery': today = datetime.date.today().strftime("%Y%m%d") response = line_bot_api.get_insight_message_delivery(today) if response.status == 'ready': messages = [ TextSendMessage(text='broadcast: ' + str(response.broadcast)), TextSendMessage(text='targeting: ' + str(response.targeting)), ] else: messages = [TextSendMessage(text='status: ' + response.status)] line_bot_api.reply_message(event.reply_token, messages) elif text == 'insight_followers': today = datetime.date.today().strftime("%Y%m%d") response = line_bot_api.get_insight_followers(today) if response.status == 'ready': messages = [ TextSendMessage(text='followers: ' + str(response.followers)), TextSendMessage(text='targetedReaches: ' + str(response.targeted_reaches)), TextSendMessage(text='blocks: ' + str(response.blocks)), ] else: messages = [TextSendMessage(text='status: ' + response.status)] line_bot_api.reply_message(event.reply_token, messages) elif text == 'insight_demographic': response = line_bot_api.get_insight_demographic() if response.available: messages = [ "{gender}: {percentage}".format(gender=it.gender, percentage=it.percentage) for it in response.genders ] else: messages = [TextSendMessage(text='available: false')] line_bot_api.reply_message(event.reply_token, messages) else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text))
def handle_message(event): text = event.message.text user_id = event.source.user_id print(user_id) print(text) if text == '自我介紹': bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='https://i.imgur.com/RXQnxHs.jpg', size='3xl', aspect_mode='cover', gravity='center', ), body=BoxComponent( layout='vertical', contents=[ SeparatorComponent(margin='xxl'), # title TextComponent( text='張書維 Vicharm Chang', weight='bold', size='xl', align='center', margin='lg'), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='程式語言', color='#aaaaaa', size='sm', flex=2 ), TextComponent( text='Python, C, C++', wrap=True, color='#666666', size='sm', flex=5 ) ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='學籍', color='#aaaaaa', size='sm', flex=2 ), TextComponent( text="台大電機所計算機組,碩一", wrap=True, color='#666666', size='sm', flex=5, ), ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='畢業學校', color='#aaaaaa', size='sm', flex=2 ), TextComponent( text="成功大學資訊工程學系", wrap=True, color='#666666', size='sm', flex=5, ), ], ), ], ), TextComponent( text='學習軟體程式8年 對軟體開發有極大興趣', color='#666666', size='sm', margin='lg' ), ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='primary', color='#6D5546', height='sm', action=MessageAction(label='查看專案', text='開發專案經驗'), ), ButtonComponent( style='primary', color='#6D5546', height='sm', action=MessageAction(label='自我推薦', text='自我推薦'), ) ] ), ) message = FlexSendMessage(alt_text="自我介紹", contents=bubble) line_bot_api.reply_message( event.reply_token, message ) elif text == '開發專案經驗': carousel = CarouselContainer( contents=[ BubbleContainer( direction='ltr', hero=ImageComponent( url='https://i.imgur.com/kj7UJcl.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', gravity='center' ), body=BoxComponent( margin='lg', layout='vertical', contents=[ # title TextComponent(text='Konma Bot', wrap=True, weight='bold', size='xxl', align='center'), # info BoxComponent( margin='lg', layout='vertical', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ IconComponent( url='https://i.imgur.com/YMxsgqo.png'), TextComponent( text='毛孩影片推播', color='#666666', size='sm', ), ] ), BoxComponent( layout='baseline', spacing='sm', contents=[ IconComponent( url='https://i.imgur.com/gtkZuKm.png'), TextComponent( text='領養送養查詢', color='#666666', size='sm', ), ] ), BoxComponent( layout='baseline', spacing='sm', contents=[ IconComponent( url='https://i.imgur.com/zALcrA5.png'), TextComponent( text='寵物知識問答', color='#666666', size='sm', ), ] ), BoxComponent( layout='baseline', spacing='sm', contents=[ IconComponent( url='https://i.imgur.com/0lRYfH6.png'), TextComponent( text='飼主交友分享', color='#666666', size='sm', ), ] ), ] ) ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='link', height='sm', action=MessageAction( label='試玩影片推播功能', text='試玩Konma Bot'), ), ButtonComponent( style='link', height='sm', action=URIAction( label='查看github專案', uri='https://github.com/changsuwi/Konma-Chatbot'), ) ] ), ), BubbleContainer( direction='ltr', hero=ImageComponent( url='https://live.staticflickr.com/949/27294712367_63f3db8890_z_d.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', gravity='center' ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Bon Voyage', wrap=True, weight='bold', size='xxl', align='center'), # info BoxComponent( margin='lg', layout='vertical', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ IconComponent( url='https://i.imgur.com/syxg5cD.png'), TextComponent( text='串接google map api 做資料視覺化', color='#666666', size='sm', flex=1 ), ] ), BoxComponent( layout='baseline', spacing='sm', contents=[ IconComponent( url='https://i.imgur.com/Ye12a4V.png'), TextComponent( text='直觀查看熱門景點動態', color='#666666', size='sm', flex=1 ), ] ), BoxComponent( layout='baseline', spacing='sm', contents=[ IconComponent( url='https://i.imgur.com/spcJLhA.png'), TextComponent( text="上傳圖片,與其他使用者分享", wrap=True, color='#666666', size='sm', flex=1, ), ] ), ] ), ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='link', height='sm', action=URIAction( label='查看專案github', uri='https://github.com/changsuwi/Travel-Photography' ), ), ] ), ), BubbleContainer( direction='ltr', hero=ImageComponent( url='https://i.imgur.com/kj7UJcl.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', gravity='center' ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ ButtonComponent( style='link', height='sm', action=URIAction( label='查看其他github專案', uri='https://github.com/changsuwi'), ) ] ), ), ] ) message = FlexSendMessage(alt_text="開發專案經驗", contents=carousel) line_bot_api.reply_message( event.reply_token, message ) elif text == '自我推薦': bubble = BubbleContainer( body=BoxComponent( layout='vertical', contents=[ TextComponent( text='選擇我的原因', weight='bold', size='xxl', margin='md', align='center' ), SeparatorComponent(margin='xxl'), BoxComponent( layout='vertical', margin='xxl', spacing='sm', contents=[ TextComponent( text='1. Chatbot與其他軟體開發經驗豐富', margin='md', size='sm' ), TextComponent( text='2. 對於computer science學科相當熟悉', margin='md', size='sm' ), TextComponent( text='3. 學習速度快,可以快速進入狀況', margin='md', size='sm' ), TextComponent( text='4. 有團隊開發經驗,縮小溝通成本', margin='md', size='sm' ), ] ) ] ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='primary', color='#6D5546', height='sm', action=MessageAction( label='查看自我介紹', text='自我介紹' ), ), ButtonComponent( style='primary', color='#6D5546', height='sm', action=MessageAction( label='查看開發專案', text='開發專案經驗' ), ), ] ), ) message = FlexSendMessage(alt_text="自我推薦", contents=bubble) line_bot_api.reply_message( event.reply_token, message) elif text == '試玩Konma Bot': message = FlexSendMessage(alt_text="試玩Konma Bot", contents=get_video()) line_bot_api.reply_message( event.reply_token, message ) message = TextSendMessage( text='想看更多', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction( label='更多寵物影片', text='試玩Konma Bot' ) ), QuickReplyButton( action=MessageAction( label='自我推薦', text='自我推薦' ) ), QuickReplyButton( action=MessageAction( label='開發專案經驗', text='開發專案經驗' ) ), ] ) ) line_bot_api.push_message( user_id, message ) else: message = TextSendMessage(text='請點選主選單,點擊有興趣的項目,謝謝') line_bot_api.reply_message( event.reply_token, message )
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 ]==========[ ARSYBAI ]====================== if text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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 ]=============[ ARSYBAI ]====================== elif text == '/template': buttons_template = TemplateSendMessage( alt_text='template', template=ButtonsTemplate( title='[ TEMPLATE MSG ]', text='Tap the Button', actions=[ MessageTemplateAction(label='Culum 1', text='/arsybai'), MessageTemplateAction(label='CULUM 2', text='/arsybai'), MessageTemplateAction(label='CULUM 3', text='/arsybai') ])) line_bot_api.reply_message(event.reply_token, buttons_template) #=====[ CAROUSEL MESSAGE ]==========[ ARSYBAI ]====================== elif text == '/carousel': message = TemplateSendMessage( alt_text='OTHER MENU', template=CarouselTemplate(columns=[ CarouselColumn(title='CAROUSEL 1', text='This Carousel URI action', actions=[ URITemplateAction( label='>carousel 1<', uri='https://line.me/ti/p/~arsy22bai') ]), CarouselColumn(title='ABAI-API', text='API documentation', actions=[ URITemplateAction( label='>Visit<', uri='https://arsybaiapi.herokuapp.com') ]) ])) line_bot_api.reply_message(event.reply_token, message) #=====[ FLEX MESSAGE ]==========[ RJBOTS ]====================== elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message)
def create_bubble_messages(contents): bubble_messages = [] for o in contents: header_text = o['header_text'] header = BoxComponent(type="box", layout="vertical", background_color=o['main_color'], contents=[ TextComponent( type="text", text=header_text, weight="bold", color="#FFFFFF", ) ]) hero = ImageComponent(url=o['profile_image'], size='full', aspect_ratio='2:1', aspect_mode='cover', action=URIAction(uri=o['tweet_url'])) body_image_box = BoxComponent( type="box", layout='horizontal', contents=o['images'], ) body_text_box = BoxComponent( type="box", layout='baseline', contents=[ IconComponent( type="icon", url=o['tweeter_icon'], size="sm", aspect_ratio="1:1", ), TextComponent( type="text", text=o['text'], weight='bold', size='sm', wrap=True, ), ], ) body = BoxComponent( type="box", layout='vertical', contents=[ body_image_box, body_text_box, ], ) footer_button = ButtonComponent( type="button", style="primary", action=URIAction(uri=o['tweet_url'], label='このツイートを見る'), color=o['main_color'], ) footer = BoxComponent( type="box", layout="horizontal", contents=[ footer_button, ], ) bubble = BubbleContainer( type="bubble", direction='ltr', header=header, hero=hero, body=body, footer=footer, ) bubble_messages.append(bubble) return bubble_messages
def flex_send_message_entity(self, entity): if not entity.match: return False value = _Tabelog_Value() value.set_value_tp(self.select_tabelog_entity(entity.name)) if value.name == '': return False image_url = my_s3_link_url(value.image_key) map_url = value.url + 'dtlmap/' stars_url = self._review_stars_url(value.score) bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url=image_url, size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction( uri=value.url ) ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text=value.name, weight='bold', size='xl' ), # review BoxComponent( layout='baseline', margin='md', contents=[ IconComponent(size='sm', url=stars_url[0]), IconComponent(size='sm', url=stars_url[1]), IconComponent(size='sm', url=stars_url[2]), IconComponent(size='sm', url=stars_url[3]), IconComponent(size='sm', url=stars_url[4]), TextComponent( text='{:.2f}'.format(value.score), size='md', color='#999999', margin='md',flex=0) ] ), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='最寄り駅', color='#aaaaaa', size='xs', flex=1 ), TextComponent( text=value.station, wrap=True, color='#666666', size='sm', flex=3 ) ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='ジャンル', color='#aaaaaa', size='xs', flex=1 ), TextComponent( text=value.genre, wrap=True, color='#666666', size='sm', flex=3 ), ], ), ], ) ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='primary', height='sm', action=URIAction(label='地図を見る', uri=map_url), ), # SeparatorComponent(), ButtonComponent( style='link', height='sm', action=MessageAction(label='ねこ', text='ねこ') ) ] ), ) message = FlexSendMessage(alt_text="tabelog flex", contents=bubble) return message
def create_carousel(items): # Flaskのロガーを取得 logger = logging.getLogger('flask.app') logger.debug(len(items)) bubbles = [] for item in items[:10]: hero = ImageComponent(url=item.img, size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri=item.url, label='label')) # body title_text_component = TextComponent( text=item.title, weight='bold', size='md', color='#5c5752', ) # tagをTextComponentの配列に整形 tag_components = [] for tag in item.tags: # if i == 0: # tag_components.append( # TextComponent( # text=tag, # size='sm', # color='#5c5752', # flex=0, # ) # ) # continue tag_components.append( TextComponent( text=tag, size='sm', color='#5c5752', flex=1, )) # 調理方法をiconComponentとtextComponentの配列に整形 cooking_method_components = [] for method in item.cooking_methods: cooking_method_components.append( IconComponent(url=DOMAIN + method['icon'], size='sm', color='#5c5752')) cooking_method_components.append( TextComponent(text=method['name'], size='sm', color='#5c5752', flex=1)) # 組み立て body = BoxComponent( layout='vertical', margin='xl', spacing='xl', contents=[ # title title_text_component, # tags, cooking methods BoxComponent(layout='vertical', spacing='md', contents=[ BoxComponent(layout='baseline', spacing='xl', contents=tag_components), BoxComponent( layout='baseline', spacing='sm', contents=cooking_method_components) ]), ], ) footer = BoxComponent( layout='vertical', spacing='sm', contents=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]) bubble = BubbleContainer( direction='ltr', hero=hero, body=body, footer=footer, ) bubbles.append(bubble) carousel = CarouselContainer(bubbles) return carousel
def sendFlex(event, backdata, user_id): #彈性配置 try: if not (teamUp.objects.filter(bid=user_id).exists()): #沒有訂房記錄 bubble = BubbleContainer( direction='ltr', #項目由左向右排列 header=BoxComponent( #標題 layout='vertical', contents=[ TextComponent(text='可以跑就是Runn-able', weight='bold', size='xl'), ] ), hero=ImageComponent( #主圖片 url='https://upload.cc/i1/2020/02/23/CrfWMt.png', size='full', aspect_ratio='792:555', #長寬比例 aspect_mode='cover', ), body=BoxComponent( #主要內容 layout='vertical', contents=[ TextComponent(text='按讚、留言,加meToo', size='md'), BoxComponent( layout='baseline', #水平排列 margin='md', contents=[ TextComponent(text='按', size='md', color='#999999',flex=0), IconComponent(size='lg',\ url='https://upload.cc/i1/2020/04/19/NLBGdU.png'), TextComponent(text='、 ', size='md', color='#999999',flex=0), IconComponent(size='md',\ url='https://upload.cc/i1/2020/04/19/D7mc9a.png'), TextComponent(text=' ,加me ', size='md', color='#999999', flex=0), IconComponent(size='lg',\ url='https://upload.cc/i1/2020/04/19/DlaV4C.png'), ] ), BoxComponent( layout='vertical', margin='lg', contents=[ BoxComponent( layout='baseline', contents=[ TextComponent(text='營業地址:', color='#aaaaaa', size='sm', flex=2), TextComponent(text='320桃園市中壢區中大路300號', color='#666666', size='sm', flex=5) ], ), SeparatorComponent(color='#0000FF'), BoxComponent( layout='baseline', contents=[ TextComponent(text='營業時間:', color='#aaaaaa', size='sm', flex=2), TextComponent(text="08:30 - 22:30", color='#666666', size='sm', flex=5), ], ), ], ), BoxComponent( layout='horizontal', margin='xxl', contents=[ ButtonComponent( style='link', height='sm', action=URIAction(label='點我查看商城訂單目前狀態',\ uri="https://liff.line.me/1653880251-yZpK05QY"), ) ] ), BoxComponent( layout='horizontal', margin='xxl', contents=[ ButtonComponent( style='secondary', height='sm', action=URIAction(label='電話', uri='tel:034257387'), ), ButtonComponent( style='primary', height='sm', action=URIAction(label='揪團',\ uri="line://app/1653880251-4b2aDNMl") ) ] ) ], ), footer=BoxComponent( #底部版權宣告 layout='vertical', contents=[ TextComponent(text='Copyright@III DA106 Group5', color='#888888', size='sm', align='center'), ] ), ) message = FlexSendMessage(alt_text="準備揪團", contents=bubble) else: #已有訂房記錄 message = TextSendMessage(text='您目前已有揪團,不能再揪團。') line_bot_api.reply_message(event.reply_token, message) except: line_bot_api.reply_message(event.reply_token, TextSendMessage(text='sendFlex發生錯誤!'))
size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://line.me/ti/p/~masih.00', label='label') ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='mosen.bw', 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(
def skill(self): bubble = BubbleContainer( body = BoxComponent( layout = 'vertical', contents = [ # header TextComponent(text="SAM's SKIL", weight='bold', size='sm', color='#1DB446'), TextComponent(text='Programming Skill', weight='bold', size='xxl', margin='md'), SeparatorComponent(margin='xxl'), # Body BoxComponent( layout = 'vertical', margin ='md', spacing = 'sm', contents = [ # Backend BoxComponent( layout='baseline', spacing='md', contents=[ IconComponent(url='https://i.imgur.com/8Uxdkpn.png', size='md'), TextComponent(text='Backend', size='lg', color='#7b7b7b') ] ), # node go BoxComponent( layout = 'horizontal', spacing = 'md', contents = [ TextComponent(text='Node.js - express', size='sm', color='#111111'), TextComponent(text='Golang - gin', size='sm', color='#111111'), ] ), # Mobile BoxComponent( layout='baseline', spacing='md', margin='xl', contents=[ IconComponent(url='https://i.imgur.com/0hOfB2w.png', size='md'), TextComponent(text='Mobile', size='lg', color='#7b7b7b') ] ), # swift BoxComponent( layout = 'horizontal', spacing = 'md', contents = [ TextComponent(text='Swift', size='sm', color='#111111'), ] ), # Others BoxComponent( layout='baseline', spacing='md', margin='xl', contents=[ IconComponent(url='https://i.imgur.com/etmNxkf.png', size='md'), TextComponent(text='Others', size='lg', color='#7b7b7b') ] ), # py c# java html/css git docker BoxComponent( layout = 'horizontal', spacing = 'md', contents = [ TextComponent(text='Python', size='sm', color='#111111'), TextComponent(text='C#', size='sm', color='#111111'), TextComponent(text='Java', size='sm', color='#111111') ] ), BoxComponent( layout = 'horizontal', spacing = 'md', contents = [ TextComponent(text='HTML/CSS', size='sm', color='#111111'), TextComponent(text='Git', size='sm', color='#111111'), TextComponent(text='Docker', size='sm', color='#111111') ] ), # DB BoxComponent( layout='baseline', spacing='md', margin='xl', contents=[ IconComponent(url='https://i.imgur.com/DaVwYMh.png', size='md'), TextComponent(text='Database', size='lg', color='#7b7b7b') ] ), # mysql ms oracle pg redis mongo BoxComponent( layout = 'horizontal', spacing = 'md', contents = [ TextComponent(text='MySQL', size='sm', color='#111111'), TextComponent(text='MSSQL', size='sm', color='#111111'), TextComponent(text='Oracle', size='sm', color='#111111') ] ), BoxComponent( layout = 'horizontal', spacing = 'md', contents = [ TextComponent(text='PostgreSQL', size='sm', color='#111111'), TextComponent(text='Redis', size='sm', color='#111111'), TextComponent(text='Mongo', size='sm', color='#111111') ] ), SeparatorComponent(margin='xxl'), # footer BoxComponent( layout = 'vertical', spacing = 'md', contents = [ SpacerComponent(size='md'), ButtonComponent( style='primary', height='sm', color='#00BE00', action=MessageAction(label="SAM's Portfolio", text='你有什麼作品?'), ), ButtonComponent( style='secondary', height='sm', action=URIAction(label="SAM's GitHub", uri='line://app/1570355825-rLKWJZK6'), ) ] ) ] ) ] ) ) message = FlexSendMessage(alt_text="SAM's Skill", contents=bubble) return message
def handle_text_message(event): text = event.message.text if text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Display name: ' + profile.display_name), TextSendMessage(text='Status message: ' + profile.status_message) ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Bot can't use profile API without user ID")) elif text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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")) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn( thumbnail_image_url= 'https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/shop-icon.png', image_background_color='#ffffff', text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), CarouselColumn( thumbnail_image_url= 'https://icons.iconarchive.com/icons/paomedia/small-n-flat/512/shop-icon.png', image_background_color='#FFFFFF', text='hoge2', title='fuga2', actions=[ PostbackAction( label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'image_carousel': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction( label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'imagemap': pass elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url= 'https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_2_restaurant.png', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', spacing='md', contents=[ # title TextComponent(text='Brown Cafe', weight='bold', size='xl'), # review BoxComponent( layout='baseline', margin='md', contents=[ IconComponent( size='sm', url= 'https://cdn4.iconfinder.com/data/icons/small-n-flat/24/star-512.png' ), IconComponent( size='sm', url= 'https://cdn4.iconfinder.com/data/icons/small-n-flat/24/star-512.png' ), IconComponent( size='sm', url= 'https://cdn4.iconfinder.com/data/icons/small-n-flat/24/star-512.png' ), IconComponent( size='sm', url= 'https://cdn4.iconfinder.com/data/icons/small-n-flat/24/star-512.png' ), IconComponent( size='sm', url= 'https://cdn4.iconfinder.com/data/icons/small-n-flat/24/star-512.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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='xxl'), # callAction ButtonComponent( style='primary', height='sm', # action=URIAction(label='CALL', uri='tel:000000'), color='#905c44', action=URIAction(label='Add to Cart', uri='https://linecorp.com')), # separator # SeparatorComponent(), # # websiteAction # ButtonComponent( # style='link', # height='sm', # action=URIAction(label='WEBSITE', uri="https://example.com") # ) ]), ) flex = [] flex.append(bubble) flex.append(bubble) a = CarouselContainer(type='carousel', contents=flex) message = FlexSendMessage(alt_text="hello", contents=a) line_bot_api.reply_message(event.reply_token, message) elif text == '/list_barang': req = requests.get( 'https://server-buychat.herokuapp.com/product_category') response = json.loads(req.text) items = [] for category in response['data']: postdata = { "action": "search_product", "product_category_id": category['Id'] } items.append( QuickReplyButton(action=PostbackAction( label=category['Product_category_name'], data=json.dumps(postdata)))) line_bot_api.reply_message( event.reply_token, TextSendMessage(text='Ada %s Jenis Barang Yang Tersedia' % (response['count']), quick_reply=QuickReply(items=items))) else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text))
def handle_text_message(event): text = (event.message.text).lower() if text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Display name: ' + profile.display_name), TextSendMessage(text='Status message: ' + profile.status_message), TextSendMessage(text='Picture: ' + profile.picture_url) ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Bot can't use profile API without user ID")) elif text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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")) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'navigation': buttons_template = ButtonsTemplate( title='Navigation Bot vers.1', text='Hello, ada yang bisa saya bantu...?', actions=[ MessageAction(label='Info Grapari', text='cari info Grapari'), URIAction(label='About Dev.', uri='http://line.me/ti/p/~primaananda_') ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'cari info grapari' or text == 'cari grapari' or text == 'grapari': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='Daftar grapari wilayah Denpasar', title='Denpasar', actions=[ MessageAction(label='Grapari Teuku Umar', text='grapari teuku umar'), MessageAction(label='grapari renon', text='grapari renon') ]), CarouselColumn(text='Daftar grapari wilayah Bangli', title='Bangli', actions=[ PostbackAction( label='Status Grapari', data='tidak terdapat Grapari di Bangli', text=' '), MessageAction(label=' ', text=' ') ]), CarouselColumn(text='Daftar grapari wilayah Buleleng', title='Buleleng', actions=[ MessageAction(label='grapari Buleleng', text='grapari buleleng'), MessageAction(label=' ', text=' ') ]), CarouselColumn(text='Daftar grapari wilayah Gianyar', title='Gianyar', actions=[ MessageAction(label='grapari Gianyar', text='grapari gianyar'), MessageAction(label=' ', text=' ') ]), CarouselColumn(text='Daftar grapari wilayah Jembrana', title='Jembrana', actions=[ MessageAction(label='graPARI Negara', text='grapari negara'), MessageAction(label=' ', text=' ') ]), CarouselColumn(text='Daftar grapari wilayah Karangasem', title='Karangasem', actions=[ MessageAction(label='graPARI Karangasem', text='grapari karangasem'), MessageAction(label=' ', text=' ') ]), CarouselColumn(text='Daftar grapari wilayah Klungkung', title='Klungkung', actions=[ PostbackAction( label='Status Grapari', data='tidak terdapat Grapari di Klungkung', text=' '), MessageAction(label=' ', text=' ') ]), CarouselColumn(text='Daftar grapari wilayah Tabanan', title='Tabanan', actions=[ MessageAction(label='Grapari Tabanan', text='grapari tabanan'), MessageAction(label=' ', text=' ') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'alamat grapari renon': line_bot_api.reply_message(event.reply_token, [ LocationSendMessage( title='My GraPARI Denpasar Renon', address= 'Jl. Raya Puputan No.33, Panjer, Denpasar Sel., Kota Denpasar, Bali 80234', latitude=-8.672262, longitude=115.228615) ]) elif text == 'alamat grapari teuku umar': line_bot_api.reply_message(event.reply_token, [ LocationSendMessage( title='My GraPARI Denpasar Teuku Umar', address= 'Jl. Teuku Umar No.6, Dauh Puri Klod, Denpasar Bar., Kota Denpasar, Bali 80114', latitude=-8.669041, longitude=115.214185) ]) elif text == 'alamat grapari buleleng': line_bot_api.reply_message(event.reply_token, [ LocationSendMessage( title='My GraPARI Buleleng', address= 'Jl. A. Yani No.72, Kaliuntu, Kec. Buleleng, Kabupaten Buleleng, Bali 81114', latitude=-8.111648, longitude=115.085734) ]) elif text == 'alamat grapari gianyar': line_bot_api.reply_message(event.reply_token, [ LocationSendMessage( title='My GraPARI Gianyar', address= 'Jl. A. Yani No.72, Kaliuntu, Kec. Buleleng, Kabupaten Buleleng, Bali 81114', latitude=-8.111648, longitude=115.085734) ]) elif text == 'alamat grapari mbg': line_bot_api.reply_message(event.reply_token, [ LocationSendMessage( title='My graPARI Mall Bali Galeria', address= 'JL. by Pass I Gusti Ngurah Rai , 80361 Denpasar , Bali, Kuta, Badung Regency, Bali 80361', latitude=-8.723316, longitude=115.184888) ]) elif text == 'alamat grapari karangasem': line_bot_api.reply_message(event.reply_token, [ LocationSendMessage( title='My graPARI Karangasem', address= 'Jl. PB. Sudirman 98 C, Amlapura, Kec. Karangasem, Kab. Karangasem, Bali 80811', latitude=-8.451645, longitude=115.603835) ]) elif text == 'alamat grapari negara': line_bot_api.reply_message(event.reply_token, [ LocationSendMessage( title='GraPARI Telkomsel Negara', address= 'Jl. Ngurah Rai, Pendem, Kec. Jembrana, Kabupaten Jembrana, Bali 82218', latitude=-8.360644, longitude=114.629995) ]) elif text == 'alamat grapari tabanan': line_bot_api.reply_message(event.reply_token, [ LocationSendMessage( title='GraPARI Telkomsel Tabanan', address= 'Jl. Dr. Ir. Soekarno, Banjar Anyar, Kediri, Kabupaten Tabanan, Bali 82121', latitude=-8.552806, longitude=115.135258) ]) elif text == 'grapari teuku umar': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://i.imgur.com/G18bDUi.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction( uri='https://i.imgur.com/G18bDUi.jpg', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='My GraPARI Teuku Umar', weight='bold', size='xl'), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent(text='Alamat', color='#aaaaaa', size='sm', flex=3), TextComponent( text= 'Jl. Teuku Umar No.6, Dauh Puri Klod, Denpasar Bar., Kota Denpasar, Bali 80114', wrap=True, color='#666666', size='sm', flex=5) ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent(text="Waktu Buka", color='#aaaaaa', size='sm', flex=3), TextComponent( text= "Senin, 08.00–17.00\nSelasa, 08.00–17.00\nRabu, 08.00–17.00\nKamis, 08.00–17.00\nJumat, 08.00–17.00\nSabtu, 08.00–12.00\nMinggu, Tutup", wrap=True, color='#666666', size='sm', flex=5, ), ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent(text='No. Telp', color='#aaaaaa', size='sm', flex=3), TextComponent( text="0811-3940-500", wrap=True, color='#666666', size='sm', flex=5, ), ], ), ], ) ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='primary', color='#00b300', height='sm', action=URIAction(label='Call', uri='tel:08113940500'), ), # websiteAction ButtonComponent(style='secondary', height='sm', action=PostbackAction( label='Alamat GraPARI', data='alamat grapari teuku umar', text='alamat grapari teuku umar')) ]), ) message = FlexSendMessage(alt_text="grapari teuku umar", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), CarouselColumn(text='hoge2', title='fuga2', actions=[ PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), CarouselColumn(text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'image_carousel': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction( label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'imagemap': pass elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, alamatAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # alamatAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'quick_reply': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply(items=[ QuickReplyButton( action=PostbackAction(label="label1", data="data1")), QuickReplyButton( action=MessageAction(label="label2", text="text2")), QuickReplyButton(action=DatetimePickerAction( label="label3", data="data3", mode="date")), QuickReplyButton(action=CameraAction(label="label4")), QuickReplyButton(action=CameraRollAction(label="label5")), QuickReplyButton(action=LocationAction(label="label6")), ]))) elif text == '.help': line_bot_api.reply_message( event.reply_token, TextSendMessage( text= 'Berikut merupakan command yang terdapat pada BOT ini: \n1. info_grapari\n2. profile\n3. bye\n4. confirm\n5. buttons\n6. carousel\n7 image\n8 image carousel\n9 imagemap\n10 flex\n11 quick_reply\n12 info\n13 about\n14 ip', quick_reply=QuickReply(items=[ QuickReplyButton( action=MessageAction(label="profile", text="profile")), QuickReplyButton( action=MessageAction(label="bye", text="bye")), QuickReplyButton( action=MessageAction(label="confirm", text="confirm")), QuickReplyButton( action=MessageAction(label="buttons", text="buttons")), QuickReplyButton(action=MessageAction(label="carousel", text="carousel")), QuickReplyButton( action=MessageAction(label="image", text="image")), QuickReplyButton(action=MessageAction( label="image carousel", text="image carousel")), QuickReplyButton(action=MessageAction(label="imagemap", text="imagemap")), QuickReplyButton( action=MessageAction(label="flex", text="flex")), QuickReplyButton(action=MessageAction(label="quick_reply", text="quick_reply")), QuickReplyButton( action=MessageAction(label="info", text="info")), QuickReplyButton( action=MessageAction(label="about", text="about")), QuickReplyButton( action=MessageAction(label="your ip", text="ip")) ]))) elif text == 'info': line_bot_api.reply_message(event.reply_token, TextSendMessage(text='')) elif text == 'about': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Ini merupakan bot yang masih dalam proses pengembangan.') ) elif text == 'ip': res = requests.get('https://ipinfo.io/') data = res.json() # your_ip = data['ip'] line_bot_api.reply_message( event.reply_token, TextSendMessage( text=('alamat IP : ' + data['ip'] + '\nhostname : ' + data['hostname'] + '\nKota : ' + data['city'] + '\nNegara : ' + data['country'] + '\nLokasi : ' + data['loc'] + '\nOrganisasi : ' + data['org']))) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Need help? click this button .help', quick_reply=QuickReply(items=[ QuickReplyButton( action=MessageAction(label="help", text=".help")) ])))
def handle_text_message(event): text = event.message.text if text == 'Hello': line_bot_api.reply_message(event.reply_token, TextSendMessage('Hi There!!')) elif text.lower() == 'getridch': carousel_template = CarouselTemplate(columns=[ CarouselColumn( text='What you can do', title='Seller', actions=[ CameraAction(label='Take a photo'), # CameraRollAction(label='Choose a photo'), ]), CarouselColumn( text='What you can do', title='Buyer', actions=[ PostbackAction(label='Get near by trash', data='getNearbyLocation', text='Show location'), # MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'menu': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply(items=[ QuickReplyButton(action=PostbackAction(label="getridch", data="getridch")), QuickReplyButton(action=CameraAction(label="Camera")), QuickReplyButton(action=CameraRollAction( label="Camera Roll")), QuickReplyButton(action=LocationAction(label="Location")), QuickReplyButton(action=DatetimePickerAction( label="Date", data="data3", mode="date")), ]))) elif text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message( event.reply_token, TextSendMessage(text='Display name: ' + profile.user_id)) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Bot can't use profile API without user ID")) elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!') ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'list': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='What you can do', title='Seller', actions=[ CameraAction(label='Take a photo'), PostbackAction(label='ping', data='ping') ]), CarouselColumn(text='Options', title='Buyer', actions=[ PostbackAction(label='Test ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'KBTG': confirm_template = ConfirmTemplate(text='Confirm Address : KBTG ?', actions=[ PostbackAction( label='Confirm', data='cfaddress'), PostbackAction(label='cancel', data='getridch', text='cancel'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message)
def handle_text_message(event): text = event.message.text user_dict = get_user_identity(event.source.user_id) if user_dict['time'] > 10800: change_situation(event.source.user_id, 0) user_dict['situation'] = 0 if text == 'getid': if isinstance(event.source, SourceUser): user_dict = get_user_identity(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='id: ' + str(user_dict['id'])), TextSendMessage(text='situation: ' + str(user_dict['situation'])), TextSendMessage(text='status: ' + str(user_dict['status'])), ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text="Cannot connect to the server")) elif user_dict['situation'] == 0: profile = line_bot_api.get_profile(event.source.user_id) change_situation(event.source.user_id, 1) temp_text = str(profile.display_name ) + 'さん初めまして、私はお料理お姉さんよ。もしかして、今晩のメニューに悩んでいるんじゃない?' confirm_template = ConfirmTemplate(text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif user_dict['situation'] == 1 and text == 'いいえ': change_situation(event.source.user_id, 0) line_bot_api.reply_message( event.reply_token, TextSendMessage(text="あら、そうなの。また料理に困ったら声をかけてね!")) elif user_dict['situation'] == 1 and text == 'はい': change_situation(event.source.user_id, 3) temp_text = 'じゃあ私があなたの気分からお料理を提案してあげるわ!今日はお肉の気分?' confirm_template = ConfirmTemplate(text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif user_dict['situation'] == 3 and text == 'いいえ': change_situation(event.source.user_id, 4) temp_text = 'じゃあ海鮮の気分?' confirm_template = ConfirmTemplate(text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif user_dict['situation'] == 3 and text == 'はい': change_situation(event.source.user_id, 5) temp_text = 'ちょっと凝った料理に挑戦してみる?' confirm_template = ConfirmTemplate(text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif user_dict['situation'] == 4 and text == 'いいえ': change_situation(event.source.user_id, 12) temp_text = 'あなたは今日はベジタリアンなのね!じゃあこのお肉を使わない豆腐ハンバーグはどうかな?' recipe_dict = get_recipe(6) img_url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/65/Tofu_Hamburg_steak_20141107.jpg/200px-Tofu_Hamburg_steak_20141107.jpg' buttons_template = ButtonsTemplate(thumbnail_image_url=img_url, title='豆腐ハンバーグ', text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, [ template_message, ]) elif user_dict['situation'] == 4 and text == 'はい': change_situation(event.source.user_id, 13) temp_text = 'じゃあこの「海鮮アボカド」を作ってみない?' recipe_dict = get_recipe(7) img_url = recipe_dict['img_url'] buttons_template = ButtonsTemplate(thumbnail_image_url=img_url, title='海鮮アボカド', text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, [ template_message, ]) elif user_dict['situation'] == 5 and text == 'いいえ': change_situation(event.source.user_id, 6) temp_text = 'がっつりしたものが食べたいの?' confirm_template = ConfirmTemplate(text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif user_dict['situation'] == 5 and text == 'はい': change_situation(event.source.user_id, 8) temp_text = 'じゃあこの「ビーフウェリントン」を作ってみない? とっても豪華なイギリスの肉料理よ!' buttons_template = ButtonsTemplate( thumbnail_image_url= 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/Beef_Wellington_-_Crosscut.jpg/800px-Beef_Wellington_-_Crosscut.jpg', title='ビーフウェリントン', text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, [ template_message, ]) elif user_dict['situation'] == 6 and text == 'いいえ': change_situation(event.source.user_id, 9) temp_text = 'じゃあこの「タコライス」はいかが?' buttons_template = ButtonsTemplate( thumbnail_image_url= 'https://upload.wikimedia.org/wikipedia/commons/4/45/Taco_Rice1.JPG', title='タコライス', text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, [ template_message, ]) elif user_dict['situation'] == 6 and text == 'はい': change_situation(event.source.user_id, 7) temp_text = 'じゃあこの「ビーフステーキ」がいいんじゃないかしら?' buttons_template = ButtonsTemplate( thumbnail_image_url= 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/150418_Awaji_beef_at_Sumoto_Hyogo_pref_Japan02s5.jpg/800px-150418_Awaji_beef_at_Sumoto_Hyogo_pref_Japan02s5.jpg', title='ビーフステーキ', text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, [ template_message, ]) elif user_dict['situation'] == 7 and text == 'いいえ': change_situation(event.source.user_id, 0) line_bot_api.reply_message( event.reply_token, TextSendMessage(text="う〜ん、難しい子ねえ。また気が向いたら話しかけるのよ!")) elif user_dict['situation'] == 7 and text == 'はい': change_situation(event.source.user_id, 11) recipe_dict = get_recipe(4) temp_text = recipe_dict['recipe_text'] line_bot_api.reply_message(event.reply_token, [ TextSendMessage( text="やっぱりステーキだよね!じゃあこのレシピにしたがって作ってみるのよ!できたら写真を送ってね〜"), TextSendMessage(text=temp_text), ]) elif user_dict['situation'] == 8 and text == 'いいえ': change_situation(event.source.user_id, 0) line_bot_api.reply_message(event.reply_token, TextSendMessage(text="あら、残念。じゃあまた今度ね!")) elif user_dict['situation'] == 8 and text == 'はい': change_situation(event.source.user_id, 11) recipe_dict = get_recipe(2) temp_text = recipe_dict['recipe_text'] line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text="やった〜!じゃあこのレシピにしたがって作ってみるのよ!できたら写真を送ってね〜"), TextSendMessage(text=temp_text), ]) elif user_dict['situation'] == 9 and text == 'いいえ': change_situation(event.source.user_id, 10) temp_text = 'それなら「青椒肉絲」ならどう?' buttons_template = ButtonsTemplate( thumbnail_image_url= 'https://upload.wikimedia.org/wikipedia/commons/9/9d/Pepper_steak.jpg', title='青椒肉絲', text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, [ template_message, ]) elif user_dict['situation'] == 9 and text == 'はい': change_situation(event.source.user_id, 11) recipe_dict = get_recipe(3) temp_text = recipe_dict['recipe_text'] line_bot_api.reply_message(event.reply_token, [ TextSendMessage( text="そうこなくっちゃ!じゃあこのレシピにしたがって作ってみるのよ!できたら写真を送ってね〜"), TextSendMessage(text=temp_text), ]) elif user_dict['situation'] == 10 and text == 'いいえ': change_situation(event.source.user_id, 0) line_bot_api.reply_message( event.reply_token, TextSendMessage(text="う〜ん、難しい子ねえ。また気が向いたら話しかけるのよ!")) elif user_dict['situation'] == 10 and text == 'はい': change_situation(event.source.user_id, 11) recipe_dict = get_recipe(5) temp_text = recipe_dict['recipe_text'] line_bot_api.reply_message(event.reply_token, [ TextSendMessage( text="今日は中華に挑戦よ!じゃあこのレシピにしたがって作ってみるのよ!できたら写真を送ってね〜"), TextSendMessage(text=temp_text), ]) elif user_dict['situation'] == 12 and text == 'いいえ': change_situation(event.source.user_id, 14) temp_text = 'じゃあこのナスとチーズのベジタリアン料理でどうだ〜!!' recipe_dict = get_recipe(8) img_url = recipe_dict['img_url'] buttons_template = ButtonsTemplate(thumbnail_image_url=img_url, title='ナスとチーズのベジタリアン', text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, [ template_message, ]) elif user_dict['situation'] == 12 and text == 'はい': change_situation(event.source.user_id, 11) recipe_dict = get_recipe(6) temp_text = recipe_dict['recipe_text'] line_bot_api.reply_message(event.reply_token, [ TextSendMessage( text="そうこなくっちゃ! じゃあこのレシピにしたがって作ってみるのよ。完成したら写真を送ってね〜"), TextSendMessage(text=temp_text), ]) elif user_dict['situation'] == 13 and text == 'いいえ': change_situation(event.source.user_id, 15) temp_text = 'じゃあこの「ガーリックシュリンプ」ならどうだ!!' recipe_dict = get_recipe(9) img_url = recipe_dict['img_url'] buttons_template = ButtonsTemplate(thumbnail_image_url=img_url, title='ガーリックシュリンプ', text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, [ template_message, ]) elif user_dict['situation'] == 13 and text == 'はい': change_situation(event.source.user_id, 11) recipe_dict = get_recipe(7) temp_text = recipe_dict['recipe_text'] line_bot_api.reply_message(event.reply_token, [ TextSendMessage( text="そうこなくっちゃ!じゃあこのレシピにしたがって作ってみるのよ!完成したら写真を送ってね〜"), TextSendMessage(text=temp_text), ]) elif user_dict['situation'] == 14 and text == 'いいえ': change_situation(event.source.user_id, 0) line_bot_api.reply_message( event.reply_token, TextSendMessage(text="もう! 難しいんだから! 勝手にしなさい(≧ヘ≦ )プイッ!!")) elif user_dict['situation'] == 14 and text == 'はい': change_situation(event.source.user_id, 11) recipe_dict = get_recipe(8) temp_text = recipe_dict['recipe_text'] line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text="じゃあこのレシピにしたがって作ってね!完成したら写真を送るのよ〜"), TextSendMessage(text=temp_text), ]) elif user_dict['situation'] == 15 and text == 'いいえ': change_situation(event.source.user_id, 0) line_bot_api.reply_message( event.reply_token, TextSendMessage(text="もう! 難しいんだから! 勝手にしなさい(≧ヘ≦ )プイッ!!")) elif user_dict['situation'] == 15 and text == 'はい': change_situation(event.source.user_id, 11) recipe_dict = get_recipe(9) temp_text = recipe_dict['recipe_text'] line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text="じゃあこのレシピにしたがって作ってね!完成したら写真を送るのよ〜"), TextSendMessage(text=temp_text), ]) elif user_dict['situation'] == 11: temp_text = 'できたら写真を送ってね〜' line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text=temp_text), ]) elif user_dict['situation'] >= 1 and user_dict['situation'] <= 15: temp_text = '「はい」か「いいえ」で答えてね!' confirm_template = ConfirmTemplate(text=temp_text, actions=[ MessageAction(label='はい', text='はい'), MessageAction(label='いいえ', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Display name: ' + profile.display_name), TextSendMessage(text='Status message: ' + str(profile.status_message)) ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Bot can't use profile API without user ID")) elif text == 'quota': quota = line_bot_api.get_message_quota() line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='type: ' + quota.type), TextSendMessage(text='value: ' + str(quota.value)) ]) elif text == 'quota_consumption': quota_consumption = line_bot_api.get_message_quota_consumption() line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='total usage: ' + str(quota_consumption.total_usage)), ]) elif text == 'push': line_bot_api.push_message(event.source.user_id, [ TextSendMessage(text='PUSH!'), ]) elif text == 'multicast': line_bot_api.multicast([event.source.user_id], [ TextSendMessage(text='THIS IS A MULTICAST MESSAGE'), ]) elif text == 'broadcast': line_bot_api.broadcast([ TextSendMessage(text='THIS IS A BROADCAST MESSAGE'), ]) elif text.startswith('broadcast '): # broadcast 20190505 date = text.split(' ')[1] print("Getting broadcast result: " + date) result = line_bot_api.get_message_delivery_broadcast(date) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Number of sent broadcast messages: ' + date), TextSendMessage(text='status: ' + str(result.status)), TextSendMessage(text='success: ' + str(result.success)), ]) elif text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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")) elif text == 'image': url = request.url_root + '/static/logo.png' app.logger.info("url=" + url) line_bot_api.reply_message(event.reply_token, ImageSendMessage(url, url)) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), CarouselColumn(text='hoge2', title='fuga2', actions=[ PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'image_carousel': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction( label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'imagemap': pass elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'flex_update_1': bubble_string = """ { "type": "bubble", "body": { "type": "box", "layout": "vertical", "contents": [ { "type": "image", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/flexsnapshot/clip/clip3.jpg", "position": "relative", "size": "full", "aspectMode": "cover", "aspectRatio": "1:1", "gravity": "center" }, { "type": "box", "layout": "horizontal", "contents": [ { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "Brown Hotel", "weight": "bold", "size": "xl", "color": "#ffffff" }, { "type": "box", "layout": "baseline", "margin": "md", "contents": [ { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png" }, { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png" }, { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png" }, { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png" }, { "type": "icon", "size": "sm", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gray_star_28.png" }, { "type": "text", "text": "4.0", "size": "sm", "color": "#d6d6d6", "margin": "md", "flex": 0 } ] } ] }, { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "¥62,000", "color": "#a9a9a9", "decoration": "line-through", "align": "end" }, { "type": "text", "text": "¥42,000", "color": "#ebebeb", "size": "xl", "align": "end" } ] } ], "position": "absolute", "offsetBottom": "0px", "offsetStart": "0px", "offsetEnd": "0px", "backgroundColor": "#00000099", "paddingAll": "20px" }, { "type": "box", "layout": "vertical", "contents": [ { "type": "text", "text": "SALE", "color": "#ffffff" } ], "position": "absolute", "backgroundColor": "#ff2600", "cornerRadius": "20px", "paddingAll": "5px", "offsetTop": "10px", "offsetEnd": "10px", "paddingStart": "10px", "paddingEnd": "10px" } ], "paddingAll": "0px" } } """ message = FlexSendMessage(alt_text="hello", contents=json.loads(bubble_string)) line_bot_api.reply_message(event.reply_token, message) elif text == 'quick_reply': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply(items=[ QuickReplyButton( action=PostbackAction(label="label1", data="data1")), QuickReplyButton( action=MessageAction(label="label2", text="text2")), QuickReplyButton(action=DatetimePickerAction( label="label3", data="data3", mode="date")), QuickReplyButton(action=CameraAction(label="label4")), QuickReplyButton(action=CameraRollAction(label="label5")), QuickReplyButton(action=LocationAction(label="label6")), ]))) elif text == 'link_token' and isinstance(event.source, SourceUser): link_token_response = line_bot_api.issue_link_token( event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='link_token: ' + link_token_response.link_token) ]) elif text == 'insight_message_delivery': today = datetime.date.today().strftime("%Y%m%d") response = line_bot_api.get_insight_message_delivery(today) if response.status == 'ready': messages = [ TextSendMessage(text='broadcast: ' + str(response.broadcast)), TextSendMessage(text='targeting: ' + str(response.targeting)), ] else: messages = [TextSendMessage(text='status: ' + response.status)] line_bot_api.reply_message(event.reply_token, messages) elif text == 'insight_followers': today = datetime.date.today().strftime("%Y%m%d") response = line_bot_api.get_insight_followers(today) if response.status == 'ready': messages = [ TextSendMessage(text='followers: ' + str(response.followers)), TextSendMessage(text='targetedReaches: ' + str(response.targeted_reaches)), TextSendMessage(text='blocks: ' + str(response.blocks)), ] else: messages = [TextSendMessage(text='status: ' + response.status)] line_bot_api.reply_message(event.reply_token, messages) elif text == 'insight_demographic': response = line_bot_api.get_insight_demographic() if response.available: messages = [ "{gender}: {percentage}".format(gender=it.gender, percentage=it.percentage) for it in response.genders ] else: messages = [TextSendMessage(text='available: false')] line_bot_api.reply_message(event.reply_token, messages) else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text))
def unikanews(event): ENDPOINT = "http://news.unika.ac.id/?s=" ENDPOINT_IKOM = "http://news.unika.ac.id/?s=ikom" url = urlreq.urlopen( urlreq.Request( ENDPOINT, headers={ 'User-Agent': "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)" })) udict = url.read().decode('utf-8') rawlink = re.findall('<h6><a href="(.*?)"', udict, re.DOTALL | re.IGNORECASE) my_path = "/var/www/html/vanikabot/imagenews" columns = [] for i in range(0, 4): url1 = urlreq.urlopen( urlreq.Request( rawlink[i], headers={ 'User-Agent': "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)" })) udict1 = url1.read().decode('utf-8') rawtitels = re.findall( '<h6><a href="' + rawlink[i] + '" rel="bookmark" title="(.*?)"', udict, re.DOTALL | re.IGNORECASE) rawpublikasi = re.findall('<div class="meta">(.*?)<a', udict, re.DOTALL | re.IGNORECASE) publishDate_raw = rawpublikasi[0].replace( "Publikasi tanggal ", "").replace(" di ", "").split(" ") publishDate = publishDate_raw[1].replace( ",", "") + " " + publishDate_raw[0] + " " + publishDate_raw[2] rawdes = re.findall('<p>(.*?)<a', udict, re.DOTALL | re.IGNORECASE) rawimg = re.findall( 'src="http://news.unika.ac.id/wp-content/uploads/(.*?)"', udict1, re.DOTALL | re.IGNORECASE) try: if ('.jpg' in rawimg[0]) or ('.png' in rawimg[0]): linkimg = [ "http://news.unika.ac.id/wp-content/uploads/" + rawimg[0] ] else: linkimg = [ "https://vanika.tru.io/vanikabot/imagenews/tandatanya.jpg" ] except: linkimg = [ "https://vanika.tru.io/vanikabot/imagenews/tandatanya.jpg" ] imagename = str(linkimg[0].replace( "http://news.unika.ac.id/wp-content/uploads/", "").replace("https://vanika.tru.io/vanikabot/imagenews/", "").replace(".jpg", "").replace(".png", "")) urllib.request.urlretrieve( linkimg[0], os.path.join(my_path, os.path.basename(imagename + ".png"))) carousel_column = BubbleContainer(body=BoxComponent( layout='vertical', padding_all='0px', contents=[ ImageComponent( url="https://vanika.tru.io/vanikabot/imagenews/" + imagename + ".png", size='full', aspect_ratio='2:3', aspect_mode='cover', gravity='top', ), BoxComponent( layout='vertical', contents=[ BoxComponent( layout='vertical', contents=[ #titile TextComponent(text=rawtitels[0], weight='bold', wrap=True, color='#ffffff', size='md'), ], ), BoxComponent( layout='baseline', contents=[ # info TextComponent(text=rawdes[i][:50] + " ...", color='#ebebeb', size='xs', gravity='bottom', flex=0), ], spacing='lg', ), BoxComponent( layout='vertical', contents=[ FillerComponent(), BoxComponent( layout='baseline', contents=[ FillerComponent(), IconComponent( url= 'https://vanika.tru.io/vanikabot/icon/discover.png' ), TextComponent(text='Selengkapnya', color='#ffffff', flex=0, offset_top='-2px'), FillerComponent(), ], spacing='sm', ), FillerComponent(), ], border_width='1px', corner_radius='4px', spacing='sm', border_color='#ffffff', margin='xxl', height='40px', action=URIAction(uri=rawlink[i], label='picture')), ], position='absolute', offset_bottom='0px', offset_start='0px', offset_end='0px', background_color='#11BBFFaa', padding_all='20px', padding_top='18px', ), BoxComponent( layout='vertical', contents=[ TextComponent(text='UNIKA TODAY', align='start', color='#ffffff', size='md', offset_top='3px', weight='bold', style='normal'), TextComponent( text=publishDate, color='#ffffff', size='sm'), ], position='absolute', offset_top='18px', offset_start='18px', height='100px', width='150px', ), ], )) columns.append(carousel_column) carousel_template = CarouselContainer(contents=columns) template_message = FlexSendMessage(alt_text='UNIKA NEWS', contents=carousel_template) line_bot_api.reply_message(event.reply_token, [template_message])
def handle_text_message(event): text = event.message.text if text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Display name: ' + profile.display_name), TextSendMessage(text='Status message: ' + profile.status_message) ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Bot can't use profile API without user ID")) if text == 'how': how = 'Available Commands \n /guide' line_bot_api.reply_message(event.reply_token, TextSendMessage(text=how)) elif text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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")) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn( thumbnail_image_url= 'https://1.bp.blogspot.com/-NRqCUkKHH-Q/VW6EUFzLiII/AAAAAAAAUNQ/DlcsA2ETA6k/s640/Brown%2BLINE%2Ba.jpe', image_background_color='#FFFFFF', text= 'Enjoy delicious food with a great atmoshpere at our place', title='Brown Cafe', actions=[ URIAction(label='Reserve', uri='https://line.me'), PostbackAction(label='Call', data='ping') ]), CarouselColumn( thumbnail_image_url= 'https://1.bp.blogspot.com/-NRqCUkKHH-Q/VW6EUFzLiII/AAAAAAAAUNQ/DlcsA2ETA6k/s640/Brown%2BLINE%2Ba.jpe', image_background_color='#FFFFFF', text='hoge2', title='fuga2', actions=[ PostbackAction( label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == '/guide': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url= 'https://image.flaticon.com/icons/png/512/229/229374.png', action=PostbackAction(label='Restauran', data='search_restaurant', text='Cari Restauran')), ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction( label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'imagemap': pass elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'quick_reply': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply(items=[ QuickReplyButton( action=PostbackAction(label="label1", data="data1")), QuickReplyButton( action=MessageAction(label="label2", text="text2")), QuickReplyButton(action=DatetimePickerAction( label="label3", data="data3", mode="date")), QuickReplyButton(action=CameraAction(label="label4")), QuickReplyButton(action=CameraRollAction(label="label5")), QuickReplyButton(action=LocationAction(label="label6")), ]))) elif text == 'lokasi': line_bot_api.reply_message( event.reply_token, LocationMessage( text='Lokasi Kamu', title='Lokasi Kamu', type='location', address= 'Pasaraya Blok M Gedung B Lt. 6, Jalan Iskandarsyah II No.7', latitude='-6.2439966', longitude='106.8033883')) else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text))
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 == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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='Culum 1', text='/aditmadzs'), MessageTemplateAction(label='CULUM 2', text='/aditmadzs'), MessageTemplateAction(label='CULUM 3', text='/aditmadzs') ])) line_bot_api.reply_message(event.reply_token, buttons_template) #=====[ CAROUSEL MESSAGE ]========== elif text == '/carousel': message = TemplateSendMessage( alt_text='OTHER MENU', template=CarouselTemplate(columns=[ CarouselColumn(title='ADD ME', text='Contact Aditmadzs', actions=[ URITemplateAction( label='>TAP HERE<', uri='https://line.me/ti/p/~adit_cmct') ]), CarouselColumn(title='Instagram', text='FIND ME ON INSTAGRAM', actions=[ URITemplateAction( label='>TAP HERE!<', uri='http://line.me/ti/p/~adit_cmct') ]) ])) 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/~adit_cmct', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Aditmadzs', 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='Aditmadzs', uri="https://line.me/ti/p/~adit_cmct")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message)
def handle_text_message(event): text = event.message.text # 送られてきた言葉が植物の名前だった場合は、それをキャッシュし「なに?」と返す if user_data.plant_exists(text): current_plant = text line_bot_api.reply_message(event.reply_token, TextSendMessage(text='なに?')) if text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='なまえ: ' + profile.display_name), TextSendMessage(text='一言: ' + profile.status_message) ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text="「ユーザIDがないとこのコマンドは使えません」")) elif text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='またね、今までありがとう')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='またね、今までありがとう')) line_bot_api.leave_room(event.source.room_id) else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text="ぼくはここから動けないよ...")) elif text == 'confirm': confirm_template = ConfirmTemplate(text='これでいい?', actions=[ MessageAction(label='Yes', text='はい!'), MessageAction(label='No', text='いいえ'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), CarouselColumn(text='hoge2', title='fuga2', actions=[ PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'image_carousel': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction( label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'imagemap': pass elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'quick_reply': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply(items=[ QuickReplyButton( action=PostbackAction(label="label1", data="data1")), QuickReplyButton( action=MessageAction(label="label2", text="text2")), QuickReplyButton(action=DatetimePickerAction( label="label3", data="data3", mode="date")), QuickReplyButton(action=CameraAction(label="label4")), QuickReplyButton(action=CameraRollAction(label="label5")), QuickReplyButton(action=LocationAction(label="label6")), ]))) # ユーザからビーコンの設定を行う elif text == 'beacon': BeaconWhisperEvent(event.reply_token, line_bot_api, user_data).configBeaconMsg() # 植物を削除するときの命令 elif text == 'remove' or text == 'delete': if current_plant is not None: confirm_template = ConfirmTemplate( text=current_plant + "の情報を削除します\n本当によろしいですか?\n", actions=[ PostbackAction(label='Yes', data='delete_plant ' + current_plant, displayText='はい'), PostbackAction(label='No', data='delete_plant_cancel ' + current_plant, displayText='いいえ'), ]) else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text='植物が選択されていません')) elif text == 'disconnect' and current_plant is not None: plant_animator.disconnect() line_bot_api.reply_message(event.reply_token, TextMessage(text=current_plant + ":またね")) # 植物情報(plant)のアプデをかける elif text == 'update': plant_animator.update() if current_plant is None: line_bot_api.reply_message(event.reply_token, TextSendMessage(text='どの植物に呼びかけますか?')) # text.split()[0] in (create, register) elif text.split()[0] in ('create', 'register'): plant_animator.register_plant(text.split[1]) line_bot_api.reply_message(event.reply_token, TextSendMessage(text='植物の名前を決めてあげてください!')) # この処理は工事中↑ # 方針としては一番最後にelse: で入れて、textを"create hoge"みたいに入れてもらってsplitして入れればい何とかなる(きもいけど) else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text))
def handle_text_message(event): text = event.message.text if text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Display name: ' + profile.display_name), TextSendMessage(text='Status message: ' + profile.status_message), TextSendMessage(text='user_id: ' + profile.user_id), TextSendMessage(text='test picture url: ' + profile.picture_url) ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Bot can't use profile API without user ID")) elif text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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")) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'Bot': confirm_template = ConfirmTemplate( text='Photo of Miyuu or Osaka trip?', actions=[ MessageAction(label='Miyuu !', text='Miyuu'), MessageAction(label='Osaka Trip !', text='Osaka'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), CarouselColumn(text='hoge2', title='fuga2', actions=[ PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'Osaka': carousel_template = CarouselTemplate(columns=[ CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/osaka1024.jpg', title='Osaka1', text='Cooool', actions=[ PostbackAction( label='Colorful town', text='Cooool', data='Cooool') ]), CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/osaka2-1024.jpg', title='Osaka2', text='Women power', actions=[ PostbackAction( label='Castle', text='Women power', data='Women power') ]), CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/osaka3-1024.jpg', title='Osaka3', text='Where is this?', actions=[ PostbackAction(label='Some place !!', text='Where is this?', data='Where is this?') ]), CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/osaka4-1024.jpg', title='Osaka4', text='Nice Castle', actions=[ PostbackAction(label='Another GirlPow', text='Nice Castle', data='Nice Castle') ]), CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/osaka5-1024.jpg', title='Osaka5', text='Full face !!', actions=[ PostbackAction(label='Osaka member', text='Full face !!', data='Full face !!') ]), CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/osaka6-1024.jpg', title='Osaka6', text='Tired ??', actions=[ PostbackAction( label='Mom Power!!', text='Tired ??', data='Tired ??') ]) ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'Miyuu': carousel_template = CarouselTemplate(columns=[ CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/miyuu1024-1.jpg', text='Miyuu#1', actions=[ PostbackAction( label='Best Friend', text='Elvis', data='Elvis') ]), CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/miyuu1024-2.jpg', text='Miyuu#2', actions=[ PostbackAction(label='GreatWolfLodge', text='Water park', data='Water park') ]), CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/miyuu1024-3.jpg', text='Miyuu#3', actions=[ PostbackAction( label='Miyuu Cycle', text='Arcade', data='Arcade') ]), CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/miyuu1024-4.jpg', text='Miyuu#4', actions=[ PostbackAction( label='Bath Time', text='Love It', data='Love It') ]), CarouselColumn( thumbnail_image_url= 'https://s3-us-west-2.amazonaws.com/awsrobomakerhelloworld-154344673743-bundlesbucket-1n2aine7xqbt8/image/miyuu1024-5.jpg', text='Miyuu#5', actions=[ PostbackAction( label='The Gang', text='The Gang', data='The Gang') ]) ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'image_carousel': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction( label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'Where is mom': location_message = LocationSendMessage(type='Where is Mom?', title='Mom home', address='Mom', latitude=13.799750, longitude=100.641546) line_bot_api.reply_message(event.reply_token, location_message) elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'quick_reply': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply(items=[ QuickReplyButton( action=PostbackAction(label="label1", data="data1")), QuickReplyButton( action=MessageAction(label="label2", text="text2")), QuickReplyButton(action=DatetimePickerAction( label="label3", data="data3", mode="date")), QuickReplyButton(action=CameraAction(label="label4")), QuickReplyButton(action=CameraRollAction(label="label5")), QuickReplyButton(action=LocationAction(label="label6")), ]))) else: pass
def handle_text_message(event): text = event.message.text if text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Display name: ' + profile.display_name), TextSendMessage(text='Status message: ' + profile.status_message) ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Bot can't use profile API without user ID")) elif text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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")) elif text == 'image': url = request.url_root + '/static/logo.png' app.logger.info("url=" + url) line_bot_api.reply_message(event.reply_token, ImageSendMessage(url, url)) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), CarouselColumn(text='hoge2', title='fuga2', actions=[ PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'image_carousel': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction( label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'imagemap': pass elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'quick_reply': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply(items=[ QuickReplyButton( action=PostbackAction(label="label1", data="data1")), QuickReplyButton( action=MessageAction(label="label2", text="text2")), QuickReplyButton(action=DatetimePickerAction( label="label3", data="data3", mode="date")), QuickReplyButton(action=CameraAction(label="label4")), QuickReplyButton(action=CameraRollAction(label="label5")), QuickReplyButton(action=LocationAction(label="label6")), ]))) else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text))
def sendFlex(event): #彈性配置 try: bubble = BubbleContainer( direction='ltr', #項目由左向右排列 header=BoxComponent( #標題 layout='vertical', contents=[ TextComponent(text='冰火飲料', weight='bold', size='xxl'), ] ), hero=ImageComponent( #主圖片 url='https://i.imgur.com/3sBRh08.jpg', size='full', aspect_ratio='792:555', #長寬比例 aspect_mode='cover', ), body=BoxComponent( #主要內容 layout='vertical', contents=[ TextComponent(text='評價', size='md'), BoxComponent( layout='baseline', #水平排列 margin='md', contents=[ IconComponent(size='lg', url='https://i.imgur.com/GsWCrIx.png'), TextComponent(text='25 ', size='sm', color='#999999', flex=0), IconComponent(size='lg', url='https://i.imgur.com/sJPhtB3.png'), TextComponent(text='14', size='sm', color='#999999', flex=0), ] ), BoxComponent( layout='vertical', margin='lg', contents=[ BoxComponent( layout='baseline', contents=[ TextComponent(text='營業地址:', color='#aaaaaa', size='sm', flex=2), TextComponent(text='台北市信義路14號', color='#666666', size='sm', flex=5) ], ), SeparatorComponent(color='#0000FF'), BoxComponent( layout='baseline', contents=[ TextComponent(text='營業時間:', color='#aaaaaa', size='sm', flex=2), TextComponent(text="10:00 - 23:00", color='#666666', size='sm', flex=5), ], ), ], ), BoxComponent( layout='horizontal', margin='xxl', contents=[ ButtonComponent( style='primary', height='sm', action=URIAction(label='電話聯絡', uri='tel:0987654321'), ), ButtonComponent( style='secondary', height='sm', action=URIAction(label='查看網頁', uri="http://www.e-happy.com.tw") ) ] ) ], ), footer=BoxComponent( #底部版權宣告 layout='vertical', contents=[ TextComponent(text='Copyright@ehappy studio 2019', color='#888888', size='sm', align='center'), ] ), ) message = FlexSendMessage(alt_text="彈性配置範例", contents=bubble) line_bot_api.reply_message(event.reply_token,message) except: line_bot_api.reply_message(event.reply_token,TextSendMessage(text='發生錯誤!'))
def handle_text_message(event): text = event.message.text textlow = event.message.text.lower() #EDIT START HERE #YOU CAN EDIT WITH ELIF if ("!menu" in text) or ("menu" in textlow): carousel_template = CarouselTemplate(columns=[ CarouselColumn( text='Konsultasi dengan admin kami', title='Konsultasi', thumbnail_image_url= 'https://cdn2.tstatic.net/jateng/foto/bank/images/tugu-muda-semarang-ok.jpg', actions=[ URIAction(label='Line@', uri='https://line.me/R/ti/p/%40nut4837y'), ]), CarouselColumn( text='Informasi mengenai Alfalink', title='Info', thumbnail_image_url= 'https://cdn2.tstatic.net/jateng/foto/bank/images/tugu-muda-semarang-ok.jpg', actions=[ MessageAction(label='Detail', text='Info'), ]) ]) template_message = TemplateSendMessage(alt_text='Info', template=carousel_template) line_bot_api.reply_message( event.reply_token, [TextSendMessage(text='Info'), template_message]) elif ("!info" in text) or ("info" in textlow): carousel_template = CarouselTemplate(columns=[ CarouselColumn( text='Information About Alfalink', title='Informasi Alfalink', thumbnail_image_url= 'https://cdn2.tstatic.net/jateng/foto/bank/images/tugu-muda-semarang-ok.jpg', actions=[ URIAction(label='About Us', uri='http://alfalink.net/alfalink-profile/'), URIAction(label='Career', uri='http://alfalink.net/career/'), ]) ]) template_message = TemplateSendMessage(alt_text='Menu', template=carousel_template) line_bot_api.reply_message( event.reply_token, [TextSendMessage(text="Info Alfalink"), template_message]) ##Apabila user memilih pilihan tidak pada bantuan elif ("tidak" in textlow): if isinstance(event.source, SourceUser): line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text="Terimakasih sampai jumpa kembali"), ]) #END OF EDIT ########################################################### #DEFAULT CODE elif text == 'profile': if isinstance(event.source, SourceUser): profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Display name: ' + profile.display_name), TextSendMessage(text='Status message: ' + str(profile.status_message)) ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Bot can't use profile API without user ID")) elif text == 'quota': quota = line_bot_api.get_message_quota() line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='type: ' + quota.type), TextSendMessage(text='value: ' + str(quota.value)) ]) elif text == 'quota_consumption': quota_consumption = line_bot_api.get_message_quota_consumption() line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='total usage: ' + str(quota_consumption.total_usage)), ]) elif text == 'push': line_bot_api.push_message(event.source.user_id, [ TextSendMessage(text='PUSH!'), ]) elif text == 'multicast': line_bot_api.multicast([event.source.user_id], [ TextSendMessage(text='THIS IS A MULTICAST MESSAGE'), ]) elif text == 'broadcast': line_bot_api.broadcast([ TextSendMessage(text='THIS IS A BROADCAST MESSAGE'), ]) elif text.startswith('broadcast '): # broadcast 20190505 date = text.split(' ')[1] print("Getting broadcast result: " + date) result = line_bot_api.get_message_delivery_broadcast(date) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Number of sent broadcast messages: ' + date), TextSendMessage(text='status: ' + str(result.status)), TextSendMessage(text='success: ' + str(result.success)), ]) elif text == 'bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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")) elif text == 'image': url = request.url_root + '/static/logo.png' app.logger.info("url=" + url) line_bot_api.reply_message(event.reply_token, ImageSendMessage(url, url)) elif text == 'confirm': confirm_template = ConfirmTemplate(text='Do it?', actions=[ MessageAction(label='Yes', text='Yes!'), MessageAction(label='No', text='No!'), ]) template_message = TemplateSendMessage(alt_text='Confirm alt text', template=confirm_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) template_message = TemplateSendMessage(alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'carousel': carousel_template = CarouselTemplate(columns=[ CarouselColumn(text='hoge1', title='fuga1', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping') ]), CarouselColumn(text='hoge2', title='fuga2', actions=[ PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]), ]) template_message = TemplateSendMessage(alt_text='Carousel alt text', template=carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'image_carousel': image_carousel_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn( image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction( label='date', data='date_postback', mode='date')) ]) template_message = TemplateSendMessage( alt_text='ImageCarousel alt text', template=image_carousel_template) line_bot_api.reply_message(event.reply_token, template_message) elif text == 'imagemap': pass elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message) elif text == 'quick_reply': line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Quick reply', quick_reply=QuickReply(items=[ QuickReplyButton( action=PostbackAction(label="label1", data="data1")), QuickReplyButton( action=MessageAction(label="label2", text="text2")), QuickReplyButton(action=DatetimePickerAction( label="label3", data="data3", mode="date")), QuickReplyButton(action=CameraAction(label="label4")), QuickReplyButton(action=CameraRollAction(label="label5")), QuickReplyButton(action=LocationAction(label="label6")), ]))) elif text == 'link_token' and isinstance(event.source, SourceUser): link_token_response = line_bot_api.issue_link_token( event.source.user_id) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='link_token: ' + link_token_response.link_token) ]) elif text == 'insight_message_delivery': today = datetime.date.today().strftime("%Y%m%d") response = line_bot_api.get_insight_message_delivery(today) if response.status == 'ready': messages = [ TextSendMessage(text='broadcast: ' + str(response.broadcast)), TextSendMessage(text='targeting: ' + str(response.targeting)), ] else: messages = [TextSendMessage(text='status: ' + response.status)] line_bot_api.reply_message(event.reply_token, messages) elif text == 'insight_followers': today = datetime.date.today().strftime("%Y%m%d") response = line_bot_api.get_insight_followers(today) if response.status == 'ready': messages = [ TextSendMessage(text='followers: ' + str(response.followers)), TextSendMessage(text='targetedReaches: ' + str(response.targeted_reaches)), TextSendMessage(text='blocks: ' + str(response.blocks)), ] else: messages = [TextSendMessage(text='status: ' + response.status)] line_bot_api.reply_message(event.reply_token, messages) elif text == 'insight_demographic': response = line_bot_api.get_insight_demographic() if response.available: messages = [ "{gender}: {percentage}".format(gender=it.gender, percentage=it.percentage) for it in response.genders ] else: messages = [TextSendMessage(text='available: false')] line_bot_api.reply_message(event.reply_token, messages) else: line_bot_api.reply_message( event.reply_token, TextSendMessage( text='Ketik "Menu" untuk melihat menu.', quick_reply=QuickReply(items=[ QuickReplyButton( action=MessageAction(label="Menu", text="menu")), ])))
def handle2_message(event): if event.message.text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url='https://example.com/cafe.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://example.com', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', 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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent(style='link', height='sm', action=URIAction( label='WEBSITE', uri="https://example.com")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api2.reply_message(event.reply_token, message) elif event.message.text == 'flex2': jsonToDict = json.loads(jstr) bubble = BubbleContainer.new_from_json_dict(jsonToDict) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api2.reply_message(event.reply_token, message) else: message = TemplateSendMessage( alt_text='Carousel template', template=CarouselTemplate(columns=[ CarouselColumn( thumbnail_image_url= 'https://www.ultraegaming.com/wp-content/uploads/2017/10/%E7%99%BE%E5%AE%B6%E6%A8%82-1-2.jpg', title='莫地百家樂', text='歡迎使用本系統,請跟隨指示操作。', actions=[ PostbackAction(label='註冊會員', data='註冊'), PostbackAction(label='報牌通知設定', data='Confirm') ]), CarouselColumn( thumbnail_image_url= 'https://www.triplecrowncasinos.com/wp-content/uploads/2016/07/casinos-in-colorado.jpg', title='您的套路', text='您可以自訂套路,並且可設定最多五組。', actions=[ PostbackAction(label='套路清單', data='套路清單'), PostbackTemplateAction(label='套路設定教學', data='使用教學') ]) ])) line_bot_api2.reply_message(event.reply_token, message)
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 == 'Bye': if isinstance(event.source, SourceGroup): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) line_bot_api.leave_group(event.source.group_id) elif isinstance(event.source, SourceRoom): line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Leaving group')) 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='Culum 1', text='Kris'), MessageTemplateAction(label='CULUM 2', text='Kris2'), MessageTemplateAction( label='CULUM 3', text='Pasukan Kemeng') ])) line_bot_api.reply_message(event.reply_token, buttons_template) #=====[ CAROUSEL MESSAGE ]========== elif text == 'Carousel': message = TemplateSendMessage( alt_text='OTHER MENU', template=CarouselTemplate(columns=[ CarouselColumn(title='ADD ME', text='Contact Kris', actions=[ URITemplateAction( label='>TAP HERE<', uri='https://line.me/ti/p/~krissthea') ]), CarouselColumn(title='ADD ME', text='Contact Kris2', actions=[ URITemplateAction( label='>TAP HERE!<', uri='http://line.me/ti/p/~batara_dewa') ]) ])) line_bot_api.reply_message(event.reply_token, message) #=====[ FLEX MESSAGE ]========== elif text == 'Flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url= 'https://www.google.co.id/maps/place/Tasikmalaya,+Jawa+Barat/@-7.3599766,108.1627124,12z/data=!3m1!4b1!4m5!3m4!1s0x2e6f56e5924c576f:0x301e8f1fc2f2500!8m2!3d-7.3505808!4d108.2171633?hl=id', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri='http://line.me/ti/p/~batara_dewa', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Kris', 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='Kris', uri="https://line.me/ti/p/~batara_dewa")) ]), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message(event.reply_token, message)
def message_text(event): # check bot prefix if event.message.text.startswith(BOT_PREFIX): # seperate message contents as command and arguments message_body = event.message.text.strip()[1:].split() command = message_body[0] if(len(message_body) >= 2): arguments_list = message_body[1:] arguments_string = ' '.join(arguments_list) else: arguments_list = [] arguments_string = '' # echo command: reply arguments to user if command == 'echo': if(arguments_string != ''): line_bot_api.reply_message( event.reply_token, TextSendMessage(text=arguments_string) ) elif command == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='https://img.wongnai.com/p/1920x0/2017/12/30/19f2934940cf47669b2d1336feea0b97.jpg', size='full', aspect_ratio='4:3', aspect_mode='cover', action=URIAction(uri='https://github.com/miner46er/python-line-bot-sparta', label='label') ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Brown Cafe', weight='bold', size='xl'), # review BoxComponent( layout='baseline', margin='md', contents=[ IconComponent(size='sm', url='https://cdn2.iconfinder.com/data/icons/default-1/100/.svg-4-512.png'), IconComponent(size='sm', url='https://freeiconshop.com/wp-content/uploads/edd/star-curved-outline.png'), IconComponent(size='sm', url='https://cdn2.iconfinder.com/data/icons/default-1/100/.svg-4-512.png'), IconComponent(size='sm', url='https://cdn2.iconfinder.com/data/icons/default-1/100/.svg-4-512.png'), IconComponent(size='sm', url='https://freeiconshop.com/wp-content/uploads/edd/star-curved-outline.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='Shinjuku, Tokyo', 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=[ # callAction, separator, websiteAction SpacerComponent(size='sm'), # callAction ButtonComponent( style='link', height='sm', action=URIAction(label='CALL', uri='tel:000000'), ), # separator SeparatorComponent(), # websiteAction ButtonComponent( style='link', height='sm', action=URIAction(label='WEBSITE', uri="https://github.com/miner46er/python-line-bot-sparta") ) ] ), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message( event.reply_token, message ) elif command == 'buttons': buttons_template = ButtonsTemplate( title='My buttons sample', text='Hello, my buttons', actions=[ URIAction(label='Go to line.me', uri='https://line.me'), PostbackAction(label='ping', data='ping'), PostbackAction(label='ping with text', data='ping', text='ping'), MessageAction(label='Translate Rice', text='米') ]) menu_pesan = TemplateSendMessage( alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, menu_pesan) elif command == 'pesan': order_memo = BOT_PREFIX + command + ' ' + arguments_string if len(arguments_list) == 0: pilihan_menu = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/512x512', action=MessageAction(label='Nasi Putih', text=BOT_PREFIX + command + ' putih') ), ImageCarouselColumn( image_url='https://via.placeholder.com/512x512', action=MessageAction(label='Nasi Umami', text=BOT_PREFIX + command + ' umami') ) ]) menu_pesan = TemplateSendMessage( alt_text='Menu pesanan', template=pilihan_menu) line_bot_api.reply_message(event.reply_token, menu_pesan) elif len(arguments_list) == 1: if RICE_TYPE.count(arguments_list[0]) == 1: pilihan_menu = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/512x512', action=MessageAction(label='Ayam', text=order_memo + ' ayam') ), ImageCarouselColumn( image_url='https://via.placeholder.com/512x512', action=MessageAction(label='Cumi', text=order_memo + ' cumi') ), ImageCarouselColumn( image_url='https://via.placeholder.com/512x512', action=MessageAction(label='Campur', text=order_memo + ' campur') ) ]) menu_pesan = TemplateSendMessage( alt_text='Menu pesanan', template=pilihan_menu) line_bot_api.reply_message(event.reply_token, menu_pesan) else: order_mistake(event) elif 2 <= len(arguments_list) <= 5 and arguments_list[-1] != 'selesai': if validate_order(arguments_list, -1): sauce_template = ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://via.placeholder.com/512x512', action=MessageAction(label='XO', text=order_memo + ' xo') ), ImageCarouselColumn( image_url='https://via.placeholder.com/512x512', action=MessageAction(label='Mayonnaise', text=order_memo + ' mayo') ), ImageCarouselColumn( image_url='https://via.placeholder.com/512x512', action=MessageAction(label='Bumbu Bali', text=order_memo + ' bali') ), ImageCarouselColumn( image_url='https://via.placeholder.com/512x512', action=MessageAction(label='Blackpepper', text=order_memo + ' blackpepper') ) ]) sauce_choice = TemplateSendMessage( alt_text='Menu saus', template=sauce_template) confirm_button = ButtonsTemplate( text=('Pesananmu sekarang:' + '\nNasi : ' + arguments_list[0] + '\nTopping : ' + arguments_list[1] + '\nSaus(max 4): ' + ', '.join(arguments_list[2:])), actions=[ MessageAction(label='Selesai memesan', text=order_memo + ' selesai') ]) order_confirm = TemplateSendMessage( alt_text='Pesanan saat ini', template=confirm_button) line_bot_api.reply_message(event.reply_token, [sauce_choice, order_confirm]) else: order_mistake(event) elif (len(arguments_list) == 6) and (arguments_list[-1] != 'selesai'): if validate_order(arguments_list, -1): summary_button = ButtonsTemplate( text=('Apakah pesanan sudah benar?' + '\nNasi : ' + arguments_list[0] + '\nTopping : ' + arguments_list[1] + '\nSaus(max 4): ' + ', '.join(arguments_list[2:])), actions=[ MessageAction(label='Selesai memesan', text=order_memo + ' selesai') ]) order_summary = TemplateSendMessage( alt_text='Konfirmasi pesanan', template=summary_button) line_bot_api.reply_message(event.reply_token, order_summary) elif len(arguments_list) >= 3 and arguments_list[-1] == 'selesai': if validate_order(arguments_list, -2): line_bot_api.reply_message( event.reply_token, TextSendMessage(text='Pesanan dikirim!') ) else: order_mistake(event) else: order_mistake(event)
def handle_message(event): sender = event.source.user_id text = event.message.text try: startTime = time.time() cmds.handle_message(event) cinemaxxi.handle_message(event) yify_torrent.handle_message(event) quiz.handle_message(event) notif.handle_message(event) imdbthing.handle_message(event) gid = event.source.sender_id #get group_id profil = line_bot_api.get_profile(sender) try: nama = panggil(sender) #Ini buat nama except: data = { 'nama': line_bot_api.get_profile(event.source.user_id).display_name, 'foto': line_bot_api.get_profile(event.source.user_id).picture_url, 'status': line_bot_api.get_profile(event.source.user_id).status_message, 'waktu_add': time.time() } db.child("pengguna").child(event.source.user_id).set(data) gambar = profil.picture_url #Ini profile picture status = profil.status_message #Ini status di line def stimey(total_seconds): try: MINUTE = 60 HOUR = MINUTE * 60 DAY = HOUR * 24 days = int(total_seconds / DAY) hours = int((total_seconds % DAY) / HOUR) minutes = int((total_seconds % HOUR) / MINUTE) seconds = int(total_seconds % MINUTE) string = list() if days > 0: string.append(str(days) + " hari") if hours > 0: string.append(str(hours) + " jam") if minutes > 0: string.append(str(minutes) + " menit") if seconds > 0: string.append(str(seconds) + " detik") else: if len(string) == 0: string.append("0 detik") if len(string) > 1: return ", ".join(string[:-1]) + ", dan " + string[-1] else: return ", ".join(string) except Exception as e: try: et, ev, tb = sys.exc_info() lineno = tb.tb_lineno fn = tb.tb_frame.f_code.co_filename if sender != owner: line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='Oopps.. ' + namaBot.capitalize() + ' ada kesalahan kak :('), TextSendMessage( text= 'Tapi tenang kak, laporan kesalahan ini terkirim ke owner untuk diperbaiki ;D' ) ]) line_bot_api.push_message( owner, TextSendMessage( text="[Expectation Failed] %s Line %i - %s" % (fn, lineno, str(e)))) except: line_bot_api.push_message( owner, TextSendMessage( text="Undescribeable error detected!!")) if isinstance(event.source, SourceGroup): kirim = gid elif isinstance(event.source, SourceRoom): kirim = event.source.room_id else: kirim = sender def balas(args): line_bot_api.reply_message(event.reply_token, TextSendMessage(text=args)) def message(args): line_bot_api.push_message(kirim, TextSendMessage(text=args)) def img(args): line_bot_api.push_message( kirim, ImageSendMessage(original_content_url=args, preview_image_url=args)) if sender in perintah: komando, waktu = perintah[sender] if komando == "panggilan": if text == "Ubah nama panggilan": return db.child("pengguna").child(sender).child("tambahan").child( "panggilan").set(text) line_bot_api.reply_message( event.reply_token, TextSendMessage( text="Mulai sekarang kakak akan kupanggil " + text + " ;D")) del perintah[sender] if text.lower() == namaBot: pesan = FlexSendMessage( alt_text="Menu", contents=CarouselContainer(contents=[ BubbleContainer( styles=BubbleStyle(header=BlockStyle( background_color='#223e7c')), header=BoxComponent(layout='vertical', contents=[ TextComponent(text='MENU', align='center', color='#ffffff') ]), body=BoxComponent( layout='vertical', spacing='md', contents=[ BoxComponent( layout='horizontal', spacing='sm', contents=[ BoxComponent( layout='vertical', spacing='sm', contents=[ ImageComponent( url= 'https://i.postimg.cc/k4ybdVvm/movie-icon-11.png', align='center', action=MessageAction( label='Film', text='Nonton film kuy' )), TextComponent(text='Film', size='xs', align='center') ]), BoxComponent( layout='vertical', spacing='sm', contents=[ ImageComponent( url='https://goo.gl/Rtqc1r', align='center', action=MessageAction( label='Drama', text= 'Mau nonton drama nih') ), TextComponent(text='Drama', size='xs', align='center') ]), BoxComponent( layout='vertical', spacing='sm', contents=[ ImageComponent( url='https://goo.gl/S9GjL7', align='center', action=MessageAction( label='YouTube', text= 'Mau nonton YouTube')), TextComponent(text='YouTube', size='xs', align='center') ]) ]), BoxComponent( layout='horizontal', spacing='sm', contents=[ BoxComponent( layout='vertical', spacing='sm', contents=[ ImageComponent( url= 'https://i.postimg.cc/DzD04rPf/70.png', align='center', action=PostbackAction( label='Main', text='Main kuy', data='/main')), TextComponent(text='Permainan', size='xs', align='center') ]), BoxComponent( layout='vertical', spacing='sm', contents=[ ImageComponent( url= 'https://i.postimg.cc/q75v5Q3X/69.png', align='center', action=PostbackAction( label='Pengingat', text='Atur pengingat', data='/pengingat')), TextComponent(text='Pengingat', wrap=True, size='xs', align='center') ]), BoxComponent( layout='vertical', spacing='sm', contents=[ ImageComponent( url= 'https://i.postimg.cc/YqqXtBh6/settings-3-icon.png', align='center', action=PostbackAction( label='Pengaturan', text='Pengaturan', data='/pengaturan')), TextComponent( text='Pengaturan', size='xs', align='center', wrap=True) ]) ]) ]), footer=BoxComponent( layout='baseline', contents=[ TextComponent(text='© YRP', size='xxs', align='start'), TextComponent( text=namaBot.capitalize() + ' ' + os.environ.get('HEROKU_RELEASE_VERSION'), size='xxs', align='end') ])) ])) line_bot_api.reply_message( event.reply_token, [TextComponent(text="Kamu ingin apa hari ini?"), pesan]) elif text == "Nonton film kuy": balas("Ini aku punya beberapa fungsi kalau kak " + nama + " mau nonton film ;)") line_bot_api.push_message(kirim, mau_nonton()) elif namaBot in text.lower( ) and not text.lower() == namaBot and not sender in cmds.perintah: if "apa" in text.lower(): if text.lower()[len(text) - 1] == "?": balas( random.choice([ "Ya", "Tidak", "Terkadang", "Mungkin", "Coba tanya lagi", "Entah", "Hmm..." ])) else: balas("Situ bertanya?") #=====[ LEAVE GROUP OR ROOM ]========== elif 'get out' == text.lower() or 'bye' == text.lower(): if sender != owner: balas("STFU!") return if isinstance(event.source, SourceGroup): line_bot_api.reply_message( event.reply_token, TextSendMessage(text='Good Bye Cruel World')) 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 Cruel World')) line_bot_api.leave_room(event.source.room_id) else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text="No!")) ################################################ elif text.lower() == "who am i?": #message("You're "+nama) line_bot_api.reply_message(event.reply_token, TextSendMessage(text="You're " + nama)) line_bot_api.push_message( kirim, ImageSendMessage(original_content_url=gambar, preview_image_url=gambar)) elif text[0] == "=": data = text[1:].split(" ", 1) if len(data) > 1: cmd, args = data[0].lower(), data[1] else: cmd, args = data[0].lower(), "" if cmd == "e": if sender != owner: message('STFU!') return try: ret = eval(args) if ret == None: message("Done.") return message(str(ret)) except Exception as e: try: et, ev, tb = sys.exc_info() lineno = tb.tb_lineno fn = tb.tb_frame.f_code.co_filename message("[Expectation Failed] %s Line %i - %s" % (fn, lineno, str(e))) except: message("Undescribeable error detected!!") #=====[ FLEX MESSAGE ]========== elif text == 'flex': bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url= 'https://i.pinimg.com/originals/0b/45/54/0b45541af3e8d77e23498c1bc8d552f6.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction( uri='http://line.me/ti/p/~freedom_for_all', label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='Noir', 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='Ujung Pandang, 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='Noir', uri="https://line.me/ti/p/~freedom_for_all")) ]), ) message = FlexSendMessage(alt_text="Hi there!", contents=bubble) line_bot_api.reply_message(event.reply_token, message) #======================================================================================================================= ############ ERROR HANDLING ############ except LineBotApiError as e: print(e.status_code) print(e.error.message) print(e.error.details)