def handle_menu(event): bot_api.reply_message(event.reply_token, [ TextSendMessage(text=""" Welcome to MarketChat! You can choose what you want to do on the menu below. Happy shopping! :D If you are lost, you can type "menu" to view the menu again. """.strip()), TemplateSendMessage( alt_text='Main menu', template=ButtonsTemplate( title='What do you want to do?', text='Choose action:', actions=[ PostbackTemplateAction( label='Search Items', data=make_beacon('view_categories')), PostbackTemplateAction(label='Search Store', data=make_beacon('view_stores')), PostbackTemplateAction(label='View Transactions', data=make_beacon('status')), PostbackTemplateAction(label='Special Deals', data=make_beacon('special_deals')) ])) ]) return True
def sendCarousel(event): #轉盤樣板 try: message = TemplateSendMessage( alt_text='轉盤樣板', template=CarouselTemplate(columns=[ CarouselColumn( thumbnail_image_url='https://i.imgur.com/4QfKuz1.png', title='這是樣板一', text='第一個轉盤樣板', actions=[ MessageTemplateAction(label='文字訊息一', text='賣披薩'), URITemplateAction(label='連結文淵閣網頁', uri='http://www.e-happy.com.tw'), PostbackTemplateAction(label='回傳訊息一', data='action=sell&item=披薩'), ]), CarouselColumn( thumbnail_image_url='https://i.imgur.com/qaAdBkR.png', title='這是樣板二', text='第二個轉盤樣板', actions=[ MessageTemplateAction(label='文字訊息二', text='賣飲料'), URITemplateAction(label='連結台大網頁', uri='http://www.ntu.edu.tw'), PostbackTemplateAction(label='回傳訊息二', data='action=sell&item=飲料'), ]) ])) line_bot_api.reply_message(event.reply_token, message) except: line_bot_api.reply_message(event.reply_token, TextSendMessage(text='發生錯誤!'))
def sendCancel(event, user_id): #取消訂房 try: if booking.objects.filter(bid=user_id).exists(): #已有訂房記錄 bookingdata = booking.objects.get(bid=user_id) #讀取訂房資料 roomtype = bookingdata.roomtype amount = bookingdata.roomamount in_date = bookingdata.datein out_date = bookingdata.dateout text1 = "您預訂的房間資料如下:" text1 += "\n房間型式:" + roomtype text1 += "\n房間數量:" + amount text1 += "\n入住日期:" + in_date text1 += "\n退房日期:" + out_date message = [ TextSendMessage( #顯示訂房資料 text=text1), TemplateSendMessage( #顯示確認視窗 alt_text='取消訂房確認', template=ConfirmTemplate( text='你確定要取消訂房嗎?', actions=[ PostbackTemplateAction( #按鈕選項 label='是', data='action=yes'), PostbackTemplateAction(label='否', data='action=no') ])) ] else: #沒有訂房記錄 message = TextSendMessage(text='您目前沒有訂房記錄!') line_bot_api.reply_message(event.reply_token, message) except: line_bot_api.reply_message(event.reply_token, TextSendMessage(text='發生錯誤!'))
def send_central_divition_team(reply_token): message = TemplateSendMessage( alt_text='ImageCarousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://i.imgur.com/Vq9uSfw.png', action=PostbackTemplateAction( label='公鹿', text='bucks', data='action=buy&itemid=1')), ImageCarouselColumn( image_url='https://i.imgur.com/49Py8da.png', action=PostbackTemplateAction( label='溜馬', text='pacers', data='action=buy&itemid=2')), ImageCarouselColumn( image_url='https://i.imgur.com/ccm79f8.png', action=PostbackTemplateAction( label='活塞', text='pistons', data='action=buy&itemid=3')), ImageCarouselColumn( image_url='https://i.imgur.com/jgM2e8T.png', action=PostbackTemplateAction( label='公牛', text='bulls', data='action=buy&itemid=4')), ImageCarouselColumn( image_url='https://i.imgur.com/9j4vObi.png', action=PostbackTemplateAction( label='騎士', text='caveliers', data='action=buy&itemid=5')) ])) line_bot_api = LineBotApi(channel_access_token) line_bot_api.reply_message(reply_token, message) return "OK"
def send_northwest_divition_team(reply_token): message = TemplateSendMessage( alt_text='ImageCarousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://i.imgur.com/Za8Kg4H.png', action=PostbackTemplateAction( label='爵士', text='jazz', data='action=buy&itemid=1')), ImageCarouselColumn( image_url='https://i.imgur.com/2lUGdbv.png', action=PostbackTemplateAction( label='金塊', text='nuggets', data='action=buy&itemid=2')), ImageCarouselColumn( image_url='https://i.imgur.com/2ie9dVz.png', action=PostbackTemplateAction( label='雷霆', text='thunders', data='action=buy&itemid=3')), ImageCarouselColumn(image_url='https://i.imgur.com/ZZrjJed.png', action=PostbackTemplateAction( label='灰狼', text='timberwolves', data='action=buy&itemid=4')), ImageCarouselColumn(image_url='https://i.imgur.com/2rokfHw.png', action=PostbackTemplateAction( label='拓荒者', text='trail blazers', data='action=buy&itemid=5')) ])) line_bot_api = LineBotApi(channel_access_token) line_bot_api.reply_message(reply_token, message) return "OK"
def handle_message(event): # ルールベースで特定のキーワードに対応した回答をする if event.message.text == "おはよう": line_bot_api.reply_message(event.reply_token, TextSendMessage(text="おはようございます")) # カルーセルでの選択肢付き応答 elif event.message.text == "こんにちは": date_picker = TemplateSendMessage( alt_text='Selection Menu', template=ButtonsTemplate(text='次から選んでください', title='Option', actions=[ PostbackTemplateAction( label='日本語', data='action=click&itemid=1', ), PostbackTemplateAction( label='英語', data='action=click&itemid=2', ) ])) line_bot_api.reply_message(event.reply_token, date_picker) # おうむ返し else: line_bot_api.reply_message(event.reply_token, TextSendMessage(text=event.message.text))
def send_southwest_divition_team(reply_token): message = TemplateSendMessage( alt_text='ImageCarousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn(image_url='https://i.imgur.com/KfhWlHX.png', action=PostbackTemplateAction( label='獨行俠', text='mavericks', data='action=buy&itemid=1')), ImageCarouselColumn( image_url='https://i.imgur.com/MwZ7gOG.png', action=PostbackTemplateAction( label='灰熊', text='grizzles', data='action=buy&itemid=2')), ImageCarouselColumn( image_url='https://i.imgur.com/rSfD5It.png', action=PostbackTemplateAction( label='鵜鶘', text='pelicans', data='action=buy&itemid=3')), ImageCarouselColumn( image_url='https://i.imgur.com/VakO1Td.png', action=PostbackTemplateAction( label='火箭', text='rockets', data='action=buy&itemid=4')), ImageCarouselColumn( image_url='https://i.imgur.com/76CbfhM.png', action=PostbackTemplateAction( label='馬刺', text='spurs', data='action=buy&itemid=5')) ])) line_bot_api = LineBotApi(channel_access_token) line_bot_api.reply_message(reply_token, message) return "OK"
def sendCancel(event, user_id): #取消訂房 try: if teamUp.objects.filter(bid=user_id).exists(): #已有訂房記錄 teamUpdata = teamUp.objects.get(bid=user_id) #讀取訂房資料 place = teamUpdata.place amount = teamUpdata.amount timein = teamUpdata.timein text1 = "您的揪團資料如下:" text1 += "\n場地:" + place text1 += "\n人數:" + amount + " 人" text1 += "\n日期:" + timein.replace("T", "\n時間:") message = [ TextSendMessage( #顯示訂房資料 text=text1), TemplateSendMessage( #顯示確認視窗 alt_text='取消揪團確認', template=ConfirmTemplate( text='你確定要取消揪團嗎?', actions=[ PostbackTemplateAction( #按鈕選項 label='是', data='action=yes'), PostbackTemplateAction(label='否', data='action=no') ])) ] else: #沒有訂房記錄 message = TextSendMessage(text='您目前沒有揪團!') line_bot_api.reply_message(event.reply_token, message) except: line_bot_api.reply_message(event.reply_token,\ TextSendMessage(text='sendCancel發生錯誤!'))
def on_enter_female2(self, event): # index = 0 # s = "" # while index < 16: # s += str(female_uese[index]) + " " # index += 1 # reply_token = event.reply_token # send_text_message(reply_token,s) num1 = random.randint(0, 15) num2 = random.randint(0, 15) while female_uese[num1] != 2: num1 = random.randint(0, 15) while num1 == num2 or female_uese[num2] == -1: num2 = random.randint(0, 15) female_uese[num1] = -1 female_uese[num2] = -1 s1 = female_twitcher_name[num1] s2 = female_twitcher_name[num2] u1 = female_url[num1] u2 = female_url[num2] line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text="=========== 1/4 ==========="), TemplateSendMessage( alt_text='ImageCarousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url=u1, action=PostbackTemplateAction( label=s1, text=s1, data='action=buy&itemid=1')), ImageCarouselColumn( image_url=u2, action=PostbackTemplateAction( label=s2, text=s2, data='action=buy&itemid=2')) ])) ])
def __ranking(self): if self.__redis.exists('ranking'): self.__redis.expire('ranking', 86400) ranking = self.__redis.hkeys('ranking') if ranking: columns = [] for index in ranking: news = json.loads(self.__redis.hget('ranking', index)) columns.append( CarouselColumn(thumbnail_image_url=news['_News__url'], text=news['_News__title'], actions=[ PostbackTemplateAction(label='Read', data='@Read=' + str(index)), PostbackTemplateAction(label='Delete', data='@Delete=' + str(index)) ])) message = TemplateSendMessage( alt_text='Carousel template', template=CarouselTemplate(columns=columns)) else: message = TextSendMessage('Empty!') return message
def greate_buttontemplate(index_tmp): if ((int(index_tmp) >= 0) and ((len(question_list)) - index_tmp) >= 2): other_index = index_tmp + 2 buttons_template_message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( title='常見問題', text='請選擇以下問題,由小助手替您解答', actions=[ PostbackTemplateAction(label=question_list[0 + index_tmp], data=answer_list[0 + index_tmp]), PostbackTemplateAction(label=question_list[1 + index_tmp], data=answer_list[1 + index_tmp]), PostbackTemplateAction(label="其他", data=other_index) ])) elif ((index_tmp > 0) and ((len(question_list) - index_tmp) == 1)): buttons_template_message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( title='常見問題', text='請選擇以下問題,由小助手替您解答', actions=[ PostbackTemplateAction(label=question_list[0 + index_tmp], data=answer_list[0 + index_tmp]), PostbackTemplateAction(label="回到首頁", text="#問題", data=0) ])) else: buttons_template_message = TextSendMessage(text="請重新輸入 #問題") return buttons_template_message
def confirm(cls, line_bot, event, message, data): employee_id, patient_id = data['V'] patient = Patient.objects.get(pk=patient_id) text = '留言內容:\n%s' % message pass_context = '收到針對個案 %s 的留言訊息\n%s' % (patient.name, message) token = get_random_string(8) cache.set('_line:temp:%s:%s' % (event.source.user_id, token), (employee_id, pass_context), 3600) line_bot.reply_message( event.reply_token, TemplateSendMessage(alt_text='請使用手機檢視內容', template=ConfirmTemplate( text=text[:160], actions=[ PostbackTemplateAction( '確定', json.dumps({ 'T': T_SIMPLE_QUERY, 'stage': STAGE_PASS_NOTE, 'V': token })), PostbackTemplateAction( '重填', json.dumps({ 'T': T_SIMPLE_QUERY, 'stage': STAGE_SEND_NOTE, 'V': (employee_id, patient_id, token) })) ])))
def clean(cls, line_bot, event, patient_id): token = get_random_string(8) cache.set('_line:temp:%s:%s' % (event.source.user_id, token), patient_id, 300) line_bot.reply_message( event.reply_token, TemplateSendMessage(alt_text='確定清除留言板?', template=ConfirmTemplate( text='確定清除留言板?', actions=[ PostbackTemplateAction( '確定', json.dumps({ 'T': T_SIMPLE_QUERY, 'stage': STAGE_CLEAN_CONFIRM_NOTE, 'V': (token, True) })), PostbackTemplateAction( '取消', json.dumps({ 'T': T_SIMPLE_QUERY, 'stage': STAGE_CLEAN_CONFIRM_NOTE, 'V': (token, False) })) ])))
def confirm(cls, line_bot, event, message, data): patient_id = data['V'] text = '留言內容:\n%s' % message token = get_random_string(8) cache.set('_line:temp:%s:%s' % (event.source.user_id, token), (patient_id, message), 3600) line_bot.reply_message( event.reply_token, TemplateSendMessage(alt_text='請使用手機檢視內容', template=ConfirmTemplate( text=text[:160], actions=[ PostbackTemplateAction( '確定', json.dumps({ 'T': T_SIMPLE_QUERY, 'stage': STAGE_COMMIT_NOTE, 'V': token })), PostbackTemplateAction( '重填', json.dumps({ 'T': T_SIMPLE_QUERY, 'stage': STAGE_WRITE_NOTE, 'V': (patient_id, token) })) ])))
def get_movie_template(movie_id): if movie_id is None: return TextSendMessage(text="沒有這個電影耶~查查看別的吧!") movie_name = movie_dict[movie_id][0] movie_pic = movie_dict[movie_id][1] movie_url = detail_url_by_id + movie_id movie_trailer = get_trailer_url(movie_url) if movie_trailer is None: uri_template = URITemplateAction(type='uri', label='Picture', uri=movie_pic) else: uri_template = URITemplateAction(type='uri', label='Trailer', uri=movie_trailer) buttons_template = ButtonsTemplate( type='buttons', title=movie_name[0:40], text='Check out more information for the movie!', thumbnail_image_url=movie_pic, actions=[ PostbackTemplateAction(label='Movie Info', data='movie=%s&action=3&' % movie_id), PostbackTemplateAction(label='Movie Story', data='movie=%s&action=6&' % movie_id), uri_template, PostbackTemplateAction(label='Show Times', data='movie=%s&action=1&' % movie_id) ]) message = TemplateSendMessage(type='template', alt_text=movie_name, template=buttons_template) return message
def on_enter_male(self, event): global male_used num1 = random.randint(0, 15) num2 = random.randint(0, 15) while num1 == num2: num2 = random.randint(0, 15) male_used[num1] = -1 male_used[num2] = -1 s1 = male_twicher_name[num1] s2 = male_twicher_name[num2] u1 = male_url[num1] u2 = male_url[num2] line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text="=========== 1/8 ==========="), TemplateSendMessage( alt_text='ImageCarousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url=u1, action=PostbackTemplateAction( label=s1, text=s1, data='action=buy&itemid=1')), ImageCarouselColumn( image_url=u2, action=PostbackTemplateAction( label=s2, text=s2, data='action=buy&itemid=2')) ])) ])
def view_catalog(event, i_items, compare_id=None): bot_api.reply_message( event.reply_token, list( filter(None, [ TextSendMessage(text=""" Select item to compare with: """.strip()) if compare_id is not None else None, TemplateSendMessage( alt_text='Product list', template=CarouselTemplate(columns=[ CarouselColumn( thumbnail_image_url=item.image, text=f""" Rp {'{:,}'.format(item.price)},-{f" ({round(item.promo * 100)}% off)" if item.promo is not None else ""} """.strip(), title=item.name, actions=[ PostbackTemplateAction( label='Select', data=make_beacon('compare', id=[compare_id, i])), ] if compare_id is not None else [ PostbackTemplateAction( label='Buy', data=make_beacon('buy', id=i )), PostbackTemplateAction(label='Details', data=make_beacon( 'details', id=i)), PostbackTemplateAction(label='Compare', data=make_beacon( 'view', compare=i)) ]) for i, item in i_items ])) ])))
def final_ticket(line_bot, event, message, data): patient_id, catalog_id = data['V'] text = '詢問問題內容:\n%s' % message line_bot.reply_message( event.reply_token, TemplateSendMessage(alt_text='請使用手機檢視問題', template=ConfirmTemplate( text=text[:160], actions=[ PostbackTemplateAction( '確定', json.dumps({ 'T': T_PATIENT, 'stage': STAGE_SUBMIT, 'V': (patient_id, catalog_id, message) })), PostbackTemplateAction( '重填', json.dumps({ 'T': T_PATIENT, 'stage': STAGE_REPORT, 'V': (patient_id, catalog_id) })) ])))
def send_pacific_divition_team(reply_token): message = TemplateSendMessage( alt_text='ImageCarousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://i.imgur.com/NjIZPvy.png', action=PostbackTemplateAction( label='快艇', text='clippers', data='action=buy&itemid=1')), ImageCarouselColumn( image_url='https://i.imgur.com/hLTYqcQ.png', action=PostbackTemplateAction( label='國王', text='kings', data='action=buy&itemid=2')), ImageCarouselColumn( image_url='https://i.imgur.com/2zTrz4Z.png', action=PostbackTemplateAction( label='湖人', text='lakers', data='action=buy&itemid=3')), ImageCarouselColumn( image_url='https://i.imgur.com/6FdkdEf.png', action=PostbackTemplateAction( label='太陽', text='suns', data='action=buy&itemid=4')), ImageCarouselColumn( image_url='https://i.imgur.com/YRwCVJl.png', action=PostbackTemplateAction( label='勇士', text='warriors', data='action=buy&itemid=5')) ])) line_bot_api = LineBotApi(channel_access_token) line_bot_api.reply_message(reply_token, message) return "OK"
def CarouselTemplate_icook(RecipesInformation): CarouselTemplateList = [] for EachInformation in RecipesInformation: col = CarouselColumn( # 測試用(正式上線請註解) thumbnail_image_url=EachInformation[3], # request 自己用Flask架設的 Web server內的圖片位置 # thumbnail_image_url='https://cf3f3b7280ce.ngrok.io/picture?RecipeID={}'.format(RecipesInformation[0]), title=EachInformation[1], text='推薦適合您的食譜!', actions=[ URITemplateAction( label='前往觀看', uri='https://icook.tw/recipes/{}'.format(EachInformation[0]) ), PostbackTemplateAction( label='很普通🥱', data=str(EachInformation[0]) + '_1' ), PostbackTemplateAction( label='我很喜歡❤️', data=str(EachInformation[0]) + '_5' ) ] ) CarouselTemplateList.append(col) # 建立 Carousel Template(Message types) CarouseltemplateMessage = TemplateSendMessage( alt_text='Carousel template', template=CarouselTemplate(columns=CarouselTemplateList) ) return CarouseltemplateMessage
def send_atalantic_divition_team(reply_token): message = TemplateSendMessage( alt_text='ImageCarousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://i.imgur.com/hQV1mql.png', action=PostbackTemplateAction( label='暴龍', text='raptors', data='action=buy&itemid=1')), ImageCarouselColumn( image_url='https://i.imgur.com/MNlnQcA.png', action=PostbackTemplateAction( label='賽爾提克', text='celtics', data='action=buy&itemid=2')), ImageCarouselColumn( image_url='https://i.imgur.com/DPFhrrX.png', action=PostbackTemplateAction( label='76人', text='76ers', data='action=buy&itemid=3')), ImageCarouselColumn( image_url='https://i.imgur.com/vo4yWWw.png', action=PostbackTemplateAction( label='籃網', text='nets', data='action=buy&itemid=4')), ImageCarouselColumn( image_url='https://i.imgur.com/RMKhZxx.png', action=PostbackTemplateAction( label='尼克', text='knics', data='action=buy&itemid=5')) ])) line_bot_api = LineBotApi(channel_access_token) line_bot_api.reply_message(reply_token, message) return "OK"
def get_set_clock_msg(timer, number): #min=str(timer['min']) #sec=str(timer['sec']) now = str(number['now']) target = str(number['target']) timeTemplate = TemplateSendMessage( alt_text=' 設定計時器', template=ButtonsTemplate(title='目前設定為\n每號間隔 ' + str(timer) + ',由' + now + '號開始等到' + target + '號', text='利用下方按鍵開始設定\n設定完成請點選確定', actions=[ PostbackTemplateAction(label='設定時間', text='設定時間', data='time'), PostbackTemplateAction(label='設定號碼牌', text='設定號碼牌', data='number'), PostbackTemplateAction(label='確定送出', text='確定送出', data='send'), PostbackTemplateAction(label='返回', text='返回', data='back') ])) return timeTemplate
def send_southeast_divition_team(reply_token): message = TemplateSendMessage( alt_text='ImageCarousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://i.imgur.com/JlSkgo1.png', action=PostbackTemplateAction( label='熱火', text='heats', data='action=buy&itemid=1')), ImageCarouselColumn( image_url='https://i.imgur.com/ofJ4VgI.png', action=PostbackTemplateAction( label='魔術', text='magic', data='action=buy&itemid=2')), ImageCarouselColumn( image_url='https://i.imgur.com/qerCfYv.png', action=PostbackTemplateAction( label='黃蜂', text='hornets', data='action=buy&itemid=3')), ImageCarouselColumn( image_url='https://i.imgur.com/BE37OBk.png', action=PostbackTemplateAction( label='巫師', text='wizards', data='action=buy&itemid=4')), ImageCarouselColumn( image_url='https://i.imgur.com/QxmRbDF.png', action=PostbackTemplateAction( label='老鷹', text='hawks', data='action=buy&itemid=5')) ])) line_bot_api = LineBotApi(channel_access_token) line_bot_api.reply_message(reply_token, message) return "OK"
def get_set_clockCenter_msg(timer, isCounting): #min=str(timer['min']) #sec=str(timer['sec']) if (isCounting == True): counterBtn = PostbackTemplateAction(label='結束計時', text='結束計時', data='start') topic = '計時中,可按下「結束計時」以完成計時' else: counterBtn = PostbackTemplateAction(label='開始計時', text='開始計時', data='start') topic = '目前設定為\n每號間隔 ' + str(timer) timeTemplate = TemplateSendMessage( alt_text=' 設定時間', template=ButtonsTemplate(title=topic, text='利用下方按鍵開始設定\n設定完成請點選確定', actions=[ counterBtn, PostbackTemplateAction(label='直接輸入時間', text='直接輸入時間', data='input'), PostbackTemplateAction(label='返回', text='返回', data='back') ])) return timeTemplate
def carouselColumnMaker(index): carouselColumnElement = CarouselColumn( thumbnail_image_url=labImage[index], title=labMappingTable[index], text=labPro[index], actions=[ PostbackTemplateAction( label='有關指導教授', text=lab[index], data='notResponse' ), PostbackTemplateAction( label='有關實驗室', text=lab[index], data='notResponse' ), PostbackTemplateAction( label='有關合適的人選', text=lab[index], data='notResponse' ) ] ) return carouselColumnElement
def reply_template_carousel(reply_token, text, alt_text, id): line_bot_api = LineBotApi(setting.ACCESS_TOKEN) line_bot_api.reply_message(reply_token, [ TemplateSendMessage( alt_text=alt_text, template=CarouselTemplate([ CarouselColumn(text='星5', actions=[ PostbackTemplateAction(label='星5', data='5 ' + str(id)) ]), CarouselColumn(text='星4', actions=[ PostbackTemplateAction(label='星4', data='4 ' + str(id)) ]), CarouselColumn(text='星3', actions=[ PostbackTemplateAction(label='星3', data='3 ' + str(id)) ]), CarouselColumn(text='星2', actions=[ PostbackTemplateAction(label='星2', data='2 ' + str(id)) ]), CarouselColumn(text='星1', actions=[ PostbackTemplateAction(label='星1', data='1 ' + str(id)) ]), ])) ])
def composeConfirm(alt_text, text, option1, option2): if option1['type'] == "postback": opt1_payload = PostbackTemplateAction( label=option1['label'], # text=option1['text'], data=option1['data'] ) elif option1['type'] == "message": opt1_payload = MessageTemplateAction( label=option1['label'], text=option1['text'] ) if option2['type'] == "postback": opt2_payload = PostbackTemplateAction( label=option2['label'], # text=option2['text'], data=option2['data'] ) elif option2['type'] == "message": opt2_payload = MessageTemplateAction( label=option2['label'], text=option2['text'] ) payload = TemplateSendMessage( alt_text=alt_text, template=ConfirmTemplate( text=text, actions=[opt1_payload, opt2_payload] ) ) return payload
def handle_message(event): print("event =", event) if event.message.text == "查詢個人檔案": user_id = event.source.user_id profile = line_bot_api.get_profile(user_id, timeout=None) line_bot_api.reply_message(event.reply_token, TextMessage(text=str(profile), )) else: button_template_message = ButtonsTemplate( thumbnail_image_url="https://i.imgur.com/eTldj2E.png?1", title='Menu', text='Please select', image_size="cover", actions=[ # PostbackTemplateAction 點擊選項後, # 除了文字會顯示在聊天室中, # 還回傳data中的資料,可 # 此類透過 Postback event 處理。 PostbackTemplateAction(label='查詢個人檔案顯示文字-Postback', text='查詢個人檔案', data='action=buy&itemid=1'), PostbackTemplateAction(label='不顯示文字-Postback', text=None, data='action=buy&itemid=1'), MessageTemplateAction(label='查詢個人檔案-Message', text='查詢個人檔案'), ]) line_bot_api.reply_message( event.reply_token, TemplateSendMessage(alt_text="Template Example", template=button_template_message))
def get_participation_button(new_room_id): buttons_template_message = TemplateSendMessage( alt_text='インサイダーゲームを開始します。参加者はボタンを押してください。', template=ButtonsTemplate( title='インサイダーを開始します', text='参加者はボタンを押してください。', actions=[ PostbackTemplateAction( label='参加する(要:友達追加)', text='参加する', data=urlparse.urlencode({ 'room_id': new_room_id, 'next_action': 'get-participation' }) ), PostbackTemplateAction( label='参加を締め切る', text='参加を締め切る', data=urlparse.urlencode( { 'room_id': new_room_id, 'next_action': 'close' } ) ) ] ) ) return buttons_template_message
def push_turn_off_confirm(self): see_you_message = TextSendMessage("でかけるのですか?行ってらっしゃいませ。") environment_information = self.get_environment() information_message = TextSendMessage(environment_information) confirm_template_message = TemplateSendMessage( alt_text='エアコン消しておきますか?', template=ConfirmTemplate( text='エアコン消しておきますか?', actions=[ PostbackTemplateAction( label='承認', text='承認', data='ac_off_approval' ), PostbackTemplateAction( label='否認', text='否認', data='ac_off_disapproval' ) ] ) ) send_messages = [see_you_message, information_message, confirm_template_message] self.line_bot_api.push_message(self.my_line_user_id, send_messages) return True