【LINE Messaging API】Python으로 리치 메뉴를 작성
                                            
                                                
                                                
                                                
                                                
                                                
                                                 11651 단어  FlaskLine파이썬LINEmessagingAPIlinebot
                    
리치 메뉴를 만드는 단계
 
createRichmenu.pydef 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
 1. 리치 메뉴 이미지 세부정보 정의
# 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)
 크기
화상 사이즈(pixels)는 이하만 대응
2500x1686, 2500x843, 1200x810, 1200x405, 800x540, 800x270
chat_bar_text
아래 그림과 같이 채팅바에 표시
 
 지역
action 범위를 각 버튼에 대해 RichMenuArea 설정
・bunds: 범위 지정 :
· 액션 : 액션 지정
create rich menu API
API를 호출하고 리치 메뉴 만들기
richMenuId = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create)
 2. 리치 메뉴 이미지 업로드
# 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)
 3. 리치 메뉴를 기본값으로 설정
# set the default rich menu
    line_bot_api.set_default_rich_menu(richMenuId)
이것으로 리치 메뉴 설정이 완료됩니다.
 기타 API
리치 메뉴 목록 얻기
리치 메뉴 ID가 저장된 목록을 가져옵니다.
rich_menu_list = line_bot_api.get_rich_menu_list()
리치 메뉴 삭제
삭제할 리치 메뉴 ID 지정
line_bot_api.delete_rich_menu(rich_menu.rich_menu_id)
 인용
 【LINE Developers】리치 메뉴 사용
Reference
                            
                            이 문제에 관하여(【LINE Messaging API】Python으로 리치 메뉴를 작성), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/yuj/items/44080e2d95d962b6ac43
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
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)
・bunds: 범위 지정 :
· 액션 : 액션 지정
create rich menu API
API를 호출하고 리치 메뉴 만들기
richMenuId = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create)
2. 리치 메뉴 이미지 업로드
# 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)
3. 리치 메뉴를 기본값으로 설정
# set the default rich menu
    line_bot_api.set_default_rich_menu(richMenuId)
이것으로 리치 메뉴 설정이 완료됩니다.
기타 API
리치 메뉴 목록 얻기
리치 메뉴 ID가 저장된 목록을 가져옵니다.
rich_menu_list = line_bot_api.get_rich_menu_list()
리치 메뉴 삭제
삭제할 리치 메뉴 ID 지정
line_bot_api.delete_rich_menu(rich_menu.rich_menu_id)
인용
 【LINE Developers】리치 메뉴 사용
Reference
이 문제에 관하여(【LINE Messaging API】Python으로 리치 메뉴를 작성), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/yuj/items/44080e2d95d962b6ac43텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)