def get_richmenu2(): rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN) rm_name_and_id = get_rm_name_and_id(rmm) menu_name_to_get = "Menu2" if menu_name_to_get in rm_name_and_id.keys(): richmenu_id = rm_name_and_id[menu_name_to_get] print("found {}".format(menu_name_to_get)) else: rm = RichMenu(name=menu_name_to_get, chat_bar_text="住所変更", size_full=False) rm.add_area(0, 0, 625, 421, "message", "転出") rm.add_area(625, 0, 625, 421, "message", "転入(国内)") rm.add_area(1875, 422, 625, 421, "message", "戻る") rm.add_area(1250, 422, 625, 421, "message", "delete richmenu") # Register res = rmm.register(rm, "./menu_images/4x2.png") richmenu_id = res["richMenuId"] print("Registered as " + richmenu_id) # Apply to user user_id = "U0a028f903127e2178bd789b4b4046ba7" rmm.apply(user_id, richmenu_id)
def get_richmenu(): rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN) rm_name_and_id = get_rm_name_and_id(rmm) menu_name_to_get = "Menu1" if menu_name_to_get in rm_name_and_id.keys(): richmenu_id = rm_name_and_id[menu_name_to_get] print("found {}".format(menu_name_to_get)) else: rm = RichMenu(name="Menu1", chat_bar_text="問い合わせカテゴリー", selected=True) rm.add_area(0, 0, 1250, 843, "message", "住所変更") rm.add_area(1250, 0, 1250, 843, "uri", "http://www.city.tsukuba.lg.jp/index.html") rm.add_area(0, 843, 1250, 843, "postback", "data1=from_richmenu&data2=as_postback") rm.add_area(1250, 843, 1250, 843, "postback", ["data3=from_richmenu_with&data4=message_text", "ポストバックのメッセージ"]) # Register res = rmm.register(rm, "./menu_images/4x2.png") richmenu_id = res["richMenuId"] print("Registered as " + richmenu_id) # Apply to user user_id = "U0a028f903127e2178bd789b4b4046ba7" rmm.apply(user_id, richmenu_id) # Check res = rmm.get_applied_menu(user_id) print(user_id + ":" + res["richMenuId"])
from richmenu import RichMenu, RichMenuManager # Setup RichMenuManager channel_access_token = 'MRxgDT2kynXriL1fXUHC7yY6FRx0A8sYBhTqsAl6wL0UYoMLt2d+T9QEwPq0ySiwBMnwMFb8Hkf23Z8lmsaqzEfkKH188hrlhIDCp6+hIFDQBTutt5sNhheL2+VVALeTHHHVnabxRQPdo3WPAJyZLwdB04t89/1O/w1cDnyilFU=' rmm = RichMenuManager(channel_access_token) # Setup RichMenu to register rm = RichMenu(name="Test menu", chat_bar_text="押してぽん!") rm.add_area(0, 0, 1250, 843, "message", "新しいリマインダ") rm.add_area(1250, 0, 1250, 843, "message", "一覧を見る") rm.add_area(0, 843, 1250, 843, "message", "おはよう") rm.add_area(1250, 843, 1250, 843, "message", "リマインダヌキ") # Register res = rmm.register(rm, "./image/menu2.png") richmenu_id = res["richMenuId"] print("Registered as " + richmenu_id) # Apply to user user_id = "LINE_MID_TO_APPLY" rmm.apply(user_id, richmenu_id) #check res = rmm.get_applied_menu(user_id) print(user_id + ":" + richmenu_id)
""" Usage of RichMenu Manager """ from richmenu import RichMenu, RichMenuManager # Setup RichMenuManager channel_access_token = "YOUR_CHANNEL_ACCESS_TOKEN" rmm = RichMenuManager(channel_access_token) # Setup RichMenu to register rm = RichMenu(name="Test menu", chat_bar_text="Open this menu") rm.add_area(0, 0, 1250, 843, "message", "テキストメッセージ") rm.add_area(1250, 0, 1250, 843, "uri", "http://imoutobot.com") rm.add_area(0, 843, 1250, 843, "postback", "data1=from_richmenu&data2=as_postback") rm.add_area(1250, 843, 1250, 843, "postback", ["data3=from_richmenu_with&data4=message_text", "ポストバックのメッセージ"]) # Register res = rmm.register(rm, "/path/to/menu.png") richmenu_id = res["richMenuId"] print("Registered as " + richmenu_id) # Apply to user user_id = "LINE_MID_TO_APPLY" rmm.apply(user_id, richmenu_id) # Check res = rmm.get_applied_menu(user_id) print(user_id + ":" + res["richMenuId"]) # # Others # res = rmm.get_list() # rmm.download_image(richmenu_id, "/path/to/downloaded_image.png") # res = rmm.detach(user_id)
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() canvas.save('richmenu_init.jpg', 'JPEG', quality=100, optimize=True) res = rmm.register(rm, "./richmenu_init.jpg")
line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN) handler = WebhookHandler(YOUR_CHANNEL_SECRET) # rich menu setting rmm = RichMenuManager(YOUR_CHANNEL_ACCESS_TOKEN) image0 = "static/images/menu0.png" image1 = "static/images/menu1.png" image2 = "static/images/menu2.png" image3 = "static/images/menu3.png" # all rich menu deleate rmm.remove_all() # menu0 rm = RichMenu(name="Test menu", chat_bar_text="menu 0") rm.add_area(0, 0, 2500, 843, "message", "マグロ") rm.add_area(0, 843, 830, 840, "message", "捕獲") rm.add_area(833, 843, 830, 840, "uri", LIFF_URL) rm.add_area(1666, 843, 830, 840, "message", "マグロ一丁") res = rmm.register(rm, image0) richmenu_id0 = res["richMenuId"] print(res) # menu1 rm = RichMenu(name="Test menu", chat_bar_text="menu 1") rm.add_area(0, 0, 2500, 843, "message", "マグロ") rm.add_area(0, 843, 830, 840, "message", "捕獲") rm.add_area(833, 843, 830, 840, "uri", LIFF_URL) rm.add_area(1666, 843, 830, 840, "message", "マグロ一丁") res = rmm.register(rm, image1)