createRichmenu.py
def createRichmenu():
result = False
try:
# define a new richmenu
rich_menu_to_create = RichMenu(
size = RichMenuSize(width=1200, height=405),
selected = True,
name = 'richmenu for randomchat',
chat_bar_text = 'TAP HERE',
areas=[
RichMenuArea(
bounds=RichMenuBounds(x=0, y=0, width=480, height=405),
action=MessageAction(text=config.REMOVE)
),
RichMenuArea(
bounds=RichMenuBounds(x=480, y=0, width=720, height=405),
action=MessageAction(text=config.NEXT)
)
]
)
richMenuId = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create)
# upload an image for rich menu
path = 'image path for richmenu'
with open(path, 'rb') as f:
line_bot_api.set_rich_menu_image(richMenuId, "image/jpeg", f)
# set the default rich menu
line_bot_api.set_default_rich_menu(richMenuId)
result = True
except Exception:
result = False
return result
# define a new richmenu
rich_menu_to_create = RichMenu(
size = RichMenuSize(width=1200, height=405),
selected = True,
name = 'richmenu for randomchat',
chat_bar_text = 'TAP HERE',
areas=[
RichMenuArea(
bounds=RichMenuBounds(x=0, y=0, width=480, height=405),
action=MessageAction(text=config.REMOVE)
),
RichMenuArea(
bounds=RichMenuBounds(x=480, y=0, width=720, height=405),
action=MessageAction(text=config.NEXT)
)
]
)
richMenuId = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create)
size Image size (pixels) supports only the following 2500x1686, 2500x843, 1200x810, 1200x405, 800x540, 800x270
chat_bar_text Displayed in the chat bar as shown below
areas Set ** RichMenuArea ** for each button in the action range
RichMenuArea
-Bunds: Specify range:
・ Action: Specify action
create rich menu API Call API and create rich menu
richMenuId = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create)
# upload an image for rich menu
path = 'image path for richmenu'
with open(path, 'rb') as f:
line_bot_api.set_rich_menu_image(richMenuId, "image/jpeg", f)
# set the default rich menu
line_bot_api.set_default_rich_menu(richMenuId)
** Get rich menu list ** Get the list that contains the rich menu ID
rich_menu_list = line_bot_api.get_rich_menu_list()
** Remove rich menu ** Specify the rich menu ID to delete
line_bot_api.delete_rich_menu(rich_menu.rich_menu_id)
[LINE Developers] Use rich menus
Recommended Posts