def buttons_template(user_id,initial,max,min): # # if 'search=Noall'==check[0]: # changeday=today.strftime("%Y-%m-%d") # elif "search=Nostart"==check[0]: # changeday=today.strftime("%Y-%m-%d") # elif "search=Noend"==check[0]: # changeday=check[2] # print("changeday",changeday) buttons_template_message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( thumbnail_image_url='https://live.staticflickr.com/65535/50435491973_816cca9757_c.jpg', title='查詢運動日誌', text='請選擇起始&結束日期~٩(๑❛ᴗ❛๑)۶\n查詢需要一點時間,請稍後~', actions=[ DatetimePickerAction( label="起始日期", data="startdate", mode="date", initial=initial, max=max, min=min ), DatetimePickerAction( label= "結束日期", data= "enddate", mode= "date", initial=initial, max=max, min=min) ] ) ) return buttons_template_message
def after_preference3(event=None, line_bot_api=None): user_id = event.source.user_id postback = getattr(event, "postback", None) if postback is not None: _food_sports = postback.data.split("&")[1] repo.update_users(user_id, "food_sports", _food_sports) _is_food_main = _get_food_main(user_id) if _is_food_main: _text = "オススメの食事を送るね♪\n朝食は何時に送る?" Session_interface.set_waiting_mode(user_id, MODE.AFTER_PREFERENCE4) line_bot_api.push_message(user_id, TextSendMessage(text=_text, quick_reply=QuickReply( items=[ QuickReplyButton(action=DatetimePickerAction( label="時間を選んでね!", data=MODE.AFTER_PREFERENCE4.hash, mode="time", initial="", min="00:00", max="23:59" )) ] ))) else: Session_interface.set_waiting_mode(user_id, MODE.LAST) last(event=event, line_bot_api=line_bot_api)
def modify_settings(event, user, keyword): if keyword == 'name': name_old = user.name user.name = ' ' # Note: not '' => True; not ' ' => False db.session.commit() line_bot_api.reply_message( event.reply_token, TextSendMessage(text='新しいユーザー名を入力してください。\n\n旧ユーザー名: ' + name_old)) elif keyword == 'location': items = [QuickReplyButton(action=LocationAction(label="位置情報を送る"))] line_bot_api.reply_message( event.reply_token, TextSendMessage(text='下のボタンから新しい位置情報を送信してください。', quick_reply=QuickReply(items=items))) elif keyword == 'defaulttime': current_time = datetime.now() init_time = ('0'+str(current_time.hour) if len(str(current_time.hour))==1 else str(current_time.hour)) \ +':'+('0'+str(current_time.minute) if len(str(current_time.minute))==1 else str(current_time.minute)) items = [ QuickReplyButton( action=DatetimePickerAction(label="サプリのリマインド時刻を設定する", data="set_default_time", mode="time", initial=init_time)) ] line_bot_api.reply_message( event.reply_token, TextSendMessage( text='サプリメントは毎日の継続が最重要。リマインドを送って欲しい時刻を選択してください。' \ 'このBotは、毎日指定された時刻にリマインドを送ります。', quick_reply=QuickReply(items=items) ) )
def get_quick_reply(self, morning_dt, noon_dt, evening_dt): now = datetime.utcnow() return QuickReply(items=[ QuickReplyButton(action=PostbackAction( label="1時間後", display_text="1時間後", data=f"{(now + timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M')}" )), QuickReplyButton(action=PostbackAction( label="🐓", display_text="🐓朝", data= f"{self.to_remind_at(morning_dt, now).strftime('%Y-%m-%dT%H:%M')}" )), QuickReplyButton(action=PostbackAction( label="☀️", display_text="☀️昼", data= f"{self.to_remind_at(noon_dt, now).strftime('%Y-%m-%dT%H:%M')}" )), QuickReplyButton(action=PostbackAction( label="🌙", display_text="🌙夜", data= f"{self.to_remind_at(evening_dt, now).strftime('%Y-%m-%dT%H:%M')}" )), QuickReplyButton(action=DatetimePickerAction( label="日時を選択", mode="datetime", data="picker")), QuickReplyButton(action=PostbackAction( label="キャンセル", display_text="キャンセル", data="cancel")), ])
def button_yoyaku_ymd(label): # 現在日時の取得 get_day = datetime.datetime.now() if get_day.hour + 9 > 18: get_date = str(get_day.year) + "-" + str( get_day.month).zfill(2) + "-" + str(get_day.day + 1).zfill(2) max_date = str(get_day.year) + "-" + str(get_day.month + 1).zfill( 2) + "-" + str(get_day.day + 1).zfill(2) else: get_date = str(get_day.year) + "-" + str( get_day.month).zfill(2) + "-" + str(get_day.day).zfill(2) max_date = str( get_day.year) + "-" + str(get_day.month + 1).zfill(2) + "-" + str( get_day.day).zfill(2) message_template = TemplateSendMessage( alt_text="a", template=ConfirmTemplate(text=label, actions=[ DatetimePickerAction( type="datetimepicker", label="日付選択", data="select_day_yoyaku", mode="date", initial=get_date, max=max_date, min=get_date), PostbackAction(label="予約状況確認", data="menu_yoyaku") ])) return message_template
def after_sex(event=None, line_bot_api=None): user_id = event.source.user_id postback = getattr(event, "postback", None) if postback is not None: _sex = postback.data.split("&")[1] print(_sex) repo.insert_into_users_sex(user_id, _sex) _text = "ありがとうございます★" line_bot_api.reply_message(event.reply_token, TextSendMessage(text=_text)) dur() _text = "生年月日はもちろん非公開にしますから安心してくださいね。" Session_interface.set_waiting_mode(user_id=user_id, mode=MODE.AFTER_BIRTHDATE) line_bot_api.push_message(user_id, TextSendMessage(text=_text, quick_reply=QuickReply( items=[ QuickReplyButton(action=DatetimePickerAction( label="日付を選んでね!", data=MODE.AFTER_BIRTHDATE.hash, mode="date", initial="1990-01-01", min="1950-01-01", max="2017-12-31" )) ] )))
def search_date(today): return QuickReply(items=[ QuickReplyButton( action=DatetimePickerAction(label="起始時間", data="start_date", mode="date", initial=str(today), max=str(today), min=str(today - timedelta(days=30)))), QuickReplyButton( action=DatetimePickerAction(label="結束時間", data="end_date", mode="date", initial=str(today), max=str(today), min=str(today - timedelta(days=30)))), QuickReplyButton(action=MessageAction(label="不查了", text="不查了")), ])
def test_datetime_picker(self): arg = { 'label': 'Select date', 'data': 'storeId=12345', 'mode': 'datetime', 'initial': '2017-12-25t00:00', 'max': '2018-01-24t23:59', 'min': '2017-12-25t00:00' } self.assertEqual(self.serialize_as_dict(arg, type=self.DATETIMEPICKER), DatetimePickerAction(**arg).as_json_dict())
def action_irregular_buttons(words, choices): return [ QuickReplyButton( action=DatetimePickerAction( label=words[choices[0]], data="action_irregular_" + choices[1], mode=choices[2]) ), QuickReplyButton( action=PostbackAction( label=words["cancel"], data="action_cancel", display_text=words["cancel"]), ), ]
def teacher_buttons(words): quick_buttons = [QuickReplyButton( action=DatetimePickerAction( label=words["seeActionsByDate"], data="teacher_seeActionsByDate", mode="date") )] for option in ["seeActionsAll", "seeUsers", "setEmail", "deleteUser", "teacherOff"]: quick_buttons.append(QuickReplyButton( action=PostbackAction( label=words[option], data="teacher_" + option, display_text=words[option]) )) return quick_buttons
def get_button_template_message(actionsDict): actionArr = [] for a in actionsDict.values(): if a['type'] == 'url': actionArr.append(URIAction(label=a['label'], uri=a['content'])) elif a['type'] == 'date' or a['type'] == 'time' or a[ 'type'] == 'datetime': actionArr.append( DatetimePickerAction(label=a['label'], data=a['postback'], mode=a['type'])) else: actionArr.append(MessageAction(label=a['label'], text=a['content'])) return actionArr
def handle_text_message(event): text = event.message.text if text == '/Hello': profile = line_bot_api.get_profile(event.source.user_id) line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Hi '+profile.display_name)) elif text == '/Bye': line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Good Bye')) elif text == '/notify': line_bot_api.reply_message(event.reply_token, TextSendMessage(text='Choose date and time', quick_reply=QuickReply(items=[ QuickReplyButton(action=DatetimePickerAction(label="Date and Time", data="storeId=12345", mode="datetime")) ]))) elif '/youtube:' in text: text = text[9:].lstrip().rstrip() text = text.replace(' ','+') buttons_template = ButtonsTemplate( title='Here is your '+text, text='Youtube.com', actions=[ URIAction(label='Watch', uri ='https://www.youtube.com/results?search_query='+text), ]) template_message = TemplateSendMessage( alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif '/google:' in text: text = text[8:].lstrip().rstrip() text = text.replace(' ','+') buttons_template = ButtonsTemplate( title='Google search results', text='Google.com', actions=[ URIAction(label='Visit', uri ='https://www.google.com/search?q='+text), ]) template_message = TemplateSendMessage( alt_text='Buttons alt text', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message)
def handle_message(event): push_text = event.message.text text = quickstart.extract_words(push_text) if text is None: text_message = TextSendMessage( text="Googleカレンダーの予定を知りたいですか?それとも追加したいですか?", quick_reply=QuickReply(items=[ QuickReplyButton(action=DatetimePickerAction( label="予定を知りたい", data="read", mode="date")), QuickReplyButton( action=PostbackAction(label="予定を追加したい", data="write")) ])) line_bot_api.reply_message(event.reply_token, text_message) else: htmllink = quickstart.write(*text) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=htmllink))
def make_time_button(): buttons_template_message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( thumbnail_image_url='https://1.bp.blogspot.com/-RJRt_Hv37Kk/VMIu-CCBpII/AAAAAAAAq2E/JsIJ8pPwmuY/s400/calender_takujou.png', title='待ち合わせ日時', text='いつ集まりますか?', actions=[ DatetimePickerAction( label='設定する', data='hoge=1', mode='datetime' ), ] ) ) return buttons_template_message
def handle_message(event): if (event.message.text == "시간"): line_bot_api.reply_message( event.reply_token, TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( thumbnail_image_url='https://picsum.photos/300', title='시간 테스트', text='피커 구현', actions=[ DatetimePickerAction(label='datetime', display_text='datetime', data='datetime', mode="datetime"), URIAction(label='uri', uri='http://example.com/') ]))) elif event.message.text == "시험": line_bot_api.reply_message( event.reply_token, TextSendMessage(text='https://koreatech.herokuapp.com/')) elif event.message.text == "시험점수": line_bot_api.reply_message( event.reply_token, TextSendMessage(text='학번을 입력해주세요. ex) 학번 2016136113')) elif "학번" in event.message.text: temp = event.message.text.split(' ')[1] doc_ref = db.collection(u'test').document(temp) doc = doc_ref.get() if doc.exists: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=u'점수: {}'.format(doc.to_dict()))) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=u'형식에 맞추거나 학번을 다시 입력해주세요.')) else: # dialog 결과 전달 받기 [2] response = detect_intent_texts("test-dpu9", "connect_line", [event.message.text], "en-US") # 라인에 메세지 전달 [6] line_bot_api.reply_message(event.reply_token, TextSendMessage(text=response))
def buttons_templatenewdate(initial, max,min): buttons_template_message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( thumbnail_image_url='https://live.staticflickr.com/65535/50436378452_f0b97f86db_w.jpg', title='新增運動日誌', text='請選擇日期~٩(๑❛ᴗ❛๑)۶\n讀取日期需要一點時間,請稍後~', actions=[ DatetimePickerAction( label="運動日期", data="q1", mode="date", initial=initial, max=max, min=min )] ) ) return buttons_template_message
def after_goal_weight(event=None, line_bot_api=None): user_id = event.source.user_id _goal_weight = event.message.text repo.update_users(user_id, "goal_weight", _goal_weight) _text = "いつまでに目標を達成したいですか?" Session_interface.set_waiting_mode(user_id=user_id, mode=MODE.AFTER_GOAL_DATE) line_bot_api.push_message(user_id, TextSendMessage(text=_text, quick_reply=QuickReply( items=[ QuickReplyButton(action=DatetimePickerAction( label="日付を選んでね!", data=MODE.AFTER_GOAL_DATE.hash, mode="date", initial=dt.now().strftime("%Y-%m-%d"), min="2018-10-01", max="2018-12-31" )) ] )))
def button_change_yoyaku(label, yoyaku_id, day): get_day = datetime.datetime.now() if (get_day.hour + 9) > 18: get_date = str(get_day.year) + "-" + str( get_day.month).zfill(2) + "-" + str(get_day.day + 1).zfill(2) max_date = str(get_day.year) + "-" + str(get_day.month + 1).zfill( 2) + "-" + str(get_day.day + 1).zfill(2) else: get_date = str(get_day.year) + "-" + str( get_day.month).zfill(2) + "-" + str(get_day.day).zfill(2) max_date = str( get_day.year) + "-" + str(get_day.month + 1).zfill(2) + "-" + str( get_day.day).zfill(2) if day <= get_date: day = get_date message_template = TemplateSendMessage( alt_text="a", template=ButtonsTemplate( text=label, actions=[ DatetimePickerAction(type="datetimepicker", label="日付を変更する", data="change_yoyaku_day_" + str(yoyaku_id), mode="date", initial=day, max=max_date, min=get_date), PostbackAction(label="時刻を変更する", data="change_yoyaku_time_" + str(yoyaku_id)), PostbackAction(label="備考を修正する", data="change_yoyaku_note_" + str(yoyaku_id)), PostbackAction(label="予約状況一覧に戻る", data="cancel") ])) return message_template
def PostBack(event): with open('develop/Ancate_content.json') as f: data = json.loads(f.read()) with open('develop/quickreply.json') as f: data2 = f.read() USER = { 'Id': event.source.user_id, 'Name': line_bot_api.get_profile(event.source.user_id).display_name, 'reply_token': event.reply_token } messages = TextSendMessage( text='Sample', quick_reply=QuickReply(items=[ QuickReplyButton(action=MessageAction(label="label", text="text")), QuickReplyButton(action=CameraAction(label="Camera")), QuickReplyButton(action=LocationAction(label="Location")), QuickReplyButton(action=DatetimePickerAction( label="Datetime", mode="time", data="test")) ])) line_bot_api.push_message(USER['Id'], messages=messages) return
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 test_push_text_message_with_quick_reply(self): responses.add(responses.POST, LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/push', json={}, status=200) self.tested.push_message( 'to', TextSendMessage( text='Hello, world', quick_reply=QuickReply(items=[ QuickReplyButton(image_url='https://example.com', 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")), ]))) request = responses.calls[0].request self.assertEqual(request.method, 'POST') self.assertEqual( request.url, LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/message/push') self.assertEqual( json.loads(request.body), { "to": "to", "messages": [{ "type": "text", "text": "Hello, world", "quickReply": { "items": [ { "type": "action", "imageUrl": "https://example.com", "action": { "type": "postback", "label": "label1", "data": "data1", } }, { "type": "action", "action": { "type": "message", "label": "label2", "text": "text2", } }, { "type": "action", "action": { "type": "datetimepicker", "label": "label3", "data": "data3", "mode": "date", } }, { "type": "action", "action": { "type": "camera", "label": "label4", } }, { "type": "action", "action": { "type": "cameraRoll", "label": "label5", } }, { "type": "action", "action": { "type": "location", "label": "label6", } }, ] } }] })
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 setUp(self): self.tested = LineBotApi('channel_secret') self.button_template_message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( thumbnail_image_url='https://example.com/image.jpg', title='Menu', text='Please select', actions=[ PostbackAction(label='postback', text='postback text', data='action=buy&itemid=1'), MessageAction(label='message', text='message text'), URIAction(label='uri', uri='http://example.com/') ])) self.button_message = [{ "type": "template", "altText": "Buttons template", "template": { "type": "buttons", "thumbnailImageUrl": "https://example.com/image.jpg", "title": "Menu", "text": "Please select", "actions": [{ "type": "postback", "label": "postback", "text": "postback text", "data": "action=buy&itemid=1" }, { "type": "message", "label": "message", "text": "message text" }, { "type": "uri", "label": "uri", "uri": "http://example.com/" }] } }] self.confirm_template_message = TemplateSendMessage( alt_text='Confirm template', template=ConfirmTemplate(text='Are you sure?', actions=[ PostbackAction( label='postback', text='postback text', data='action=buy&itemid=1'), MessageAction(label='message', text='message text') ])) self.confirm_message = [{ "type": "template", "altText": "Confirm template", "template": { "type": "confirm", "text": "Are you sure?", "actions": [{ "type": "postback", "label": "postback", "text": "postback text", "data": "action=buy&itemid=1" }, { "type": "message", "label": "message", "text": "message text" }] } }] self.carousel_template_message = TemplateSendMessage( alt_text='Carousel template', template=CarouselTemplate(columns=[ CarouselColumn( thumbnail_image_url='https://example.com' '/item1.jpg', title='this is menu1', text='description1', actions=[ PostbackAction(label='postback1', text='postback text1', data='action=buy&itemid=1'), MessageAction(label='message1', text='message text1'), URIAction(label='uri1', uri='http://example.com/1') ]), CarouselColumn(thumbnail_image_url='https://example.com' '/item2.jpg', image_background_color='#000000', title='this is menu2', text='description2', actions=[ PostbackAction(label='postback2', text='postback text2', data='action=buy&itemid=2'), MessageAction(label='message2', text='message text2'), URIAction(label='uri2', uri='http://example.com/2') ]), CarouselColumn( thumbnail_image_url='https://example.com' '/item3.jpg', title='this is menu3', text='description3', actions=[ DatetimePickerAction( label="datetime picker date", data="action=sell&itemid=2&mode=date", mode="date", initial="2013-04-01", min="2011-06-23", max="2017-09-08"), DatetimePickerAction( label="datetime picker time", data="action=sell&itemid=2&mode=time", mode="time", initial="10:00", min="00:00", max="23:59"), DatetimePickerAction( label="datetime picker datetime", data="action=sell&itemid=2&mode=datetime", mode="datetime", initial="2013-04-01T10:00", min="2011-06-23T00:00", max="2017-09-08T23:59") ]) ])) self.carousel_message = [{ "type": "template", "altText": "Carousel template", "template": { "type": "carousel", "columns": [{ "thumbnailImageUrl": "https://example.com/item1.jpg", "title": "this is menu1", "text": "description1", "actions": [{ "type": "postback", "label": "postback1", "text": "postback text1", "data": "action=buy&itemid=1" }, { "type": "message", "label": "message1", "text": "message text1" }, { "type": "uri", "label": "uri1", "uri": "http://example.com/1" }] }, { "thumbnailImageUrl": "https://example.com/item2.jpg", "imageBackgroundColor": "#000000", "title": "this is menu2", "text": "description2", "actions": [{ "type": "postback", "label": "postback2", "text": "postback text2", "data": "action=buy&itemid=2" }, { "type": "message", "label": "message2", "text": "message text2" }, { "type": "uri", "label": "uri2", "uri": "http://example.com/2" }] }, { "thumbnailImageUrl": "https://example.com/item3.jpg", "title": "this is menu3", "text": "description3", "actions": [{ "type": "datetimepicker", "label": "datetime picker date", "data": "action=sell&itemid=2&mode=date", "mode": "date", "initial": "2013-04-01", "min": "2011-06-23", "max": "2017-09-08" }, { "type": "datetimepicker", "label": "datetime picker time", "data": "action=sell&itemid=2&mode=time", "mode": "time", "initial": "10:00", "min": "00:00", "max": "23:59" }, { "type": "datetimepicker", "label": "datetime picker datetime", "data": "action=sell&itemid=2&mode=datetime", "mode": "datetime", "initial": "2013-04-01T10:00", "min": "2011-06-23T00:00", "max": "2017-09-08T23:59" }] }], } }] self.image_carousel_template_message = TemplateSendMessage( alt_text='Image carousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn(image_url='https://example.com/' 'item1.jpg', action=PostbackAction( label='postback1', data='action=buy&itemid=1')), ImageCarouselColumn( image_url='https://example.com' '/item2.jpg', action=MessageAction(label='message2', text='message text2')), ImageCarouselColumn(image_url='https://example.com/' 'item3.jpg', action=URIAction( label='uri1', uri='https://example.com/1')) ])) self.image_carousel_message = [{ "type": "template", "altText": "Image carousel template", "template": { "type": "image_carousel", "columns": [{ "imageUrl": "https://example.com/item1.jpg", "action": { "type": "postback", "label": "postback1", "data": "action=buy&itemid=1", } }, { "imageUrl": "https://example.com/item2.jpg", "action": { "type": "message", "label": "message2", "text": "message text2" } }, { "imageUrl": "https://example.com/item3.jpg", "action": { "type": "uri", "label": "uri1", "uri": "https://example.com/1" } }] } }]
def handle_text_message(event): text = event.message.text profile = line_bot_api.get_profile(event.source.user_id) 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(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( text='hoge1', image_url='https://via.placeholder.com/1024x1024', action=DatetimePickerAction(label='datetime', data='datetime_postback', mode='datetime')), ImageCarouselColumn( text='hoge1', 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 == 'image': bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='http://gosehat.heroku.com/static/image/logo_new.png', 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='Tentang Aplikasi', 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= 'GoSehat merupakan aplikasi konsultasi kesehatan yang dibangun oleh :' '1. Arvianti Yulia Maulfa, 2. Entin Martiana Kusumaningtyas, 3. Fadilah Fahrul Hardiansyah ' '' # BoxComponent( # layout='baseline', # spacing='sm', # contents=[ # TextComponent( # text='GoSehat merupakan aplikasi konsultasi kesehatan yang dibangun oleh :' # '1. Arvianti Yulia Maulfa, 2. Entin Martiana Kusumaningtyas, 3. Fadilah Fahrul Hardiansyah ' # '', # 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.lower() == 'tentang aplikasi': url = request.url_root + '/static/image/tentang.png' app.logger.info("url=" + url) text = 'GoSehat merupakan aplikasi konsultasi kesehatan yang dibangun oleh:\n1. Arvianti Yulia Maulfa \n2. Entin ' \ 'Martiana Kusumaningtyas \n3. Fadilah Fahrul Hardiansyah\n' line_bot_api.reply_message(event.reply_token, [ ImageSendMessage(url, url), TextSendMessage(text=text), ]) elif text.lower() == 'informasi aplikasi': text = 'GoSehat adalah chatbot (aplikasi pintar) yang dapat digunakan untuk ' \ 'konsultasi kesehatan secara gratis! Anda dapat bertanya seputar kesehatan seperti pengobatan,' \ 'pencegahan, atau penyebab suatu penyakit. \n\nCukup kirim pesan apa yang ingin Anda tanyakan atau ' \ 'memilih menu yang tersedia ya.\ncontoh: "Saya sering mengalami pusing, mual, batuk. Saya ' \ 'sakit apa ?" atau menanyakan informasi seperti "Haloo, untuk obat maag apa ya?" \n\nTahapan pemakaian ' \ 'aplikasi GoSehat :\n1. Ketikkan pesan seperti pada contoh diatas atau pilih menu \n2. Anda bisa ' \ 'mengetikkan gejala untuk mendeteksi penyakit pada tubuh Anda\n3. Anda bisa mengetikkan nama penyakit ' \ 'untuk mengetahui jenis penyakit\n4. Tunggu hingga aplikasi memberikan Anda jawaban\n\nTetap jaga ' \ 'kesehatan ya!' line_bot_api.reply_message( event.reply_token, TextSendMessage(text=text), ) 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: conn = create_connection() cursor = conn.cursor() # set user_id dan profile (untuk nama) user_id = event.source.user_id name_user = line_bot_api.get_profile(event.source.user_id).display_name time = dt.datetime.now() if dt.datetime.now() < dt.datetime.now().replace( hour=12, minute=0, second=0) and dt.datetime.now() > dt.datetime.now().replace( hour=0, minute=0, second=0): salam = "Selamat Pagi " elif dt.datetime.now() > dt.datetime.now().replace( hour=12, minute=0, second=0) and dt.datetime.now() < dt.datetime.now().replace( hour=18, minute=0, second=0): salam = "Selamat Siang " elif dt.datetime.now() > dt.datetime.now().replace( hour=18, minute=0, second=0): salam = "Selamat Malam " else: salam = "Assalamualaikum " # MENU if text == '\informasi': messages = "Masukkan informasi yang ingin dicari.\nContoh : 'Apa penyakit maag ?'" save_menuinformasi(user_id, name_user, text, conn) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=(messages))) elif text == '\konsultasi': save_menukonsultasi(user_id, name_user, text, conn) messages = "Masukkan keluhan Anda.\nContoh : 'Saya merasa demam, mual pusing muntih. Saya sakit apa ?'" line_bot_api.reply_message(event.reply_token, TextSendMessage(text=(messages))) else: cursor.execute("SELECT status FROM menu WHERE id_user = '******'") count_menu = cursor.fetchall() # print("DEBUG> count menu = ", count_menu) if len(count_menu) != 0: if count_menu[0][0] == '\informasi': disease_id = 0 sinonim, penyakit, messages_info = get_info(text) if len(penyakit) == 0: messages = check_greeting(sinonim) save_history(user_id, name_user, text, messages, "", disease_id, time, conn) else: messages = salam + name_user + "\n" + messages_info[0][0] save_history(user_id, name_user, text, messages_info[0][0], "", disease_id, time, conn) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=(messages))) delete_menukonsultasi(user_id, conn) elif count_menu[0][0] == '\konsultasi': messages = message_bot(user_id, name_user, salam, text, time, conn) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=(messages))) delete_menukonsultasi(user_id, conn) else: decision = decide_process(text) print("DEBUG> pilihan = ", decision) if decision == "informasi": disease_id = 0 sinonim, penyakit, messages_info = get_info(text) if len(penyakit) == 0 and len(sinonim) <= 2: # gabung_sinonim = ' '.join(sinonim) messages = check_greeting(sinonim) save_history(user_id, name_user, text, messages, "", disease_id, time, conn) else: messages = salam + name_user for msg in messages_info: messages = messages + "\n\n" + msg[0][0] save_history(user_id, name_user, text, messages, "", disease_id, time, conn) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=(messages))) else: messages = message_bot(user_id, name_user, salam, text, time, conn) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=(messages))) delete_menukonsultasi(user_id, conn)
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 normal_mode(event, text, userid): try: for case in switch(text): if case('s'): #進入stock模式 users.objects.filter(uid=userid).update(chat_mode="stock") content = '進入股票模式,請輸入股票代碼:(離開模式輸入L或l)' LINE_BOT_API.reply_message(event.reply_token, TextSendMessage(text=content)) break if case('b'): #進入bullshit模式 #content = str(bullshit.bullshit()) users.objects.filter(uid=userid).update(chat_mode="bullshit") content = "進入唬爛模式\n請輸入主題名稱:(離開模式輸入L或l)" LINE_BOT_API.reply_message(event.reply_token, TextSendMessage(text=content)) break if case('g'): #進入gsheet模式 users.objects.filter(uid=userid).update(chat_mode="gsheet") content = '進入上傳模式,請輸入網址:(離開模式輸入L或l)' LINE_BOT_API.reply_message(event.reply_token, TextSendMessage(text=content)) break if case('hw'): #進入NTU hw 模式 users.objects.filter(uid=userid).update(chat_mode="gsheet_NTU") content = '進入上傳模式(NTU pyxl作業)\n請輸入網址:(離開模式輸入L或l)' LINE_BOT_API.reply_message(event.reply_token, TextSendMessage(text=content)) break if case('userid'): push_text(userid, "userid : " + event.source.user_id) push_text( 'U4f9b4c95fcee10fc8c72ad40cbef90ca', event.message.text + ", send by " + event.source.user_id) break if case('test'): push_text(userid, 'test') break if case( '肚子餓' ) and userid != 'U715b0aba205ddf78123b47ffb8f28f52': #如果是妹妹,就不能說不好的話 LINE_BOT_API.reply_message(event.reply_token, TextSendMessage(text='乾我什麼事')) break if case('變身'): push_image(userid, 'https://i.imgur.com/zTbh6K1.jpg', 'https://i.imgur.com/CNhnRs2.jpg') break if case('小火龍'): push_image(userid, 'https://i.imgur.com/zTbh6K1.jpg', 'https://i.imgur.com/zTbh6K1.jpg') break if case('等'): sleep(20) LINE_BOT_API.reply_message(event.reply_token, TextSendMessage(text='乾我什麼事')) break if case('q'): message = TextSendMessage( text=" i am bobo", quick_reply=QuickReply(items=[ QuickReplyButton( action=MessageAction(label='LOVE', text='LOVE')), QuickReplyButton( image_url="https://i.ibb.co/dJPnTr9/pika-icon.png", action={ "type": "message", "label": "Tempura", "text": "PIKACHU" }), QuickReplyButton( image_url="https://i.ibb.co/dJPnTr9/pika-icon.png", action={ "type": "message", "label": "Tempura", "text": "PIKACHU" }), QuickReplyButton(action={ "type": "camera", "label": "Camera" }), QuickReplyButton(action=DatetimePickerAction( label="depart date", data="data3", mode="date")), QuickReplyButton(action=DatetimePickerAction( label="depart time", data="data3", mode="time")) ])) LINE_BOT_API.reply_message(event.reply_token, message) break if case('push'): push_text('Udd66eba9352626779fee2fff43c79f82', 'i am bobo') #蕭瑞昕的ID break if case(): print(event.reply_token) reply_text(event, event.message.text) #回應同一個訊息 #LINE_BOT_API.push_message('U4f9b4c95fcee10fc8c72ad40cbef90ca', TextSendMessage(text=event.message.text+", send by "+event.source.user_id)) #LINE_BOT_API.reply_message(event.reply_token, TextSendMessage(text=event.message.text+'2')) break except Exception as e: print("exception") getException(e)
from linebot.models import RichMenu, RichMenuSize, RichMenuBounds, RichMenuArea, DatetimePickerAction, MessageAction import datetime milk_rich_menu = RichMenu( size=RichMenuSize(width=2500, height=843), selected=True, name="milk rich menu", chat_bar_text="Open Menu", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=1617, height=843), action=DatetimePickerAction(data="action=calc_month", mode="date", initial=str( datetime.date.today()))), RichMenuArea(bounds=RichMenuBounds(x=1617, y=0, width=2500 - 1617, height=843), action=MessageAction(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) ]) 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 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(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 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 == '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)