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 La taille de l'image (pixels) ne prend en charge que les éléments suivants 2500x1686, 2500x843, 1200x810, 1200x405, 800x540, 800x270
chat_bar_text S'affiche dans la barre de chat comme indiqué ci-dessous
areas Définissez ** RichMenuArea ** pour chaque bouton de la plage d'action
RichMenuArea
-Bunds: Spécifiez la plage:
-Action: Spécifier l'action
create rich menu API Appelez l'API et créez un menu riche
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)
** Obtenez une liste de menus riche ** Obtenez la liste qui contient l'ID de menu enrichi
rich_menu_list = line_bot_api.get_rich_menu_list()
** Supprimer le menu riche ** Spécifiez l'ID de menu enrichi à supprimer
line_bot_api.delete_rich_menu(rich_menu.rich_menu_id)
[LINE Developers] Utiliser des menus riches
Recommended Posts