def callback(): signature = request.headers['X-Line-Signature'] # get request body as text body = request.get_data(as_text=True) app.logger.info("Request body: " + body) # parse webhook body events = [] try: events = parser.parse(body, signature) except InvalidSignatureError: abort(400) for event in events: print("showing event") pprint.pprint(event) print("") if isinstance(event, MessageEvent): if isinstance(event.message, TextMessage): text = event.message.text if text in AREA_COUNT.keys(): line_bot_api.reply_message( event.reply_token, get_area_buttons_template_message(text) ) if text == "staff": get_richmenu() if text == "住所変更": line_bot_api.reply_message( event.reply_token, [ TextSendMessage(text="住所変更のFAQを表示します。"), ImageSendMessage(original_content_url="https://i.imgur.com/8uLNKdb.png", preview_image_url="https://i.imgur.com/8uLNKdbb.png") ] ) get_richmenu2() if text == "戻る": get_richmenu() if text == "delete richmenu": rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN) rmm.remove_all() post_text_to_db(event) # if isinstance(event.message, LocationMessage): # latitude = event.message.latitude # longtitude = event.message.longitude # line_bot_api.reply_message( # event.reply_token, # get_budget_buttons_template_message() # ) if isinstance(event, PostbackEvent): data_str = event.postback.data data_dict = dict(urlparse.parse_qsl(data_str)) try: next = data_dict['next'] except: next = '' if next == 'budget': line_bot_api.reply_message( event.reply_token, get_budget_buttons_template_message(data_dict) ) elif next == 'transportation': line_bot_api.reply_message( event.reply_token, get_transportation_buttons_template_message(data_dict) ) elif next == "show-result": print("showing result") places = get_places_by_nearby_search( data_dict['budget'], data_dict['transportation'], get_geocode(data_dict['area']) )["results"] result_count = len(places) nth_result = data_dict['nth-result'] start_index = int(nth_result) * 5 end_index = 5 + int(nth_result) * 5 second_message = get_additional_search_confirm_template(data_dict) if end_index >= result_count: end_index = result_count second_message = TextSendMessage( text='指定された条件でこれ以上の候補は見つかりませんでした。\n条件を変えて検索する場合は、下のボタンから現在地を入力してください。' ) if end_index % 5 is not 0: start_index = end_index - (end_index % 5) line_bot_api.reply_message( event.reply_token, [get_spot_carousels(places[start_index:end_index]), second_message] ) if "detail" in data_str: place_id = dict(urlparse.parse_qsl(data_str))['id'] place_detail = get_place_detail(place_id)['result'] messages = [] if 'phone' in data_str: messages = [TextSendMessage(text=place_detail['formatted_phone_number'])] line_bot_api.reply_message( event.reply_token, messages ) post_postback_to_db(event) return 'OK'
border_image_res = (2500, 1) border = Image.new('RGB', border_image_res, (2, 24, 255)) trigger_words = [ 'マイナンバー関連', '印鑑登録関連', '各種証明書', '4', '5', '6', '計測スタート', '計測終了' ] column_count = 4 row_count = 2 grid_width = int(small_image_res[0] / column_count) grid_height = math.ceil(small_image_res[1] / row_count) # Setup RichMenuManager rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN) print(rmm.get_list()) rmm.remove_all() # Setup RichMenu to register rm = RichMenu(name="menu_init", chat_bar_text="問い合わせ分類", size_full=False) for i, word in enumerate(trigger_words): img = Image.new('RGB', (grid_width, grid_height), (128, 128, 128)) text = f"{word}" draw_text_at_center(img, text) row, column = calculate_grid_position(i, column_count) x, y = get_position(row, column) canvas.paste(img, (x, y)) rm.add_area(x, y, grid_width, grid_height, "message", word) canvas.show()