def callback(): data = request.json eventType = request.headers.get('X-Github-Event') if eventType == 'create': # seseorang sedang membuat branch baru di remote repo if data['ref_type'] == 'branch': refMaster = data['master_branch'] refName = data['ref'] actor = data['sender']['login'] refLink = data['repository']['html_url'] message = actor + " telah membuat branch baru namanya " + refName + " dari branch " + refMaster + " : " + refLink + "/tree/" + refName line_bot_api.push_message(app.config["roomId"], TextSendMessage(text=message)) elif eventType == 'pull_request': # seseorang sedang melakukan pull request if data['action'] == 'opened': link = data['pull_request']['html_url'] headRepo = data['pull_request']['head']['ref'] baseRepo = data['pull_request']['base']['ref'] actor = data['sender']['login'] message = "si " + actor + " udah bikin pull request dari " + headRepo + " ke " + baseRepo + ", tolong di review ya, ini link nya " + link line_bot_api.push_message(app.config["roomId"], TextSendMessage(text=message)) elif eventType == 'repository': if data['action'] == 'unarchived': repoName = data['repository']['name'] repoLink = data['repository']['html_url'] message = "Alhamdulillah ya repository " + repoName + " udah aktif lagi, yuk kita berkontribusi lagi. cek linknya di + " + repoLink line_bot_api.push_message(app.config["roomId"], TextSendMessage(text=message)) elif data['action'] == 'archived': repoName = data['repository']['name'] repoLink = data['repository']['html_url'] message = "ALERT\nRepository " + repoName + " telah diarchive, tapi masih bisa diakses kok.\n makasih ya udah bersama-sama berkontribusi di repo tersebut. cek linknya di " + repoLink line_bot_api.push_message(app.config["roomId"], TextSendMessage(text=message)) elif eventType == 'pull_request_review': if data['action'] == 'submitted': repoName = data['repository']['name'] prName = data['pull_request']['title'] prReviewLink = data['review']['html_url'] message = "Ada review tuh buat Pull Request + " + prName + " di Repository " + repoName + ", yang bersangkutan jangan lupa cek ya di " + prReviewLink line_bot_api.push_message(app.config["roomId"], TextSendMessage(text=message)) else: print(eventType + " belum ada handlernya ih") return "OK", 200
def replyText(event): if event.source.user_id == "Uf4a596a6eb65eabf52c003ffe325a21d": try: img_url = google_search(event.message.text) print(img_url) line_bot_api.reply_message( event.reply_token, ImageSendMessage(original_content_url=img_url, preview_image_url=img_url)) except: #hello_text = echo(event.message.text) line_bot_api.push_message('Uf4a596a6eb65eabf52c003ffe325a21d', TextSendMessage(text='沒找到'))
def reply_text_and_get_user_profile(event): # 取出消息內User的資料 profile = line_bot_api.get_profile(event.source.user_id) # 將用戶資訊存在檔案內 with open("./users.txt", "a") as myfile: myfile.write(json.dumps(vars(profile), sort_keys=True)) myfile.write('\r\n') # 將菜單綁定在用戶身上 linkRichMenuId = secretFileContentJson.get("rich_menu_id") linkResult = line_bot_api.link_rich_menu_to_user(event.source.user_id, linkRichMenuId) # 對新關注用戶傳送文字訊息 Follow1_message = json.load( open("../Json_message/Follow1", 'r', encoding="utf-8")) Follow2_message = json.load( open("../Json_message/Follow2", 'r', encoding="utf-8")) Follow1_demo = TextSendMessage.new_from_json_dict(Follow1_message) Follow2_demo = TextSendMessage.new_from_json_dict(Follow2_message) line_bot_api.push_message(event.source.user_id, Follow1_demo) line_bot_api.push_message(event.source.user_id, Follow2_demo)
def timed_job(): msg = connectDB.showAds() print(msg) line_bot_api.push_message("Uf4a596a6eb65eabf52c003ffe325a21d", TextSendMessage(text=str(msg)))
def handle_message(event): profile = line_bot_api.get_profile(event.source.user_id) # 使用者資訊 msg = str(event.message.text).upper().strip() # 使用者輸入的內容 utterance = luis(msg) # Luis 自然語言處理語句 uid = profile.user_id # 發訊者ID Timestamp = calendar.timegm(time.gmtime()) Name = profile.display_name Pic = profile.picture_url dict = { "Name": Name, "Picture": Pic, "UserID": uid, "Msg": msg, 'Timestamp': Timestamp } # 透過回傳至kafka dict可再後端進行分析/調整模型 main_api(dict) # 針對圖文選單所觸發文字進行回復 動作或是文字訊息 if re.match('威士忌推薦', msg): line_bot_api.push_message(uid, quickReplyTextSendMessage) elif re.match('調酒推薦', msg): line_bot_api.push_message(uid, cocktailTextSendMessage) # 文字觸發 推播 Liff 嵌入式網頁 #未來展望:取得jquery +評論+liff.profile資訊+更多功能 elif re.match('酒吧地圖', msg): buttons_template = ButtonsTemplate( title='親愛的使用者', text='請點選下表連結到酒吧', actions=[ uid, URIAction(label="將為您提供酒吧地圖", uri="https://liff.line.me/1654667223-V7pklmP5") ]) template_message = TemplateSendMessage(alt_text='將為您提供酒吧地圖', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif re.match('尋找酒友', msg): buttons_template = ButtonsTemplate( title='親愛的使用者', text='請點選下表連結到聊天室', actions=[ uid, URIAction(label="將為您提供酒友聊天室", uri="https://liff.line.me/1654667223-3aR1lyPv") ]) template_message = TemplateSendMessage(alt_text='將為您提供酒友聊天室', template=buttons_template) line_bot_api.reply_message(event.reply_token, template_message) elif re.match('關鍵字查詢', msg): line_bot_api.push_message(uid, TextSendMessage("請再輸入任意風味或酒名關鍵字")) elif re.match('熱門排行', msg): line_bot_api.push_message(uid, TextSendMessage("將為您提供熱門排行前五名")) Pop_message = json.load( open("./app/Json_message/popular", 'r', encoding="utf-8")) Pop_demo = FlexSendMessage.new_from_json_dict(Pop_message) line_bot_api.push_message(uid, Pop_demo) elif re.match('好酒貪杯', msg): IOT_message = json.load( open("./app/Json_message/Drink", 'r', encoding="utf-8")) IOT_demo = TemplateSendMessage.new_from_json_dict(IOT_message) line_bot_api.push_message(uid, IOT_demo) elif re.match('倒酒動作', msg): line_bot_api.push_message(uid, TextSendMessage("正在進行倒酒動作")) elif re.match('取消動作', msg): line_bot_api.push_message(uid, TextSendMessage("已為您取消動作")) elif re.match('資策會_EB102_愛心組', msg): line_bot_api.push_message(uid, TextSendMessage("https://ibar3.webnode.tw/")) # 針對調酒風味re.match 文字訊息 作出reply elif re.match("風味:圓熟", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦圓熟調酒......")) Mellow_message = json.load( open("./cocktail_flavor/Mellow", 'r', encoding="utf-8")) Mellow_demo = FlexSendMessage.new_from_json_dict(Mellow_message) line_bot_api.push_message(uid, Mellow_demo) elif re.match("風味:經典", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦經典調酒......")) Classic_message = json.load( open("./cocktail_flavor/Classic", 'r', encoding="utf-8")) Classic_demo = FlexSendMessage.new_from_json_dict(Classic_message) line_bot_api.push_message(uid, Classic_demo) elif re.match("風味:獨創", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦獨創調酒......")) Original_message = json.load( open("./cocktail_flavor/Original", 'r', encoding="utf-8")) Original_demo = FlexSendMessage.new_from_json_dict(Original_message) line_bot_api.push_message(uid, Original_demo) elif re.match("風味:草藥", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦草藥味調酒......")) herbal_message = json.load( open("./cocktail_flavor/herbal", 'r', encoding="utf-8")) herbal_demo = FlexSendMessage.new_from_json_dict(herbal_message) line_bot_api.push_message(uid, herbal_demo) elif re.match("風味:甜", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦甜味調酒......")) Sweet_message = json.load( open("./cocktail_flavor/Sweet", 'r', encoding="utf-8")) Sweet_demo = FlexSendMessage.new_from_json_dict(Sweet_message) line_bot_api.push_message(uid, Sweet_demo) elif re.match("風味:酸", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦酸味調酒......")) Sour_message = json.load( open("./cocktail_flavor/Sour", 'r', encoding="utf-8")) Sour_demo = FlexSendMessage.new_from_json_dict(Sour_message) line_bot_api.push_message(uid, Sour_demo) elif re.match("風味:苦甜", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦苦甜味調酒......")) Bittersweet_message = json.load( open("./cocktail_flavor/Bittersweet", 'r', encoding="utf-8")) Bittersweet_demo = FlexSendMessage.new_from_json_dict( Bittersweet_message) line_bot_api.push_message(uid, Bittersweet_demo) elif re.match("風味:細緻", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦細緻味調酒......")) light_message = json.load( open("./cocktail_flavor/light", 'r', encoding="utf-8")) light_demo = FlexSendMessage.new_from_json_dict(light_message) line_bot_api.push_message(uid, light_demo) elif re.match("風味:和諧", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦和諧味調酒......")) Balanced_message = json.load( open("./cocktail_flavor/Balanced", 'r', encoding="utf-8")) Balanced_demo = FlexSendMessage.new_from_json_dict(Balanced_message) line_bot_api.push_message(uid, Balanced_demo) elif re.match("風味:柑橘", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦柑橘味調酒......")) Orange_message = json.load( open("./cocktail_flavor/Orange", 'r', encoding="utf-8")) Orange_demo = FlexSendMessage.new_from_json_dict(Orange_message) line_bot_api.push_message(uid, Orange_demo) elif re.match("風味:水果香", msg): # line_bot_api.push_message(uid, TextSendMessage("將為您推薦果香味調酒......")) Fruity_message = json.load( open("./cocktail_flavor/Fruity", 'r', encoding="utf-8")) Fruity_demo = FlexSendMessage.new_from_json_dict(Fruity_message) line_bot_api.push_message(uid, Fruity_demo) # 關鍵字搜尋,先進行酒名關鍵字查詢、再進行風味tag搜尋之後才進行OLAMI模組回復使用者 # 先透過關鍵字名稱找尋有無相關data 若無再利用標籤查詢data 再沒有則利用olami查詢是否有相關AI數據庫資訊 else: try: data = name_api(msg) flexSendMessage1 = FlexSendMessage.new_from_json_dict(data) line_bot_api.push_message(uid, TextSendMessage("請稍等…將為您進行搜尋")) line_bot_api.push_message(uid, flexSendMessage1) except IndexError: data2 = tag_api(utterance) if not len(data2['contents']['contents']) == 0: flexSendMessage2 = FlexSendMessage.new_from_json_dict(data2) line_bot_api.push_message(uid, TextSendMessage("請稍等…將為您進行搜尋")) line_bot_api.push_message(uid, flexSendMessage2) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=Olami().nli(event.message.text)))