def handle_message(event): global latest_image_path if event.reply_token == "00000000000000000000000000000000": return "OK" if event.message.text == 'ออกไปได้แล้ว': if isinstance(event.source,SourceGroup): if event.source.user_id == 'U991007deaa6c52bd776443e7d89f2032': line_bot_api.reply_message( event.reply_token, TextMessage(text='บะบายค่า') ) line_bot_api.leave_group(event.source.group_id) else: line_bot_api.reply_message( event.reply_token, TextMessage(text='ไม่!') ) if event.message.text == 'ราคาน้ำมัน': l = oil_price.get_prices() s = "" for p in l: s += "%s %.2f บาท\n"%(p[0],p[1]) line_bot_api.reply_message( event.reply_token, TextSendMessage(text=s)) elif event.message.text == 'วิเคราะห์รูป': line_bot_api.reply_message( event.reply_token, [ TextSendMessage(text='สักครู่ค่ะ') ]) # Process image try: lp = LicencePlate() result = lp.process(latest_image_path) s = lp.translate(result) line_bot_api.push_message( event.source.user_id, [ TextSendMessage(text = s) ]) except Exception as e: print('Exception:',type(e),e) line_bot_api.push_message( event.source.user_id,[ TextSendMessage(text='ไม่สามารถวิเคราะห์รูปได้') ]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text+'จ้า'))
def handle_message(event): if event.message.text == 'ราคาน้ำมัน': l = oil_price.get_prices() s = "" for p in l: s += "%s %.2f บาท\n" % (p[0], p[1]) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=s)) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text + ' จ้า'))
def handle_message(event): global latest_image_path # Handle webhook verification if event.reply_token == '00000000000000000000000000000000': return 'OK' if event.message.text == 'ไปไป': if isinstance(event.source, SourceGroup): if event.source.user_id == 'U7057b3026a468fa0e08f426388d98f70': line_bot_api.reply_message(event.reply_token, TextMessage(text='บรัย')) line_bot_api.leave_group(event.source.group_id) else: line_bot_api.reply_message(event.reply_token, TextMessage(text='ไม่!')) elif event.message.text == 'profile': user_id = event.source.user_id profile = line_bot_api.get_profile(user_id) # image_message = ImageSendMessage( # original_content_url=profile.picture_url, # preview_image_url=profile.picture_url # ) line_bot_api.reply_message( event.reply_token, [ TextSendMessage(text=profile.display_name), TextSendMessage(text=profile.user_id), TextSendMessage(text=profile.picture_url), TextSendMessage(text=profile.status_message), # image_message ]) if event.message.text == 'ราคาน้ำมัน': l = oil_price.get_prices() s = "" for p in l: s += "%s %.2f บาท\n" % (p[0], p[1]) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=s)) elif event.message.text == 'วิเคราะห์รูป': line_bot_api.reply_message(event.reply_token, [TextSendMessage(text='สักครู่ครับ')]) try: lp = LicencePlate() result = lp.process(latest_image_path) s = lp.translate(result) line_bot_api.push_message(event.source.user_id, [TextSendMessage(text=s)]) except Exception as e: print('Exception:', type(e), e) line_bot_api.push_message( event.source.user_id, [TextSendMessage(text='ไม่สามารถวิเคราะห์รูปได้')]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text + 'ขอรับ'))
def default_action(): l = oil_price.get_prices() s = "" for p in l: s += "%s %f บาท\n" % (p[0], p[1]) return s
def handle_message(event): global latest_image_path global reportList if event.reply_token == "00000000000000000000000000000000": return "OK" # saveToFirebase(event) #resume exiting print(conversation.keys()) uid = event.source.user_id if uid in conversation: intent = conversation[uid] o = intent.handle(event.message.text) line_bot_api.reply_message(event.reply_token, [TextSendMessage(text=o)]) if intent.endIntent(): output = intent.getData() print(output) saveFirebase(output, event.source.user_id) del conversation[uid] return userIntent = Intent.evaluateIntent(event.message.text) if uid in reportingUsers: if isinstance(userIntent, EndReportIntent): profile = line_bot_api.get_profile(uid) del reportingUsers[uid] line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='บันทึกเสร็จสิ้นค่ะ คุณ%s' % profile.display_name) ]) return catalog = reportingUsers[uid] saveToFirebase(catalog, event) print('Saving to firebase') return if isinstance(userIntent, StartReportIntent): profile = line_bot_api.get_profile(uid) dateStr = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') reportingUsers[uid] = "report-%s-%s" % (uid, dateStr) line_bot_api.reply_message(event.reply_token, [ TextSendMessage(text='กำลังจดบันทึกให้ค่ะ คุณ%s' % profile.display_name) ]) return # rego = None if uid in conversation: rego = conversation[uid] else: rego = keepdata() conversation[uid] = rego o = rego.handle(event.message.text) line_bot_api.reply_message(event.reply_token, [TextSendMessage(text=o)]) if isinstance(userIntent, ViewReportIntent): id = int(userIntent.id) print('id:', id) (uid, dateStr) = reportList[id - 1] d, t = dateStr.split() (ye, mo, da) = d.split('-') (h, m, s) = t.split(':') key = 'report-%s-%s-%s-%s-%s-%s-%s' % (uid, ye, mo, da, h, m, s) print('Key:', key) report = Report.viewReport(key) line_bot_api.reply_message(event.reply_token, [TextSendMessage(text=report)]) return if isinstance(userIntent, ListReportIntent): reportList = Report.listReports() s = 'รายงานทั้งหมด\n' i = 1 for r in reportList: (uid, dateStr) = r profile = line_bot_api.get_profile(uid) s += "%d: %s (%s)\n" % (i, profile.display_name, dateStr) i += 1 line_bot_api.reply_message(event.reply_token, [TextSendMessage(text=s)]) return if event.message.text == 'ออกไปได้แล้ว': if isinstance(event.source, SourceGroup): if event.source.user_id == 'U991007deaa6c52bd776443e7d89f2032': line_bot_api.reply_message(event.reply_token, TextMessage(text='บะบายค่า')) line_bot_api.leave_group(event.source.group_id) else: line_bot_api.reply_message(event.reply_token, TextMessage(text='ไม่!')) if event.message.text == 'ราคาน้ำมัน': l = oil_price.get_prices() s = "" for p in l: s += "%s %.2f บาท\n" % (p[0], p[1]) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=s)) elif event.message.text == 'วิเคราะห์รูป': line_bot_api.reply_message(event.reply_token, [TextSendMessage(text='สักครู่ค่ะ')]) # Process image try: lp = LicencePlate() result = lp.process(latest_image_path) s = lp.translate(result) line_bot_api.push_message(event.source.user_id, [TextSendMessage(text=s)]) except Exception as e: print('Exception:', type(e), e) line_bot_api.push_message( event.source.user_id, [TextSendMessage(text='ไม่สามารถวิเคราะห์รูปได้')]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text + 'จ้า'))
def handle_message(event): global latest_image_path # Handle webhook verification if event.reply_token == "00000000000000000000000000000000": return saveToFirebase(event) # Resume existing intent print(conversation.keys()) uid = event.source.user_id if uid in conversation: intent = conversation[uid] o = intent.handle(event.message.text) line_bot_api.reply_message(event.reply_token, [TextSendMessage(text=o)]) if intent.endIntent(): output = intent.getData() print(output) del conversation[uid] return if event.message.text == 'register': uid = event.source.user_id rego = None if uid in conversation: rego = conversation[uid] else: rego = Registration() conversation[uid] = rego o = rego.handle(event.message.text) line_bot_api.reply_message(event.reply_token, [TextSendMessage(text=o)]) elif event.message.text == 'ออกไปได้แล้ว': if isinstance(event.source, SourceGroup): if event.source.user_id == 'U53199750dbac026a2bd87a094472ddf1': line_bot_api.reply_message(event.reply_token, TextMessage(text='บะบายค่า')) line_bot_api.leave_group(event.source.group_id) else: line_bot_api.reply_message(event.reply_token, TextMessage(text='ไม่!')) elif event.message.text == 'profile': user_id = event.source.user_id profile = line_bot_api.get_profile(user_id) # image_message = ImageSendMessage( # original_content_url=profile.picture_url, # preview_image_url=profile.picture_url # ) line_bot_api.reply_message( event.reply_token, [ TextSendMessage(text=profile.display_name), TextSendMessage(text=profile.user_id), TextSendMessage(text=profile.picture_url), TextSendMessage(text=profile.status_message), # image_message ]) elif event.message.text == 'ราคาน้ำมัน': l = oil_price.get_prices() s = "" for p in l: s += "%s %.2f บาท\n" % (p[0], p[1]) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=s)) elif event.message.text == 'วิเคราะห์รูป': line_bot_api.reply_message(event.reply_token, [TextSendMessage(text='สักครู่ค่ะ')]) # Process image try: lp = LicencePlate() result = lp.process(latest_image_path) s = lp.translate(result) line_bot_api.push_message(event.source.user_id, [TextSendMessage(text=s)]) except Exception as e: print('Exception:', type(e), e) line_bot_api.push_message( event.source.user_id, [TextSendMessage(text='ไม่สามารถวิเคราะห์รูปได้ค่ะ-')]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text + 'จ้า'))
def handle_message(event): global latest_image_path if event.reply_token == "00000000000000000000000000000000": return "OK" saveToFirebase(event) #resume exiting print(conversation.keys()) uid = event.source.user_id if uid in conversation: intent = conversation[uid] o = intent.handle(event.message.text) line_bot_api.reply_message(event.reply_token, [TextSendMessage(text=o)]) if intent.endIntent(): output = intent.getData() print(output) saveFirebase(output, event.source.user_id) del conversation[uid] return if event.message.text == 'result': uid = event.source.user_id rego = None if uid in conversation: rego = conversation[uid] else: rego = keepdata() conversation[uid] = rego o = rego.handle(event.message.text) line_bot_api.reply_message(event.reply_token, [TextSendMessage(text=o)]) if event.message.text == 'ออกไปได้แล้ว': if isinstance(event.source, SourceGroup): if event.source.user_id == 'U991007deaa6c52bd776443e7d89f2032': line_bot_api.reply_message(event.reply_token, TextMessage(text='บะบายค่า')) line_bot_api.leave_group(event.source.group_id) else: line_bot_api.reply_message(event.reply_token, TextMessage(text='ไม่!')) if event.message.text == 'ราคาน้ำมัน': l = oil_price.get_prices() s = "" for p in l: s += "%s %.2f บาท\n" % (p[0], p[1]) line_bot_api.reply_message(event.reply_token, TextSendMessage(text=s)) elif event.message.text == 'วิเคราะห์รูป': line_bot_api.reply_message(event.reply_token, [TextSendMessage(text='สักครู่ค่ะ')]) # Process image try: lp = LicencePlate() result = lp.process(latest_image_path) s = lp.translate(result) line_bot_api.push_message(event.source.user_id, [TextSendMessage(text=s)]) except Exception as e: print('Exception:', type(e), e) line_bot_api.push_message( event.source.user_id, [TextSendMessage(text='ไม่สามารถวิเคราะห์รูปได้')]) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text + 'จ้า'))