def choose_settings(event): user = LineFriend.objects.get(line_user_id=event.source.user_id) line_bot_api.reply_message( event.reply_token, TemplateSendMessage(alt_text='設定', template=ButtonsTemplate( title='設定', text='変更したい設定を選択してください。', actions=[ PostbackAction( label='記事へのコメントの通知設定', display_text='記事へのコメントの通知設定', data='article_comment_settings', ), PostbackAction( label='質問へのコメントの通知設定', display_text='質問へのコメントの通知設定', data='answer_settings', ), PostbackAction( label='ポジション設定', display_text='ポジション設定', data='change_position', ), ])))
def answer_settings(event): user = LineFriend.objects.get(line_user_id=event.source.user_id) if user.notify_answer: text_on = '通知をON(現在のまま)' text_off = '通知をOFF' elif not user.notify_answer: text_on = '通知をON' text_off = '通知をOFF(現在のまま)' line_bot_api.reply_message( event.reply_token, TemplateSendMessage(alt_text='LINE通知設定', template=ButtonsTemplate( title='質問への回答・コメント通知設定', text='質問への回答やコメントの通知設定を変更しますか?', actions=[ PostbackAction( label=text_on, display_text=text_on, data='notify_answer=True', ), PostbackAction( label=text_off, display_text=text_off, data='notify_answer=False', ), ])))
def change_position(event): user = LineFriend.objects.get(line_user_id=event.source.user_id) line_bot_api.reply_message( event.reply_token, TemplateSendMessage(alt_text='ポジション設定', template=ButtonsTemplate( title='ポジション設定', text='あなたのポジションを選択してください。', actions=[ PostbackAction( label='インターン生', display_text='インターン生', data='is_intern=True', ), PostbackAction( label='質問回答担当', display_text='質問回答担当', data='is_answerer=True', ), PostbackAction( label='その他', display_text='その他', data='position=others', ), ])))
def handle_message(event): REPLY_TOKEN = event.reply_token USER_ID = PUSH_REPLY_ID = event.source.user_id if event.source.type == 'room': PUSH_REPLY_ID = event.source.room_id elif event.source.type == 'group': PUSH_REPLY_ID = event.source.group_id LINE_USER = LineProfile.objects.get(line_id=USER_ID) txt = event.message.text.strip() if txt == 'プロフィール': reply = TemplateSendMessage( alt_text='プロフィール', template=ButtonsTemplate( thumbnail_image_url=LINE_USER.line_icon_url, title=LINE_USER.line_name, text='hello world!', image_aspect_ratio='square', actions=[ MessageAction(label='ok', text='success'), URIAction( label='login', uri='https://calliope-sample-portfolio.herokuapp.com/') ], ), ) else: reply = [TextSendMessage(text=txt * 2)] line_bot_api.reply_message(REPLY_TOKEN, reply)
def process_single_line(commands: list): """單行查詢 Args: commands: 包含查詢內容的列表 """ user_guide = TemplateSendMessage( alt_text='''電腦版無法顯示按紐,按鈕功能只是舉例,實際使用上請自行替換 查群規: 貓 群規 查名字: 貓 小貓貓 查遊戲維基網址: 貓 光炮 查遊戲內物品資料: 貓 光炮 21''', template=ButtonsTemplate( text='簡單功能介紹', actions=[ MessageAction(label='查群規', text='貓 群規'), MessageAction(label='查名字', text='貓 小貓貓'), MessageAction(label='查遊戲內物品資料', text='貓 光炮 21'), MessageAction(label='查一段等級之間經驗', text='貓 計算經驗\n光炮 1 0 21\n守衛 3 20 21') ] ) ) if len(commands) == 1: if commands[0] == '群規': return database.get_rules() if commands[0] == '執法者': return database.group_data['admin'] if commands[0] == '使用說明': return user_guide try: name = database.correct(commands[0]) except ValueError: name = commands[0] return generate_url(name) if commands[0] == '群規': try: return database.get_rules(int(commands[1])) except ValueError as error: print(error) return '' if commands[1] == '圖片': try: name = database.correct(commands[0]) except ValueError: pass if database.item_data[name]['type'] != 'node': return database.get_picture(name, 0) try: name = database.correct(commands[0]) level = int(commands[1]) database.verify_input(name, level, level) except ValueError as error: pass else: return database.item_data[name]['data'][level]['data_string'] return ''
def on_enter_success_player(self, event): message = TemplateSendMessage(alt_text='Buttons template', template=ButtonsTemplate( text='Success', actions=[ MessageAction(label='check', text='check'), ])) line_bot_api.reply_message(event.reply_token, message)
def generate_button_message(text, thumbnail_image_url, actions=sample_actions): """ :param actions: Action when tapped. Max: 4 :type actions: list[T <= :py:class:`linebot.models.template.TemplateAction`] """ button_template = ButtonsTemplate(text=text, thumbnail_image_url=thumbnail_image_url, actions=actions) button_message = TemplateSendMessage(alt_text='Buttons alt text', template=button_template) return (button_message)
def story_board(self, text): return { 'menu': TemplateSendMessage( alt_text='ButtonsTemplate', template=ButtonsTemplate( title='ごみ出しメニュー', text=text if text else '選択して下さい', actions=[ PostbackAction(label='今日のごみ出し', data=json.dumps({ 'model': 'trash', 'scene': 'result', 'process': { 'handle': 'what_day_of_garbage_is_today' } })), PostbackAction(label='戻る', data=json.dumps({ 'model': 'main_menu', 'scene': 'menu' })) ])), 'result': TemplateSendMessage(alt_text='ButtonsTemplate', template=ButtonsTemplate( title='ごみ出しメニュー', text=text if text else '取得できませんでした', actions=[ PostbackAction(label='戻る', data=json.dumps({ 'model': 'trash', 'scene': 'menu' })) ])) }
def on_enter_enter_player(self, event): #message = TextSendMessage(text='Enter player number') #line_bot_api.reply_message(event.reply_token, message) message = TemplateSendMessage(alt_text='Buttons template', template=ButtonsTemplate( title='安安你好', text='Please select', actions=[ MessageAction(label='增加球員', text='add_player'), MessageAction(label='開始比賽', text='game'), ])) line_bot_api.reply_message(event.reply_token, message)
def on_enter_statistic(self, event): #message = TextSendMessage(text='Enter player number') #line_bot_api.reply_message(event.reply_token, message) message = TemplateSendMessage(alt_text='Buttons template', template=ButtonsTemplate( title='安安你好', text='Please select', actions=[ MessageAction(label='兩分球出手', text='twopt'), MessageAction(label='三分球出手', text='threept'), MessageAction(label='罰球出手', text='freept'), MessageAction(label='籃板球', text='rebound'), ])) line_bot_api.reply_message(event.reply_token, message)
def story_board(self, text): return { 'menu': TemplateSendMessage(alt_text='ButtonsTemplate', template=ButtonsTemplate( title='勤怠メニュー', text=text if text else '選択して下さい', actions=[ URIAction(uri='line://app/<LIFF URL>', label='勤怠入力'), PostbackAction(label='戻る', data=json.dumps({ 'model': 'main_menu', 'scene': 'menu' })) ])) }
def on_enter_freeptmiss(self, event): now = 0 for i in range(len(player_num)): if player_num[i].number == CurrentPlayer[len(CurrentPlayer) - 1].number: player_num[i].free_miss += 1 now = i print("Number %d miss free %d times" % (CurrentPlayer[len(CurrentPlayer) - 1].number, player_num[now].free_miss)) message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( text="No.%d miss %d 1pt" % (CurrentPlayer[len(CurrentPlayer) - 1].number, player_num[now].free_miss), actions=[ MessageAction(label='check', text='check'), ])) line_bot_api.reply_message(event.reply_token, message)
def can_choose_date(self): return TemplateSendMessage( alt_text="提醒小幫手", template=ButtonsTemplate( title="提醒事項", text="請選擇想提醒的時間", actions=[ DatetimePickerAction( label="選擇時間", data= "type={type}&action=add_to_reminder&tz={tz}&text={text}" .format( type=self.type, tz=self.wrapper_data_instance.tz, text=self.wrapper_data_instance.text, ), mode="datetime", ) ], ), )
def on_enter_DRebound(self, event): now = 0 for i in range(len(player_num)): if player_num[i].number == CurrentPlayer[len(CurrentPlayer) - 1].number: player_num[i].DRebound += 1 print(player_num[i].DRebound) now = i print("Number %d made one %d times" % (CurrentPlayer[len(CurrentPlayer) - 1].number, player_num[now].DRebound)) message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( text="No.%d made %d DReb" % (CurrentPlayer[len(CurrentPlayer) - 1].number, player_num[now].DRebound), actions=[ MessageAction(label='check', text='check'), ])) line_bot_api.reply_message(event.reply_token, message)
def process_text_message(event): if event.message.text == "我要看美女": page = random.randint(0,5) ptt_beauty = Beauty(page) title, sex_url, img = ptt_beauty.random_get_beautiful_lady() buttons_template_message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( text=title, actions=[ { "type": "uri", "label": title, "uri": sex_url } ], ) ) result_message_array = [ ImageSendMessage(original_content_url=img, preview_image_url=img), buttons_template_message ] line_bot_api.reply_message( event.reply_token, result_message_array ) else: # 讀取本地檔案,並轉譯成消息 result_message_array =[] replyJsonPath = "素材/"+event.message.text+"/reply.json" result_message_array = detect_json_array_to_new_message_array(replyJsonPath) # 發送 line_bot_api.reply_message( event.reply_token, result_message_array )
def story_board(self, text): return { 'menu': TemplateSendMessage(alt_text='ButtonsTemplate', template=ButtonsTemplate( title='メインメニュー', text=text if text else '選択して下さい', actions=[ PostbackAction(label='勤怠メニュー', data=json.dumps({ 'model': 'clock_in', 'scene': 'menu' })), PostbackAction(label='ごみ出しメニュー', data=json.dumps({ 'model': 'trash', 'scene': 'menu' })), PostbackAction(label='(工事中)クーポンメニュー', data=json.dumps({ 'model': 'coupon', 'scene': 'menu' })), PostbackAction(label='(工事中)自然言語メニュー', data=json.dumps({ 'model': 'talk', 'scene': 'menu' })) ])) }
def handle_message(event): text = event.message.text if text == 'start': start_menu = ButtonsTemplate( title = u'店舗管理メニュー', text = u'操作を選んでください', actions=[ PostbackTemplateAction(label=u'登録/修正', data='edit', text=u'編集したい商品を選んでください。'), PostbackTemplateAction(label=u'確認', data='confirm',text=u'お客様から見たBotのプレビューです。')] ) template_message = TemplateSendMessage( alt_text='Buttons alt text', template=start_menu ) line_bot_api.reply_message(event.reply_token, template_message) elif text == u'編集したい商品を選んでください。': pass elif text == u'お客様から見たBotのプレビューです。': pass else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=u'"start"と入力してください。') ) # get user_id from event uId = event.source.user_id print(uId) #get profile from user_id profile = line_bot_api.get_profile(uId) print(profile.display_name) print(profile.user_id) print('reply to text message') line_bot_api.push_message(profile.user_id, TextSendMessage(text='Bello!'))
TextSendMessage(text="哈囉!😊歡迎加入信手卡來,我們提供關於信用卡💳的各種資訊,歡迎點擊您有興趣的功能喔!😄"), ImageSendMessage(original_content_url='https://i.imgur.com/YXXiCvZ.jpg', preview_image_url='https://i.imgur.com/Zs6btto.jpg'), ImageSendMessage(original_content_url='https://i.imgur.com/x0vZwjt.jpg', preview_image_url='https://i.imgur.com/GEVyxIt.jpg') ] # 預測額度流程 reply_message_list_predict = [ TextSendMessage(text="想知道您的核卡額度?🤔輸入下列訊息,我們就會幫您預測喔!😉"), TemplateSendMessage(alt_text='Buttons template', template=ButtonsTemplate( title='信用卡核卡額度', text='輸入訊息,開始預測', actions=[{ "type": "uri", "label": "開始預測", "uri": "line://app/1653471513-2vnJK4EJ" }], )) ] # 新聞推薦流程 reply_message_list_news = [ TextSendMessage( text= "您想知道哪一類的信用卡相關資訊呢?點選下方按鈕或是輸入@加上您感興趣的內容,例如:@我想知道2020最強神卡,我們就會提供相關訊息給您🙂" ), ImagemapSendMessage( base_url='https://i.imgur.com/Ohn59DU.png#', alt_text='新聞推薦',
def handle_message(event): # 當接收到「求職指南」後秀出Button Template if event.message.text == "求職指南": line_bot_api.reply_message( event.reply_token, TemplateSendMessage(alt_text='求職指南', template=ButtonsTemplate(title='求職類相關書籍', text='請選擇您想觀看的部分', actions=[ { "type": "postback", "label": "求職新書", "text": "求職新書", "data": "Book&new" }, { "type": "postback", "label": "求職暢銷書", "text": "求職暢銷書", "data": "Book&famous" }, ]))) # 當接收到「產業新聞﹞後秀出Button Template if event.message.text == "產業新聞": line_bot_api.reply_message( event.reply_token, TemplateSendMessage(alt_text='產業新聞', template=ButtonsTemplate(title='產業新聞', text='請選擇您想觀看的新聞分類', actions=[{ "type": "postback", "label": "製造業新聞", "text": "製造業新聞", "data": "News&6" }, { "type": "postback", "label": "服務業新聞", "text": "服務業新聞", "data": "News&7" }, { "type": "postback", "label": "金融業新聞", "text": "金融業新聞", "data": "News&8" }, { "type": "postback", "label": "科技業新聞", "text": "科技業新聞", "data": "News&9" }]))) # 當接收到「履歷推薦」後秀出連結網址 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ user_profile = line_bot_api.get_profile(event.source.user_id) if event.message.text == "履歷推薦": # 將user_id寫入資料庫 user_id = user_profile.user_id line_bot_api.reply_message( event.reply_token, TextSendMessage(text="http://54.95.77.137:5050/")) conn = connectDB() cur = None if conn is not None: cur = conn.cursor() if cur is not None: sql = 'INSERT INTO `project`.`line_user_id` (`user_id`) VALUES ("{}")'.format( user_id) cur.execute(sql) conn.commit() # 當接收到「推薦結果」後秀出Carousel Template if event.message.text == "推薦結果": recommend_carousel_template_message = recommend() line_bot_api.reply_message(event.reply_token, recommend_carousel_template_message)
abort(400) return 'OK' buttons_template_message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( thumbnail_image_url='<image url>', title='Menu', text='Please select', actions=[ PostbackTemplateAction( label='postback', text='同時也可以讓用戶發送文字訊息', data='action=buy&itemid=1' ), MessageTemplateAction( label='message', text='資策會聊天機器人' ), URITemplateAction( label='uri', uri='https://www.youtube.com/' ) ] ) ) @handler.add(MessageEvent, message=TextMessage) def handle_message(event): line_bot_api.reply_message( event.reply_token,
# In[ ]: from linebot.models import ( TemplateSendMessage, CarouselTemplate, CarouselColumn, PostbackTemplateAction, MessageTemplateAction, URIAction,URITemplateAction ) from linebot.models.template import( ButtonsTemplate ) camp_search_buttons_template_message = TemplateSendMessage( alt_text = '?�地?��?', template = ButtonsTemplate( title = '?�地?��?', text = '請選?�地?��?尋or條件?��???, actions = [ { "type": "uri", "label": "?��??��?", "uri": "https://is.gd/9yCgXX" },{ "type": "postback", "label": "條件?��?", "text": "[::text:]條件?��?", "data": "資�? 2" } ] ) )
try: handler.handle(body, signature) except InvalidSignatureError: abort(400) return 'OK' buttons_template_message = TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( thumbnail_image_url='https://<ngrok>.ap.ngrok.io/images/eddie.jpg', title='Menu', text='Please select', actions=[ PostbackTemplateAction(label='postback', text='讓用戶發送文字訊息', data='action=buy&itemid=1'), MessageTemplateAction(label='message', text='聊天機器人'), URITemplateAction(label='uri', uri='https://www.youtube.com/') ])) @handler.add(MessageEvent, message=TextMessage) def handle_message(event): line_bot_api.reply_message(event.reply_token, buttons_template_message) if __name__ == "__main__": app.run(host='0.0.0.0')