def FlexWeatherTemplate(city, url, w, aqiindex, uvi): return (FlexSendMessage( alt_text=city + "-天氣及空氣品質 Flex", contents=BubbleContainer(body=BoxComponent( layout="vertical", padding_all="0px", contents=[ ImageComponent(url=url, gravity="center", margin="none", size="full", aspectRatio="1:1", aspectMode="cover"), BoxComponent( layout="vertical", padding_all="20px", position="absolute", contents=[ TextComponent(text=city, size="xl"), TextComponent(text=str( datetime.datetime.now(pytz.timezone( 'Asia/Taipei')).strftime("%Y/%m/%d %H:%M")), size="xs"), ImageComponent(url="https" + w.get_weather_icon_url()[4:], size="xxs", align="start"), TextComponent(text=status2ct(w.get_status()), size="xxl", weight="bold"), TextComponent(text=w.get_detailed_status(), size="xs"), TextComponent(text="溫度: " + str( round( w.get_temperature( unit='celsius')['temp'], 1)) + "°C" + " 濕度: " + str(w.get_humidity()) + "%", size="xl"), TextComponent(text="空氣品質: " + requests.get( 'https://data.epa.gov.tw/api/v1/aqx_p_432?api_key=9be7b239-557b-4c10-9775-78cadfc555e9&format=json&limit=1234' ).json()['records'][aqiindex]['AQI'] + "(" + aqi2rate( requests.get( 'https://data.epa.gov.tw/api/v1/aqx_p_432?api_key=9be7b239-557b-4c10-9775-78cadfc555e9&format=json&limit=100' ).json()['records'][aqiindex]['AQI']) + ")"), TextComponent( text="紫外線: " + str(round(float(uvi.json()['records'][0] ['UVI']))) + "(" + uvi2rate(uvi.json()['records'][0]['UVI']) + ")"), TextComponent( text="風速: " + str(round(w.get_wind()['speed'] * 18 / 5, 1)) + "km/h") ]) ]))))
def single(set1): for x in set1: mes = BubbleContainer( hero=ImageComponent(url=set1[x], size='full', align='center', aspect_ratio='13:13', aspect_mode='cover'), body=BoxComponent(layout='vertical', contents=[ TextComponent(margin='md', text=x, weight='bold', size='md', align='center'), SeparatorComponent(margin='xl', color='#0000FF'), BoxComponent(margin='md', layout='horizontal', spacing='xs', contents=[ ButtonComponent( style='link', color='#84C1FF', flex=1, height='sm', action=MessageAction( label="我的最愛", text='SeeMyLove')) ]) ])) return FlexSendMessage(alt_text="hello", contents=mes) else: return TextSendMessage(text="None img")
def add_video(template, title, url, thumbnails): bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url=thumbnails, size='full', aspect_ratio='20:13', aspect_mode='cover', gravity='center'), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text=title, wrap=True, weight='bold', size='xxl', align='center') ]), footer=BoxComponent(layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='link', height='sm', action=URIAction(label='點擊查看', uri=url), ) ]), ) template.contents.append(bubble) return template
def test_bubble_container(self): arg = { 'header': BoxComponent(layout='vertical', contents=[TextComponent(text='Header text')]), 'body': BoxComponent(layout='vertical', contents=[TextComponent(text='Body text')]), 'footer': BoxComponent(layout='vertical', contents=[TextComponent(text='Footer text')]), 'styles': BubbleStyle(header=BlockStyle(background_color='#00ffff'), hero=BlockStyle(background_color='#00ffff', separator=True), footer=BlockStyle(background_color='#00ffff', separator=True, separator_color='#00ffff')) } heros = [ ImageComponent(uri='https://example.com/flex/images/image.jpg'), BoxComponent(layout='vertical', contents=[TextComponent(text='Body text')]), ] for hero in heros: arg['hero'] = hero self.assertEqual(self.serialize_as_dict(arg, type=self.BUBBLE), BubbleContainer(**arg).as_json_dict())
def res_user_status(event): profile = line_bot_api.get_profile(event.source.user_id) status_msg = profile.status_message if status_msg != "None": # LINEに登録されているstatus_messageが空の場合は、"なし"という文字列を代わりの値とする status_msg = "なし" message=FlexSendMessage( alt_text='ユーザー情報', contents=BubbleContainer( header=BoxComponent( layout="vertical", contents=[ TextComponent( text='text', align='center', gravity='center', contents=[ SpanComponent(text='ユーザー情報') ] ) ] ),#Header hero=ImageComponent( url=profile.picture_url, size="full", aspect_mode="fit", action=None ), body=BoxComponent( layout="vertical", contents=[ TextComponent( text='text', align='center', gravity='center', contents=[ SpanComponent(text=f'User Id: {profile.user_id}') ] ), TextComponent( text='text', align='center', gravity='center', contents=[ SpanComponent(text=f'Status Message: {status_msg}') ] ) ] ),#Body footer=BoxComponent( layout="vertical", contents=[ ButtonComponent( action=MessageAction(label="成功", text="?") ) ] )#Footer ) ) line_bot_api.reply_message(event.reply_token, messages=message)
def test_image_component(self): arg = { 'url': 'https://example.com/flex/images/image.jpg', 'size': 'full', 'aspect_ratio': '1.91:1' } self.assertEqual(self.serialize_as_dict(arg, type=self.IMAGE), ImageComponent(**arg).as_json_dict())
def get_toss_flex_message(megDict, to, reply=True): bubble = BubbleContainer( direction='ltr', header=BoxComponent(layout='baseline', margin='md', contents=[ TextComponent(text=megDict['title'], weight='bold', size='xl'), ]), body=BoxComponent(layout='horizontal', margin='sm', spacing='sm', contents=[ ImageComponent( size='sm', url=megDict['img'][0], ), ImageComponent( size='sm', url=megDict['img'][1], ), ]), footer=BoxComponent(layout='vertical', spacing='sm', contents=[ SeparatorComponent(), ButtonComponent(style='link', height='sm', action=URIAction( label=megDict['btn_word'], uri=megDict['url'])) ]), ) message = FlexSendMessage(alt_text=megDict['title'], contents=bubble) if reply: line_bot_api.reply_message(to, message) else: line_bot_api.push_message(to, message)
def getYoutubeBubble(url): bubble = BubbleContainer( direction='ltr', spacing='none', hero=ImageComponent( url=url, size='md', aspect_ratio="1:1", aspect_mode='cover', action=URIAction(label='RateBeer', uri=url), ), ) return bubble
def test_box_component(self): arg = { 'layout': 'vertical', 'contents': [ ImageComponent( url='https://example.com/flex/images/image.jpg'), SeparatorComponent(), TextComponent(text='Text in the box'), ] } self.assertEqual(self.serialize_as_dict(arg, type=self.BOX), BoxComponent(**arg).as_json_dict())
def intro(self, user_name): bubble = BubbleContainer( # header header=BoxComponent(layout='horizontal', contents=[ TextComponent( text='Hi {0},'.format(user_name), size='lg', color='#000000') ]), # hero hero=ImageComponent(url='https://i.imgur.com/xYgkKHe.png', size='full', aspect_ratio='16:9', aspect_mode='cover'), # body body=BoxComponent( layout='vertical', spacing='md', contents=[ SeparatorComponent(margin='md'), BoxComponent( layout='horizontal', spacing='md', contents=[ TextComponent( text='Hi 可以發一張圖片給我,\n我能識別出裡面的人臉情緒唷~\n\n', size='md', wrap=True, color='#272727', align='center') ]), BoxComponent( layout='horizontal', spacing='md', contents=[ TextComponent( text='聲明\n辨識完即刪除,不會以任何形式保存圖片、人像等敏感性資訊', size='sm', wrap=True, color='#00BE00', align='center') ]) ])) message = FlexSendMessage(alt_text="hello~", contents=bubble) return message
def generate_carousel_for_search(books): contents = [] for book in books: content = BubbleContainer( action=URIAction(uri=book['url']), size='micro', hero=ImageComponent(url=book['photo_url'], size='full', aspect_mode='cover', aspect_ratio='320:213'), body=BoxComponent(layout='vertical', spacing='sm', padding_all='13px', contents=[ TextComponent(text=book['name'], weight='bold', size='sm'), BoxComponent( layout='baseline', contents=[ TextComponent(text=book['authors'], size='xs', color='#8c8c8c', margin='md'), TextComponent(text=book['publisher'], size='xs', color='#8c8c8c', margin='md') ]), SeparatorComponent(margin='md', color='#a0a0a0'), TextComponent(text=book['summary'], color='#8c8c8c', size='xs', wrap=True) ]), footer=BoxComponent(layout='vertical', contents=[ SeparatorComponent(margin='md', color='#a0a0a0'), TextComponent(text=book['price'], wrap=True, size='sm', flex=5, align='center') ])) contents.append(content) return CarouselContainer(contents=contents)
def show_single_result(self, imgurl, emotion, confidence): bubble = BubbleContainer( # header header=BoxComponent(layout='horizontal', contents=[ TextComponent(text='辨識結果', size='lg', color='#5b5b5b') ]), #hero hero=ImageComponent(url='{0}'.format(imgurl), size='3xl', aspect_ratio='16:9', aspect_mode='fit'), # body body=BoxComponent( layout='vertical', spacing='md', contents=[ SeparatorComponent(margin='md'), BoxComponent(layout='horizontal', spacing='md', contents=[ TextComponent(text='情緒 :', size='lg', color='#9d9d9d', align='center'), TextComponent(text='{0}'.format(emotion), size='lg', color='#00BE00', weight='bold') ]), BoxComponent(layout='horizontal', spacing='md', contents=[ TextComponent(text='信心值 :', size='lg', color='#9d9d9d', align='center'), TextComponent( text='{0}%'.format(confidence), size='lg', color='#00BE00', weight='bold') ]) ])) message = FlexSendMessage(alt_text="辨識結果", contents=bubble) return message
def create_contents(tweets): contents = [] for t in tweets: if t.created_at >= datetime.utcnow() - timedelta(hours=1, minutes=1): print(t.full_text) print(t.created_at) profile_image = t.user.profile_image_url_https text = t.full_text is_retweeted = re.match('^RT', text) header_text = '公式のツイート' if not is_retweeted else '公式のリツイート' main_color = '#08B901' if is_retweeted else '#1EA2F1' tweeter = t.retweeted_status.user if is_retweeted else t.user tweeter_icon = tweeter.profile_image_url_https try: extended_entities = t.retweeted_status.extended_entities media = extended_entities['media'] if is_retweeted else t.media images = [ ImageComponent( type="image", url=m['media_url_https'], aspect_ratio='1:1', aspect_mode='cover', margin="md", ) for m in media ] except: images = [] contents.append({ 'header_text': header_text, 'main_color': main_color, 'text': text, 'profile_image': profile_image.replace('_normal', ''), 'tweeter_icon': tweeter_icon.replace('_normal', ''), 'tweet_url': 'https://twitter.com/hiratahirata14/status/' + t.id_str, 'images': images, }) print('---------------') else: print('---------------') return contents
def test_box_component(self): arg = { 'layout': 'vertical', 'contents': [ ImageComponent(url='https://example.com/flex/images/image.jpg'), SeparatorComponent(), TextComponent(text='Text in the box'), ], 'background_color': '#00000000', 'border_width': 'light', 'corner_radius': 'xs', 'flex': 2 } self.assertEqual( self.serialize_as_dict(arg, type=self.BOX), BoxComponent(**arg).as_json_dict() )
def get_news_message(title, href, img, imghref, showinTilte): cont = [] for i in range(len(title)): row = BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent(text=title[i], color='#666666', size='sm', margin='md', wrap=True, action=URIAction(label='WEBSITE', uri=href[i])) ], ) cont.append(row) cont.append(SeparatorComponent()) del (cont[-1]) title = 'Top News' + showinTilte bubble = BubbleContainer( direction='ltr', hero=ImageComponent(url=img[0], size='full', aspect_ratio='20:13', aspect_mode='cover', action=URIAction(uri=imghref[0], label='label')), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text=title, weight='bold', size='xl'), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=cont, ) ], )) message = FlexSendMessage(alt_text="hello", contents=bubble) return message
def welcome(self): bubble = BubbleContainer( # header header=BoxComponent( layout='horizontal', contents=[ TextComponent(text='哆哆歡迎您', weight='bold', size='lg', color='#00BE00') ] ), #hero hero=ImageComponent(url='https://i.imgur.com/onXQU46.png', size='full', aspect_ratio='16:9', aspect_mode='cover'), # body body=BoxComponent( layout='vertical', spacing='md', contents=[ # main info TextComponent(text='嗨,我是哆哆,感謝您加我為好友,我會回答您的問題讓您更進一步了解明聲。讓我們開始吧!\n\n您可以直接輸入:\n\n可以介紹一下嗎?\n你會什麼?\n你有什麼作品?\n有拿過什麼認證嗎?\n\n當不知道如何使用時,請輸入help\n我會出來為您引導。', size='md', wrap=True, color='#6c6c6c'), SeparatorComponent(margin='xl'), BoxComponent( layout = 'vertical', contents = [ SpacerComponent(size='md'), ButtonComponent( style='primary', height='sm', action=MessageAction(label="Let's Start", text='可以介紹一下嗎?'), ) ] ) ] ) ) message = FlexSendMessage(alt_text="Welcome", contents=bubble) return message
def create_bubble_container(thumbnail_image_url, video_url): return BubbleContainer( direction='ltr', hero=ImageComponent(url=thumbnail_image_url, size='full', aspectRatio='16:9', aspectMode='cover'), body=BoxComponent( layout='vertical', contents=[ ButtonComponent(action=URIAction(label='觀看影片', uri=video_url), style='primary', color='#29D90C', margin='lg'), ButtonComponent(action=URIAction( label='分享影片', uri='https://line.me/R/msg/text/?' + video_url), style='primary', color='#29D90C', margin='lg') ]))
def tenMod(dset): contents = [] if len(dset): for x in dset: contents.append( BubbleContainer( hero=ImageComponent(url=x, size='full', align='center', aspect_ratio='13:13', aspect_mode='cover'), body=BoxComponent( layout='vertical', contents=[ TextComponent(margin='md', text=dset[x], weight='bold', size='md', align='center'), SeparatorComponent(margin='xl', color='#0000FF'), BoxComponent(margin='md', layout='horizontal', spacing='xs', contents=[ ButtonComponent( style='link', color='#84C1FF', flex=1, height='sm', action=MessageAction( label="加入最愛", text='MyLove:' + dset[x])) ]) ]))) Carousel = CarouselContainer(contents=contents) message = FlexSendMessage(alt_text="hello", contents=Carousel) else: message = TextSendMessage(text='無符合您輸入的葡萄酒'+chr(0x100010)+"\n"\ +"請重新選擇"+chr(0x10008D)) return message
def too_many_faces(self): bubble = BubbleContainer( # header header=BoxComponent(layout='horizontal', contents=[ TextComponent( text='Multiple face detected', size='lg', color='#5b5b5b') ]), # hero hero=ImageComponent(url='https://i.imgur.com/2X6jdIK.png', size='xl', aspect_ratio='4:4', aspect_mode='cover'), # body body=BoxComponent( layout='vertical', spacing='md', contents=[ SeparatorComponent(margin='md'), BoxComponent( layout='horizontal', spacing='md', contents=[ TextComponent( text= '很抱歉, 圖片中偵測過多張臉,\n請使用其他圖片,謝謝。\n\nPlease try again. Thanks for your cooperation.', size='sm', wrap=True, color='#9d9d9d', align='center') ]) ])) message = FlexSendMessage(alt_text="Multiple Face detected", contents=bubble) return message
def no_face(self): bubble = BubbleContainer( # header header=BoxComponent(layout='horizontal', contents=[ TextComponent(text='No face detected', size='lg', color='#5b5b5b') ]), # hero hero=ImageComponent(url='https://i.imgur.com/cIGrXmq.png', size='xl', aspect_ratio='4:4', aspect_mode='cover'), # body body=BoxComponent( layout='vertical', spacing='md', contents=[ SeparatorComponent(margin='md'), BoxComponent( layout='horizontal', spacing='md', contents=[ TextComponent( text= '很抱歉, 圖片未偵測到臉部,\n 請考慮環境因素影響(如燈光)、臉部角度等因素或確認圖中是否有人臉。\n\nPlease try again. Thanks for your cooperation.', size='sm', wrap=True, color='#9d9d9d', align='center') ]) ])) message = FlexSendMessage(alt_text="No face detected", contents=bubble) return message
def sendmsg(event, context): #各種設定読み込み s3url = inifile.get('s3', 'url') groupId = inifile.get('line', 'targetId') line_token = inifile.get('line', 'token') #LINE APIオブジェクト作成 line_bot_api = LineBotApi(line_token) #イベント取得してメッセージを作成 deviceId = event['deviceInfo']['deviceId'] clickType = event['deviceEvent']['buttonClicked']['clickType'] alttext = inifile.get('message', 'shortmsg') cgfile = inifile.get('s3', 'shortcg') if (clickType == "DOUBLE"): alttext = inifile.get('message', 'doublemsg') cgfile = inifile.get('s3', 'doublecg') if (clickType == "LONG"): alttext = inifile.get('message', 'longmsg') cgfile = inifile.get('s3', 'longcg') flex = BubbleContainer( hero=ImageComponent( size='full', url=s3url + cgfile, ), body=BoxComponent( layout='vertical', contents=[TextComponent(text=alttext, weight='bold', size='lg')]), ) #|LINEにプッシュメッセージを送る line_bot_api.push_message(groupId, FlexSendMessage(alt_text=alttext, contents=flex)) return
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_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 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_message(event): if event.type == "message": if (event.message.text == "Curry Menu") or (event.message.text == "chicken_curry_cancel") or (event.message.text == "green_curry_cancel") or (event.message.text == "keema_curry_cancel"): TextSendMessage( text='画像メニューから自分好みのカレーを選んでね。', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/images01', alt_text='curry_imagemap_no.01', base_size=BaseSize(height=453, width=1040), actions=[ MessageImagemapAction( text='chicken_curry', area=ImagemapArea( x=30, y=50, width=320, height=355 ) ), MessageImagemapAction( text='green_curry', area=ImagemapArea( x=360, y=50, width=320, height=355 ) ), MessageImagemapAction( text='keema_curry', area=ImagemapArea( x=690, y=50, width=320, height=355 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #img_powder if event.type == "message": if (event.message.text == "Powder Spice"): TextSendMessage( text='画像メニューから自分好みのスパイスを選んでね。', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/powder_img', alt_text='powder_spice_img', base_size=BaseSize(height=750, width=1040), actions=[ MessageImagemapAction( text='spice_clove', area=ImagemapArea( x=0, y=10, width=160, height=330 ) ), MessageImagemapAction( text='spice_cinnamon', area=ImagemapArea( x=160, y=0, width=160, height=330 ) ), MessageImagemapAction( text='spice_cumin', area=ImagemapArea( x=330, y=0, width=160, height=330 ) ), MessageImagemapAction( text='spice_tougarashi', area=ImagemapArea( x=860, y=10, width=170, height=320 ) ), MessageImagemapAction( text='spice_blackpepper', area=ImagemapArea( x=510, y=10, width=170, height=320 ) ), MessageImagemapAction( text='spice_mace', area=ImagemapArea( x=690, y=0, width=170, height=320 ) ), MessageImagemapAction( text='spice_tougarashi', area=ImagemapArea( x=860, y=0, width=170, height=320 ) ), MessageImagemapAction( text='spice_bigcardamon', area=ImagemapArea( x=0, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_nutmeg', area=ImagemapArea( x=160, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_allspice', area=ImagemapArea( x=330, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_bayleaf', area=ImagemapArea( x=510, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_greencardamon', area=ImagemapArea( x=680, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_coriander', area=ImagemapArea( x=860, y=340, width=170, height=320 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #spice_flavor_ring if event.type == "message": if (event.message.text == "Whole Spice"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/s.f.h', alt_text='spice_flavor_ring', base_size=BaseSize(height=995, width=1040), actions=[ MessageImagemapAction( text='spicy_flavor', area=ImagemapArea( x=100, y=500, width=280, height=210 ) ), MessageImagemapAction( text='sweet_flavor', area=ImagemapArea( x=390, y=60, width=240, height=230 ) ), MessageImagemapAction( text='fresh_flavor', area=ImagemapArea( x=650, y=280, width=270, height=210 ) ), MessageImagemapAction( text='bitter_flavor', area=ImagemapArea( x=380, y=710, width=260, height=240 ) ), MessageImagemapAction( text='hot_flavor', area=ImagemapArea( x=110, y=250, width=250, height=240 ) ), MessageImagemapAction( text='herb_flavor', area=ImagemapArea( x=650, y=500, width=270, height=210 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_sweet if event.type == "message": if (event.message.text == "sweet_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/sweet', alt_text='spice_flavor_ring', base_size=BaseSize(height=994, width=1040), actions=[ MessageImagemapAction( text='sweet_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='sweet_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='sweet_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='sweet_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='sweet_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='sweet_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ), MessageImagemapAction( text='sweet_7', area=ImagemapArea( x = 50, y = 660, width = 309, height = 299 ) ), MessageImagemapAction( text='sweet_8', area=ImagemapArea( x = 369, y = 661, width = 304, height = 298 ) ), MessageImagemapAction( text='sweet_9', area=ImagemapArea( x = 680, y = 661, width = 320, height = 296 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_spicy if event.type == "message": if (event.message.text == "spicy_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/spicy', alt_text='spice_flavor_ring', base_size=BaseSize(height=773, width=1040), actions=[ MessageImagemapAction( text='spicy_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='spicy_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='spicy_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_hot if event.type == "message": if (event.message.text == "hot_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/hot', alt_text='spice_flavor_ring', base_size=BaseSize(height=994, width=1040), actions=[ MessageImagemapAction( text='hot_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='hot_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='hot_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='hot_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='hot_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='hot_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_harbr if event.type == "message": if (event.message.text == "herb_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/harbr', alt_text='spice_flavor_ring', base_size=BaseSize(height=957, width=1040), actions=[ MessageImagemapAction( text='harbr_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='harbr_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='harbr_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='harbr_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='harbr_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='harbr_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_fresh if event.type == "message": if (event.message.text == "fresh_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/fresh', alt_text='spice_flavor_ring', base_size=BaseSize(height=992, width=1040), actions=[ MessageImagemapAction( text='fresh_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='fresh_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='fresh_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='fresh_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='fresh_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='fresh_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ), MessageImagemapAction( text='fresh_7', area=ImagemapArea( x = 50, y = 660, width = 309, height = 299 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_bitter if event.type == "message": if (event.message.text == "bitter_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/bitter', alt_text='spice_flavor_ring', base_size=BaseSize(height=994, width=1040), actions=[ MessageImagemapAction( text='bitter_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='bitter_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='bitter_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='bitter_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='bitter_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='bitter_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ), MessageImagemapAction( text='bitter_7', area=ImagemapArea( x = 50, y = 660, width = 309, height = 299 ) ), MessageImagemapAction( text='bitter_8', area=ImagemapArea( x = 369, y = 661, width = 304, height = 298 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #クイックリプライ(spice_g) #def spice_quantity if event.type == "message": if (event.message.text == "spice_clove") or (event.message.text == "spice_allspice") or (event.message.text == "spice_nutmeg") or (event.message.text == "spice_cinnamon") or (event.message.text == "spice_bigcardamon") or (event.message.text == "spice_mace") or (event.message.text == "spice_bayleaf"): line_bot_api.reply_message( event.reply_token, TextSendMessage( text='ブレンドする量を選択してください', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction(label="小さじ1/2", text="spice_小さじ1/2") ), ]))) if event.type == "message": if (event.message.text == "spice_blackpepper") or (event.message.text == "spice_tougarashi"): line_bot_api.reply_message( event.reply_token, TextSendMessage( text='ブレンドする量を選択してください', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction(label="小さじ1/2", text="spice_小さじ1/2") ), QuickReplyButton( action=MessageAction(label="小さじ1", text="spice_小さじ1") ), ]))) if event.type == "message": if (event.message.text == "spice_greencardamon"): line_bot_api.reply_message( event.reply_token, TextSendMessage( text='ブレンドする量を選択してください', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction(label="小さじ1/2", text="spice_小さじ1/2") ), QuickReplyButton( action=MessageAction(label="小さじ1", text="spice_小さじ1") ), QuickReplyButton( action=MessageAction(label="小さじ2", text="spice_小さじ2") ), ]))) if event.type == "message": if (event.message.text == "spice_cumin") or (event.message.text == "spice_coriander"): line_bot_api.reply_message( event.reply_token, TextSendMessage( text='ブレンドする量を選択してください', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction(label="小さじ1/2", text="spice_小さじ1/2") ), QuickReplyButton( action=MessageAction(label="小さじ1", text="spice_小さじ1") ), QuickReplyButton( action=MessageAction(label="小さじ2", text="spice_小さじ2") ), QuickReplyButton( action=MessageAction(label="小さじ4", text="spice_小さじ4") ), ]))) #チキンカレー_flex if event.type == "message": if (event.message.text == "chicken_curry"): bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='https://images.unsplash.com/photo-1585937421612-70a008356fbe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60', size='full', aspect_ratio='20:13', aspect_mode='cover', ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='チキンカレー', weight='bold', size='xl'), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='材料名', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=' ①鶏モモ肉\n ②タマネギ\n ③シメジ\n ④水\n ⑤オリーブオイル\n ⑥バター', wrap=True, color='#666666', size='sm', flex=5 ) ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='spice', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=" ⑦お好きな調味料\n (トマトソース)\n ⑧お好きなスパイス", wrap=True, color='#666666', size='sm', flex=5, ), ], ), ], ) ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='primary', height='sm', action=MessageAction(label='次へ進む', text='chicken_curry_next'), ), SeparatorComponent(), ButtonComponent( style='secondary', height='sm', action=MessageAction(label='カレーを選びなおす', text="chicken_curry_cancel") ) ] ), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message( event.reply_token, message ) #チキンカレー_flex #グリーンカレー_flex if event.type == "message": if (event.message.text == "green_curry"): bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='https://images.unsplash.com/photo-1560684352-8497838a2229?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60', size='full', aspect_ratio='20:13', aspect_mode='cover', ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='グリーンカレー', weight='bold', size='xl'), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='材料名', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=' ①鶏モモ肉\n ②タマネギ\n ③ほうれん草\n ④ナス\n ⑤エリンギ\n ⑥豆乳\n ⑦オリーブオイル', wrap=True, color='#666666', size='sm', flex=5 ) ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='spice', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=" ⑦お好きな調味料\n (グリーンペースト)\n ⑧お好きなスパイス", wrap=True, color='#666666', size='sm', flex=5, ), ], ), ], ) ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='primary', height='sm', action=MessageAction(label='次へ進む', text='green_curry_next'), ), SeparatorComponent(), ButtonComponent( style='secondary', height='sm', action=MessageAction(label='カレーを選びなおす', text="green_curry_cancel") ) ] ), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message( event.reply_token, message ) #グリーンカレー_flex #キーマカレー_flex if event.type == "message": if (event.message.text == "keema_curry"): bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='https://production-orp.s3.amazonaws.com/uploads/recipes/image/0000300319/20160801160506.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='キーマカレー', weight='bold', size='xl'), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='材料名', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=' ①豚挽肉\n ②ピーマン\n ③赤ピーマン\n ④タマネギ\n ⑤ニンジン\n ⑥コーン\n ⑦水\n ⑧オリーブオイル', wrap=True, color='#666666', size='sm', flex=5 ) ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='spice', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=" ⑦お好きな調味料\n (味噌ソース)\n ⑧お好きなスパイス", wrap=True, color='#666666', size='sm', flex=5, ), ], ), ], ) ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='primary', height='sm', action=MessageAction(label='次へ進む', text='keema_curry_next'), ), SeparatorComponent(), ButtonComponent( style='secondary', height='sm', action=MessageAction(label='カレーを選びなおす', text="keema_curry_cancel") ) ] ), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message( event.reply_token, message ) #キーマカレー_flex message_content = line_bot_api.get_message_content(event.message.id) with tempfile.NamedTemporaryFile(dir=static_tmp_path, prefix=ext + '-', delete=False) as tf: for chunk in message_content.iter_content(): tf.write(chunk) tempfile_path = tf.name dist_path = tempfile_path + '.' + ext dist_name = os.path.basename(dist_path) os.rename(tempfile_path, dist_path) line_bot_api.reply_message( event.reply_token, [ TextSendMessage(text='Save content.'), TextSendMessage(text=request.host_url + os.path.join('static', 'tmp', dist_name)) ])
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 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 main_info(gym_name, gym_now, gym_total, swim_now, swim_total, tmp): dt = datetime.utcnow() dt = dt.replace(tzinfo=timezone.utc) tzutc_8 = timezone(timedelta(hours=8)) local_dt = dt.astimezone(tzutc_8) #print(local_dt) #print(local_dt.strftime('%Y-%m-%d %H:%M')) mdatetime = local_dt.strftime('%Y-%m-%d %H:%M') bubble = BubbleContainer( direction='ltr', body=BoxComponent( layout='vertical', contents=[ TextComponent(text='即時人流資訊', weight='bold', size='sm', color='#1DB446'), TextComponent(text=gym_name, weight='bold', size='xxl', margin='md'), TextComponent(text=tmp, size='xs', color='#aaaaaa', margin='sm', wrap=True), SeparatorComponent(margin='xxl'), BoxComponent( layout='horizontal', margin='xxl', spacing='sm', contents=[ #picture BoxComponent( layout='vertical', flex=0, contents=[ ImageComponent( url='https://i.imgur.com/3qQCq1f.png', size='sm', aspectRatio="16:9", aspectMode="fit"), ImageComponent( url='https://i.imgur.com/B37vhyK.png', size='sm', aspectRatio="16:9", aspectMode="fit", margin='lg') ]), #info BoxComponent( layout='vertical', align='center', flex=1, contents=[ TextComponent( text=' 現在人數: {0} 人'.format(gym_now), flex=2, size='lg', weight='bold', color='#1DB446', gravity='center'), TextComponent( text=' 容留: {0} 人'.format(gym_total), flex=1, size='md', gravity='center'), TextComponent( text=' 現在人數: {0} 人'.format(swim_now), flex=2, size='lg', weight='bold', color='#1DB446', gravity='center', margin='xl'), TextComponent( text=' 容留: {0} 人'.format(swim_total), flex=1, size='md', gravity='center') ]) ]), SeparatorComponent(margin='lg'), ]), footer=BoxComponent(layout='horizontal', margin='md', spacing='md', contents=[ TextComponent(text="查詢時間", size="xs", color="#aaaaaa", flex=0), TextComponent(text=mdatetime, size="xs", color="#aaaaaa", align="end") ])) message = FlexSendMessage(alt_text="即時人流資訊", contents=bubble) return message
def sendmsg(event, context): #各種設定読み込み s3url = inifile.get('s3', 'url') groupId = inifile.get('line', 'targetId') line_token = inifile.get('line', 'token') credential_file = inifile.get('google', 'credential_file') scope = inifile.get('google', 'scope') sheet_key = inifile.get('google', 'sheet_key') sheet = inifile.get('google', 'sheet') babyname = inifile.get('general', 'babyname') #googleスプレッドシートへの接続 credentials = ServiceAccountCredentials.from_json_keyfile_name( credential_file, scope) client = gspread.authorize(credentials) sp = client.open_by_key(sheet_key) wks = sp.worksheet(sheet) #LINE APIオブジェクト作成 line_bot_api = LineBotApi(line_token) #イベント取得してメッセージを作成 deviceId = event['deviceInfo']['deviceId'] clickType = event['deviceEvent']['buttonClicked']['clickType'] alttext = u"おしっこした!" eventtext = u"おしっこ" cgfile = inifile.get('s3', 'shortcg') if (clickType == "DOUBLE"): alttext = u"うんちした!" eventtext = u"うんち" cgfile = inifile.get('s3', 'doublecg') if (clickType == "LONG"): alttext = u"ミルク飲んだ!" eventtext = u"ミルク" cgfile = inifile.get('s3', 'longcg') flex = BubbleContainer( hero=ImageComponent( size='full', url=s3url + cgfile, ), body=BoxComponent(layout='vertical', contents=[ TextComponent(text=babyname + alttext, weight='bold', size='lg') ]), ) #googleスプレッドシートへ追加 column = [ eventtext, datetime.now(pytz.timezone('Asia/Tokyo')).strftime("%Y/%m/%d %H:%M:%S") ] wks.append_row(column) #|LINEにプッシュメッセージを送る line_bot_api.push_message( groupId, FlexSendMessage(alt_text=babyname + alttext, contents=flex)) return
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