def create_rich_menu(): rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=1686), selected=False, name="pocket_health", chat_bar_text="服務選單", areas=[ RichMenuArea( bounds=RichMenuBounds(x=0, y=0, width=1250, height=843), action=PostbackAction(label='postback', data='richmenu_chronic')), RichMenuArea( bounds=RichMenuBounds(x=1250, y=0, width=1250, height=843), action=PostbackAction(label='postback', data='richmenu_goodbody')), RichMenuArea( bounds=RichMenuBounds(x=0, y=843, width=1250, height=843), action=PostbackAction(label='postback', data='richmenu_health')), RichMenuArea( bounds=RichMenuBounds(x=1250, y=843, width=1250, height=843), action=PostbackAction(label='postback', data='richmenu_supply')) ] ) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) print(rich_menu_id) with open("rich-menu-id.txt", "a+") as fp: fp.write(rich_menu_id)
def create_rich_menu(): result = False try: # define a new rich menu rich_menu_to_create = RichMenu( size=RichMenuSize(width=1200, height=405), selected=True, name='RichMenu for j-bot', chat_bar_text='TAP HERE', areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=500, height=405), action=URIAction( label='Open Google Map', uri='https://www.google.co.jp/maps/?hl=ja')), RichMenuArea(bounds=RichMenuBounds(x=480, y=0, width=700, height=405), action=MessageAction(text='Menu 2')) ]) rich_menu_id = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) # upload an image for rich menu path = '../static/rich_menu/rich_menu_sample.png' with open(path, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id, "image/png", f) # set the default rich menu line_bot_api.set_default_rich_menu(rich_menu_id) result = True except Exception: result = False return result
def get_menu(self, index=MAIN_MENU): login_kwargs = {'eid': self.line_channel_membership.url_safe_uuid} return RichMenu( size=RichMenuSize(width=1000, height=315), selected=True, name="Menu", chat_bar_text="Start", areas=[ RichMenuArea( bounds=RichMenuBounds(x=15, y=8, width=300, height=300), action=PostbackAction(label='Call', data='action=place_call') # action=URIAction(label='Call', uri=f'tel:{self.line_channel.shop.contact_phone_number}') ), RichMenuArea( bounds=RichMenuBounds( x=300 + 33 + 15, y=8, width=300, height=300), action=URIAction( label='Order', uri= f'https://{HOSTNAME}{self.shop.menu.get_absolute_url()}?{urlencode(login_kwargs)}' )), RichMenuArea( bounds=RichMenuBounds( x=600 + 67 + 15, y=8, width=300, height=300), action=URIAction( label='Preferences', uri= f'https://{HOSTNAME}{self.shop.get_absolute_url()}?{urlencode(login_kwargs)}' )), ])
def generate_rich_menu(request: HttpRequest) -> HttpResponse: rich_menu = RichMenu( size=RichMenuSize(width=2500, height=1686), selected=False, name="Nice richmenu", chat_bar_text="點擊選單", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=833, height=843), action=URIAction( label='我要預約', uri='https://liff.line.me/1654335010-n02repwV', )), RichMenuArea(bounds=RichMenuBounds(x=0, y=843, width=833, height=843), action=PostbackAction( label='查詢預約', text='查詢預約', data='check_reservation', )), RichMenuArea(bounds=RichMenuBounds(x=833, y=843, width=833, height=843), action=PostbackAction( label='課程介紹', text='課程介紹', data='introduce_course', )), RichMenuArea(bounds=RichMenuBounds(x=1666, y=843, width=833, height=843), action=PostbackAction( label='常見問題', text='常見問題', data='common_questions', )), RichMenuArea(bounds=RichMenuBounds(x=1666, y=0, width=833, height=843), action=URIAction( label='諮詢客服', uri='http://line.me/ti/p/@t0927899899')) ]) rich_menu_id = line_bot_api.create_rich_menu(rich_menu) with open('/home/hsintian/linebot/rich_menu.png', 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id, 'image/png', f) return HttpResponse("<h1 style='color:blue'>rich_menu: " + rich_menu_id + "</h1>")
def handle_follow(event): current_app.logger.debug("event: " + str(event)) rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=1686), selected=False, name="Nice richmenu", chat_bar_text="Tap here", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=2500, height=1686), action=URIAction(label='Go to line.me', uri='https://line.me')) ]) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) path = './rich_menu.jpg' content_type = 'image/jpeg' with open(path, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id, content_type, f) line_bot_api.link_rich_menu_to_user('all', rich_menu_id) line_bot_api.reply_message(event.reply_token, TextSendMessage(text="follow"))
def setUp(self): self.tested = LineBotApi('channel_secret') self.rich_menu_id = 'richmenu-0000000000' self.user_id = 'userid' self.rich_menu = RichMenu( size=RichMenuSize( width=2500, height=1686 ), selected=False, name="nice richmenu", chatBarText="touch me", areas=[ RichMenuArea( RichMenuBounds( x=0, y=0, width=833, height=843 ), URITemplateAction( uri='line://nv/location' ) ) ] )
def handle_message(event): rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name="Nice richmenu", chat_bar_text="Tap here", areas=[RichMenuArea( bounds=RichMenuBounds(x=0, y=0, width=2500, height=1686), action=URIAction(label='Go to line.me', uri='https://line.me'))] ) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) print(rich_menu_id) with open(path, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id, "image/png", f) start = time() # texts = sc.get_message(event.message.text) texts = "広報ちゃんβは広報ちゃんに移行しました。\nこれからはこちらをご利用ください\n\nhttps://lin.ee/2bnkBnx\n\n{}".format(rich_menu_id) if sc.is_str(texts): line_bot_api.reply_message( event.reply_token, TextSendMessage(text=texts)) else: x = [] for t in texts: x.append(TextSendMessage(text=t)) line_bot_api.reply_message( event.reply_token, x ) elapsed_time = time() - start print("elapsed_time:{0}".format(elapsed_time) + "[秒]")
def createRichmenu(line_bot_api): result = False try: rich_menu_to_create = RichMenu( size=RichMenuSize(width=1000, height=688), selected=True, name='richmenu for randomchat', chat_bar_text='メニュー', areas=[ RichMenuArea(bounds=RichMenuBounds(x=434.5, y=184, width=555.5, height=248), action=MessageAction(text="Recipatorをはじめる")), ]) richMenuId = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) path = './images/menu.png' with open(path, 'rb') as f: line_bot_api.set_rich_menu_image(richMenuId, "image/png", f) # set the default rich menu line_bot_api.set_default_rich_menu(richMenuId) result = True except Exception: result = False return result
def create_rich_menu(): print("INFO: Creating rich menu") line_bot_api = LineBotApi(channel_access_token) display_text = str( capture_seconds) + "秒の録画が始まりました!\nスマホをしまっても大丈夫です。\n2分程たったら動画が届きます。" rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=1204), selected=True, name="Nice richmenu", chat_bar_text="録画ボタン", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=2500, height=1408), action=PostbackAction(data=twitch_username, display_text=display_text)) ]) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) with open("record_button.png", 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id, 'image/png', f) line_bot_api.set_default_rich_menu(rich_menu_id) print("INFO: Finished creating rich menu")
def create_facebook_richmenu(line_bot_api, user_id): facebook_uri = "https://www.facebook.com/profile.php?id=100002433519943" ### Create one rich menu rich_menu_to_create = RichMenu(size=RichMenuBound(width=2500, height=1686), selected=False, name="Fabebook Page", chatBarText="Gift", areas=[ RichMenuArea( RichMenuBound(x=0, y=0, width=2000, height=1300), URITemplateAction(uri=facebook_uri)) ]) rich_menu_id = line_bot_api.create_rich_menu(rich_menu_to_create) ### Set image to rich_menu with open("dog.jpg", "rb") as f: pic = f.read() line_bot_api.set_rich_menu_image(rich_menu_id, "image/jpeg", pic) ### Link rich_menu_id and user_id line_bot_api.link_rich_menu_to_user(user_id, rich_menu_id) ### Console print( "[Create] The facebook rich menu is created and linked to the user_id = {}" .format(user_id))
def createRichmenu(event, context): # LineBotAPIオブジェクトを作成する token = os.getenv('LINE_ACCESS_TOKEN') line_bot_api = LineBotApi(token) result = False try: # define a new richmenu rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name='richmenu for Link', chat_bar_text='MENU', areas=[ RichMenuArea( bounds=RichMenuBounds(x=15, y=0, width=800, height=843), action=URIAction(uri='https://www.matsuokamayu.jp/') ), RichMenuArea( bounds=RichMenuBounds(x=845, y=0, width=800, height=843), action=URIAction(uri='https://twitter.com/hiratahirata14/') ), RichMenuArea( bounds=RichMenuBounds(x=1660, y=0, width=800, height=843), action=URIAction( uri='https://www.instagram.com/mayu_matsuoka_koushiki/') ) ] ) richMenuId = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) # upload an image for rich menu path = './images/rich_image.jpg' with open(path, 'rb') as f: line_bot_api.set_rich_menu_image(richMenuId, "image/png", f) # set the default rich menu line_bot_api.set_default_rich_menu(richMenuId) result = True except Exception: result = False return result
def get_rich_menu(): result = False width = 2500 height = 1686 try: # define a new richmenu rich_menu_to_create = RichMenu( size=RichMenuSize(width=width, height=height), selected=True, name='richmenu', chat_bar_text='メニュー', areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=height, height=height), action=PostbackAction(label='ストーリーをすすめる', data='next_step')), RichMenuArea(bounds=RichMenuBounds(x=height, y=0, width=width - height, height=height / 2), action=PostbackAction(label='中止', data='stop')), RichMenuArea(bounds=RichMenuBounds(x=height, y=height / 2, width=width - height, height=height / 2), action=PostbackAction(label='投票', data='vote')) ]) richMenuId = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) # upload an image for rich menu path = settings.STATIC_ROOT + 'images/richmenu.jpeg' with open(path, 'rb') as f: line_bot_api.set_rich_menu_image(richMenuId, "image/jpeg", f) result = True except Exception: result = False print(richMenuId, 'richmenu-id result: ' + str(result))
def __create_richmenu(self): rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=1686), selected=True, name="dine_richmenu", chat_bar_text="BOT設定はここ!", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=1250, height=843), action=PostbackAction( data="delete_server", display_text="サーバーを消したいよ!")), RichMenuArea(bounds=RichMenuBounds(x=0, y=843, width=1250, height=1686), action=PostbackAction( data="setting_server", display_text="サーバーを設定したいよ!")), RichMenuArea(bounds=RichMenuBounds(x=1250, y=0, width=2500, height=843), action=PostbackAction( data="register_server", display_text="サーバを登録したいよ!")), RichMenuArea(bounds=RichMenuBounds(x=1250, y=843, width=2500, height=1686), action=PostbackAction(data="select_server", display_text="サーバーを選びたいよ!")) ]) richMenuId = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) with open("picture/richmenu.png", 'rb') as f: line_bot_api.set_rich_menu_image(richMenuId, "image/png", f) line_bot_api.set_default_rich_menu(richMenuId)
def test_rich_menu_with_switch_action(self): rich_menu = RichMenu(size=RichMenuSize(width=2500, height=1686), selected=False, name="nice richmenu", chatBarText="touch me", areas=[ RichMenuArea( RichMenuBounds(x=0, y=0, width=833, height=843), RichMenuSwitchAction( rich_menu_alias_id="richmenu-alias-a", data="richmenu-changed-to-a")) ]) responses.add(responses.POST, LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/richmenu', json={ "richMenuId": "rich_menu_id", "size": { "width": 2500, "height": 1686 }, "selected": False, "name": "name", "chatBarText": "chatBarText", "areas": [{ "bounds": { "x": 0, "y": 0, "width": 2500, "height": 1686 }, "action": { "type": "richmenuswitch", "richMenuAliasId": "richmenu-alias-a", "data": "richmenu-changed-to-a" } }] }, status=200) result = self.tested.create_rich_menu(rich_menu) print(rich_menu) request = responses.calls[0].request self.assertEqual(request.method, 'POST') self.assertEqual(request.url, LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/richmenu') self.assertEqual(result, "rich_menu_id")
def setRichMenu(): try: rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name="用愛發財", chat_bar_text="用愛發財選單", areas=[ RichMenuArea( bounds=RichMenuBounds(x=0, y=0, width=833, height=843), action=PostbackAction( label='history', display_text='查看投資歷史績效', data='action=history&itemid=1' ) ), RichMenuArea( bounds=RichMenuBounds(x=833, y=0, width=833, height=843), action=URIAction(label="Go to Investment", uri="http://192.168.43.19:8080/auth") ), RichMenuArea( bounds=RichMenuBounds(x=1666, y=0, width=833, height=843), action=URIAction(label="Go to line.me", uri="https://line.me") ) ] ) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) content_type = "image/png" with open("./images/richmenu.jpg", "rb") as f: print(f) line_bot_api.set_rich_menu_image(rich_menu_id, content_type, f) line_bot_api.set_default_rich_menu(rich_menu_id) return jsonify({ "id": rich_menu_id, "description": "richMenu setted." }), 200 except Exception as e: print(e) return jsonify({ "description": "Server Error." }), 500
def NonStopObj(file): rich_menu_to_create = RichMenu( size=RichMenuSize(width=800, height=270), selected=True, name="Sample RichMenu", chat_bar_text="不具合などがある場合", areas=[RichMenuArea( bounds=RichMenuBounds(x=0, y=0, width=800, height=270), action= PostbackAction( label='不具合の報告・意見', display_text='不具合の報告・意見があります', data="action=report" ) )] ) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) print(rich_menu_id) with open (file, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id,'image/png',f) line_bot_api.set_default_rich_menu(rich_menu_id) return
def test_create_rich_menu(self): responses.add( responses.POST, LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/richmenu', json={"richMenuId": "richMenuId"}, status=200 ) rich_menu = RichMenu( size=RichMenuSize( width=2500, height=1686 ), selected=False, name="nice richmenu", chatBarText="touch me", areas=[ RichMenuArea( RichMenuBounds( x=0, y=0, width=833, height=843 ), URITemplateAction( uri='line://nv/location' ) ) ] ) result = self.tested.create_rich_menu(rich_menu) request = responses.calls[0].request self.assertEqual(request.method, 'POST') self.assertEqual( request.url, LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/richmenu' ) self.assertEqual(result, "richMenuId")
def create_affiliation_menu(): affiliation_menu = RichMenu( size=RichMenuSize(width=2500, height=843), selected=True, name='affiliation', chat_bar_text='学年・学科を設定', areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=2500, height=843), action=PostbackAction(label='affiliation', data='affiliation')) ]) affiliation_id = line_bot_api.create_rich_menu(rich_menu=affiliation_menu) with open('static/affiliation.png', 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id=affiliation_id, content_type='image/png', content=f) line_bot_api.set_default_rich_menu(affiliation_id)
# coding: utf-8 from linebot.models import RichMenu, RichMenuSize, RichMenuArea, RichMenuBounds, URIAction from Bot.Main import line_bot_api rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name="測試用 Rich Menu", chat_bar_text="點擊開啟 Rich Menu", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=2500, height=843), action=URIAction(label='Go to line.me', uri='https://line.me')), RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=2500, height=843), action=URIAction(label='Go to line.me', uri='https://line.me')) ]) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) var = line_bot_api.setDefaultRichMenu(rich_menu_id)
def create_rich_menu_material_topic(line_user_id, subject_id, topic_id): rich_menu = {} # material_learn rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name='Belajar', chat_bar_text='Belajar', areas=[ RichMenuArea(bounds=RichMenuBounds(x=38, y=40, width=579, height=776), action=PostbackAction(label='Kembali', text='Kembali', data='action=material')), RichMenuArea(bounds=RichMenuBounds(x=655, y=36, width=880, height=780), action=PostbackAction( label='Diskusi', text='Diskusi', data='action=material_discussion&subject_id=' + subject_id + '&topic_id=' + topic_id)), RichMenuArea( bounds=RichMenuBounds(x=1584, y=36, width=880, height=784), action=PostbackAction(label='Latihan Soal', text='Latihan Soal', data='action=material_quiz&subject_id=' + subject_id + '&topic_id=' + topic_id)), ]) rich_menu['material_learn'] = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) with open(constant.RICH_MENU_MATERIAL_LEARN, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu['material_learn'], 'image/png', f) # material_quiz rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name='Latihan Soal', chat_bar_text='Latihan Soal', areas=[ RichMenuArea(bounds=RichMenuBounds(x=38, y=40, width=579, height=776), action=PostbackAction(label='Kembali', text='Kembali', data='action=material')), RichMenuArea(bounds=RichMenuBounds(x=655, y=36, width=880, height=780), action=PostbackAction( label='Belajar', text='Belajar', data='action=material_learn&subject_id=' + subject_id + '&topic_id=' + topic_id)), RichMenuArea(bounds=RichMenuBounds(x=1584, y=36, width=880, height=784), action=PostbackAction( label='Diskusi', text='Diskusi', data='action=material_discussion&subject_id=' + subject_id + '&topic_id=' + topic_id)), ]) rich_menu['material_quiz'] = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) with open(constant.RICH_MENU_MATERIAL_QUIZ, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu['material_quiz'], 'image/png', f) # material_discussion rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name='Diskusi', chat_bar_text='Diskusi', areas=[ RichMenuArea(bounds=RichMenuBounds(x=38, y=40, width=579, height=776), action=PostbackAction(label='Kembali', text='Kembali', data='action=material')), RichMenuArea(bounds=RichMenuBounds(x=655, y=36, width=880, height=780), action=PostbackAction( label='Belajar', text='Belajar', data='action=material_learn&subject_id=' + subject_id + '&topic_id=' + topic_id)), RichMenuArea( bounds=RichMenuBounds(x=1584, y=36, width=880, height=784), action=PostbackAction(label='Latihan Soal', text='Latihan Soal', data='action=material_quiz&subject_id=' + subject_id + '&topic_id=' + topic_id)), ]) rich_menu['material_discussion'] = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) with open(constant.RICH_MENU_MATERIAL_DISCUSSION, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu['material_discussion'], 'image/png', f) return rich_menu
# slackに報告 SLACKBOT_WEBHOOK_URL = os.environ["SLACKBOT_ERROR_KEYWORD"] requests.post(SLACKBOT_ERROR_KEYWORD, data=json.dumps({'text': "たぶん適当な検索ワード : " + text})) ##################################################################################### rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=1686), selected=False, name='richmenu for randomchat', # chat_bar_text = 'id_default', chat_bar_text="基幹科目等の検索はこちら", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=93, width=675, height=750), action=PostbackAction(data="人間論")), RichMenuArea(bounds=RichMenuBounds(x=0, y=843, width=675, height=750), action=PostbackAction(data="人文科学")), RichMenuArea(bounds=RichMenuBounds(x=675, y=93, width=575, height=750), action=PostbackAction(data="自然論")), RichMenuArea(bounds=RichMenuBounds(x=675, y=843, width=575, height=750), action=PostbackAction(data="自然科学")), RichMenuArea(bounds=RichMenuBounds(x=1250, y=93, width=575, height=750), action=PostbackAction(data="社会論")), RichMenuArea(bounds=RichMenuBounds(x=1250, y=843, width=575, height=750), action=PostbackAction(data="社会科学")),
def main(): # 2. Create rich menu A (richmenu-a) rich_menu_object_a = rich_menu_object_a_json() areas = [ RichMenuArea(bounds=RichMenuBounds(x=info['bounds']['x'], y=info['bounds']['y'], width=info['bounds']['width'], height=info['bounds']['height']), action=create_action(info['action'])) for info in rich_menu_object_a['areas'] ] rich_menu_to_a_create = RichMenu(size=RichMenuSize( width=rich_menu_object_a['size']['width'], height=rich_menu_object_a['size']['height']), selected=rich_menu_object_a['selected'], name=rich_menu_object_a['name'], chat_bar_text=rich_menu_object_a['name'], areas=areas) rich_menu_a_id = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_a_create) # 3. Upload image to rich menu A with open('./public/richmenu-a.png', 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_a_id, 'image/png', f) # 4. Create rich menu B (richmenu-b) rich_menu_object_b = rich_menu_object_b_json() areas = [ RichMenuArea(bounds=RichMenuBounds(x=info['bounds']['x'], y=info['bounds']['y'], width=info['bounds']['width'], height=info['bounds']['height']), action=create_action(info['action'])) for info in rich_menu_object_b['areas'] ] rich_menu_to_b_create = RichMenu(size=RichMenuSize( width=rich_menu_object_b['size']['width'], height=rich_menu_object_b['size']['height']), selected=rich_menu_object_b['selected'], name=rich_menu_object_b['name'], chat_bar_text=rich_menu_object_b['name'], areas=areas) rich_menu_b_id = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_b_create) # 5. Upload image to rich menu B with open('./public/richmenu-b.png', 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_b_id, 'image/png', f) # 6. Set rich menu A as the default rich menu line_bot_api.set_default_rich_menu(rich_menu_b_id) # 7. Create rich menu alias A alias_a = RichMenuAlias(rich_menu_alias_id='richmenu-alias-a', rich_menu_id=rich_menu_a_id) line_bot_api.create_rich_menu_alias(alias_a) # 8. Create rich menu alias B alias_b = RichMenuAlias(rich_menu_alias_id='richmenu-alias-b', rich_menu_id=rich_menu_b_id) line_bot_api.create_rich_menu_alias(alias_b) print('success')
# #set default rich menu # url=f'https://api.line.me/v2/bot/user/all/richmenu/{non_id}' # headers = { # 'Authorization': 'Bearer ' + settings.access_token # } # res=requests.post(url, headers=headers) # print(res) # create richmenu rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=True, name="none_room", chat_bar_text="メニューを開く・閉じる", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=1250, height=843), action=MessageAction(text='部屋を作る')), RichMenuArea(bounds=RichMenuBounds(x=1250, y=0, width=1250, height=843), action=MessageAction(text='部屋に入る')) ]) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) # upload image with open('static/none_room.png', 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id, 'image/png', f) print(f'richmenu_id = "{rich_menu_id}"') # create richmenu rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843),
def handle_message(event): text = event.message.text keep_uid = str( event.source)[str(event.source).find('userId') + 10:str(event.source). find('"', str(event.source).find('userId') + 10)] profile = line_bot_api.get_profile(str(keep_uid)) displayName = str( profile)[str(profile).find('displayName') + 15:str(profile).find('"', str(profile).find('displayName') + 15)] if text == 'Profile': line_bot_api.push_message('U9f6b4dfa2e30a22ad6a282dc34a86de2', TextSendMessage(text=str(profile))) elif text == 'Hi': line_bot_api.reply_message( event.reply_token, TextSendMessage(text='hi ' + str(displayName))) elif text == 'Register': line_bot_api.push_message( 'U9f6b4dfa2e30a22ad6a282dc34a86de2', TextSendMessage(text=displayName + ':' + keep_uid)) elif text == 'Excel': line_bot_api.reply_message( event.reply_token, TextSendMessage( text= 'https://drive.google.com/open?id=1c_Gmmq19LMgDsdBNzo46F1zt_rWp8RXv' )) elif text == 'Image': ## line_bot_api.reply_message( ## event.reply_token,ImageSendMessage( ## original_content_url='https://raw.githubusercontent.com/gapvan/my-line-bot-v01/master/menu.png', ## preview_image_url='https://raw.githubusercontent.com/gapvan/my-line-bot-v01/master/menu.png')) line_bot_api.reply_message( event.reply_token, ImagemapSendMessage( base_url= 'https://raw.githubusercontent.com/gapvan/my-line-bot-v01/master/menu.png?w=1040', alt_text='Image', base_size=BaseSize(height=1040, width=1040), actions=[ #URIImagemapAction(link_uri='https://www.facebook.com', MessageImagemapAction(text='full menu', area=ImagemapArea(x=0, y=0, width=1040, height=1040)) ])) elif text == 'MeetingRoom': chk_permission = 1 for i in range(len(users)): if (users[i][0] == displayName) & (users[i][1] == keep_uid): chk_permission = 1 if chk_permission: line_bot_api.reply_message( event.reply_token, TextSendMessage( text= 'https://outlook.office.com/owa/?realm=central.co.th&exsvurl=1&ll-cc=3081&modurl=0&path=/calendar/view/Day' )) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text='คุณไม่มีสิทธิ์เข้าใช้งาน WPRS ได้ครับ')) ## line_bot_api.reply_message( ## event.reply_token,ImageSendMessage( ## original_content_url='https://raw.githubusercontent.com/gapvan/my-line-bot-v01/master/RIS_Meeting_Room.jpg', ## preview_image_url='https://raw.githubusercontent.com/gapvan/my-line-bot-v01/master/RIS_Meeting_Room.jpg')) elif text == 'Monitor': line_bot_api.reply_message( event.reply_token, ImagemapSendMessage( base_url= 'https://raw.githubusercontent.com/gapvan/my-line-bot-v01/master/monitor_task.png?w=1038', alt_text='monitor_task', base_size=BaseSize(height=1040, width=1040), actions=[ #URIImagemapAction(link_uri='https://www.facebook.com', MessageImagemapAction(text='WPRS', area=ImagemapArea(x=0, y=0, width=347, height=520)), MessageImagemapAction(text='CNSGNSALE1', area=ImagemapArea(x=347, y=0, width=347, height=520)), MessageImagemapAction(text='STSALE', area=ImagemapArea(x=694, y=0, width=347, height=520)), MessageImagemapAction(text='CNSGNSALE', area=ImagemapArea(x=0, y=521, width=347, height=520)), MessageImagemapAction(text='ยังไม่เปิดใช้งานครับ', area=ImagemapArea(x=347, y=521, width=347, height=520)), MessageImagemapAction(text='ยังไม่เปิดใช้งานครับ', area=ImagemapArea(x=694, y=521, width=347, height=520)) ])) elif text == 'WPRS': chk_permission = 1 for i in range(len(users)): if (users[i][0] == displayName) & (users[i][1] == keep_uid): chk_permission = 1 if chk_permission: line_bot_api.reply_message( event.reply_token, TextSendMessage( text= 'https://drive.google.com/open?id=1X63rWkPREk3JOXKCvn0X6t-vYuUB05_k' )) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text='คุณไม่มีสิทธิ์เข้าใช้งาน WPRS ได้ครับ')) elif text == 'CNSGNSALE1': chk_permission = 1 for i in range(len(users)): if (users[i][0] == displayName) & (users[i][1] == keep_uid): chk_permission = 1 if chk_permission: line_bot_api.reply_message( event.reply_token, TextSendMessage( text= 'https://drive.google.com/open?id=15lrXuWk_-mlCWFo6Legd0WgYOL9-3GLX' )) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text='คุณไม่มีสิทธิ์เข้าใช้งาน WPRS ได้ครับ')) elif text == 'STSALE': chk_permission = 1 for i in range(len(users)): if (users[i][0] == displayName) & (users[i][1] == keep_uid): chk_permission = 1 if chk_permission: line_bot_api.reply_message( event.reply_token, TextSendMessage( text= 'https://drive.google.com/open?id=1Ph2d5VaCYSQCy92yk5LdUgpg_HaMku5q' )) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text='คุณไม่มีสิทธิ์เข้าใช้งาน WPRS ได้ครับ')) elif text == 'CNSGNSALE': chk_permission = 1 for i in range(len(users)): if (users[i][0] == displayName) & (users[i][1] == keep_uid): chk_permission = 1 if chk_permission: line_bot_api.reply_message( event.reply_token, TextSendMessage( text= 'https://drive.google.com/open?id=1BjibISg0sa48rh-JgFPVGuM_KSefTkQf' )) else: line_bot_api.reply_message( event.reply_token, TextSendMessage(text='คุณไม่มีสิทธิ์เข้าใช้งาน WPRS ได้ครับ')) elif text == 'Menu': rich_menu_to_create = RichMenu( size=RichMenuSize(width=800, height=540), selected=False, name="Main Menu", chat_bar_text="Tap here", areas= [(RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=266, height=270), action=MessageAction(label="moniter", text="Monitor"))), (RichMenuArea( bounds=RichMenuBounds(x=267, y=0, width=267, height=270), action=MessageAction( label="report", text= "https://drive.google.com/open?id=1oqYThl46BQXnPV47Q6AQawZHM9Klu_8o" ))), (RichMenuArea( bounds=RichMenuBounds(x=533, y=0, width=267, height=270), action=URIAction( label='cnext', uri= 'https://passport.central.co.th/adfs/ls/IdpInitiatedSignOn.aspx?loginToRp=https://www.successfactors.com/CENTRAL' ))), (RichMenuArea( bounds=RichMenuBounds(x=0, y=271, width=266, height=270), action=URIAction( label='issue', uri= 'https://ris6789.central.co.th/arsys/shared/login.jsp?/arsys/' ))), (RichMenuArea(bounds=RichMenuBounds(x=267, y=271, width=267, height=270), action=MessageAction(label=" ", text="ยังไม่เปิดใช้งานครับ"))), (RichMenuArea(bounds=RichMenuBounds(x=533, y=271, width=267, height=270), action=MessageAction(label="meetingroom", text="MeetingRoom")))]) rich_menu_id = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) print(rich_menu_id) with open('.//main_menu.png', 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id, 'image/png', f) line_bot_api.link_rich_menu_to_user(keep_uid, rich_menu_id) ## line_bot_api.reply_message( ## event.reply_token,TextSendMessage(text=str(rich_menu_id))) else: print(event.message.text)
event.reply_token, TextSendMessage(text="【油價】\n提供當日中油、台塑主要油價。")) else: line_bot_api.reply_message( event.reply_token, TextSendMessage("未知Postback:\n" + event.postback.data)) rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=1686), selected=True, name="圖文選單 1", chat_bar_text="查看快捷鍵", areas=[ RichMenuArea( bounds=RichMenuBounds(x=0, y=0, width=854, height=843), action=URIAction( label="呼叫助理", uri="https://liff.line.me/1654548127-50gGKZyE/Manager")), RichMenuArea( bounds=RichMenuBounds(x=854, y=0, width=854, height=843), action=URIAction( label="推薦行程", uri="https://liff.line.me/1654548127-50gGKZyE/Travel")), RichMenuArea( bounds=RichMenuBounds(x=1707, y=0, width=854, height=843), action=URIAction( label="記帳小本本", uri="https://liff.line.me/1654548127-50gGKZyE/Account")), RichMenuArea(bounds=RichMenuBounds(x=0, y=843, width=854, height=843), action=MessageAction(label="天氣及空氣品質", text="天氣及空氣品質")), RichMenuArea(bounds=RichMenuBounds(x=854, y=843, width=854,
from linebot.models import RichMenu, RichMenuSize, RichMenuBounds, RichMenuArea, DatetimePickerAction, MessageAction import datetime milk_rich_menu = RichMenu( size=RichMenuSize(width=2500, height=843), selected=True, name="milk rich menu", chat_bar_text="Open Menu", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=1617, height=843), action=DatetimePickerAction(data="action=calc_month", mode="date", initial=str( datetime.date.today()))), RichMenuArea(bounds=RichMenuBounds(x=1617, y=0, width=2500 - 1617, height=843), action=MessageAction(text="ミス")), ])
URIAction, PostbackAction ) LINE_CHANNEL_ACCESS_TOKEN = '6pzegJmVUuwqq78rLWl87O9Tr5N8kNU7r8+kxhizZ2emhpTiWMt2OdBCnA19Xqi/nla5PeZNwO++cZYOMHDZKuCpezNxMVYbyDRK1g3RGemZD7XR09bIOaOW3uIBnpBga6XGUXS5M0smEIW4O32aHgdB04t89/1O/w1cDnyilFU=' line_bot_api = LineBotApi(LINE_CHANNEL_ACCESS_TOKEN) # create rich menu # from https://developers.line.biz/en/reference/messaging-api/#create-rich-menu rich_menu_to_create = RichMenu( size=RichMenuSize(width=800, height=270), # 2500x1686, 2500x843, 1200x810, 1200x405, 800x540, 800x270 selected=True, name="NextPage", chat_bar_text="See Menu", areas=[ RichMenuArea( bounds=RichMenuBounds(x=0, y=0, width=400, height=270), action=URIAction(label='Youtube', uri='https://www.youtube.com/')), RichMenuArea( bounds=RichMenuBounds(x=400, y=0, width=400, height=270), action=PostbackAction(label='Next Page', data='action=previouspage')), ] ) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) print("rich_menu_id", rich_menu_id) # upload image and link it to richmenu # from https://developers.line.biz/en/reference/messaging-api/#upload-rich-menu-image with open(os.path.join('images', 'firstpage.jpg'), 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id, 'image/jpeg', f)
def create_timetable_menu(): affiliations = { '11', '12', '13', '14', '15', '2m', '2e', '2j', '2c', '2z', '3m', '3e', '3j', '3c', '3z', '4m', '4e', '4j', '4c', '4z', '5des', '5ene', '5ele', '5rob', '5its', '5mat', '5bio', '5city', '5con', '5gm', } for affiliation in affiliations: timetable_menu = RichMenu( size=RichMenuSize(width=2500, height=1686), selected=True, name='timetable' + affiliation, chat_bar_text='時間割を確認', areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=500, height=1000), action=PostbackAction(label='Mon', data=str(affiliation + 'Mon'))), RichMenuArea(bounds=RichMenuBounds(x=500, y=0, width=500, height=1000), action=PostbackAction(label='Tue', data=str(affiliation + 'Tue'))), RichMenuArea(bounds=RichMenuBounds(x=1000, y=0, width=500, height=1000), action=PostbackAction(label='Wed', data=str(affiliation + 'Wed'))), RichMenuArea(bounds=RichMenuBounds(x=1500, y=0, width=500, height=1000), action=PostbackAction(label='Thu', data=str(affiliation + 'Thu'))), RichMenuArea(bounds=RichMenuBounds(x=2000, y=0, width=500, height=1000), action=PostbackAction(label='Fri', data=str(affiliation + 'Fri'))), RichMenuArea(bounds=RichMenuBounds(x=0, y=1000, width=2500, height=686), action=PostbackAction(label='affiliation', data='affiliation')), ]) timetable_id = line_bot_api.create_rich_menu(rich_menu=timetable_menu) with open('static/timetable.png', 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id=timetable_id, content_type='image/png', content=f)
def create_rich_menu(line_user_id): rich_menu = {} # home rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name='Home', chat_bar_text='Home', areas=[ RichMenuArea(bounds=RichMenuBounds(x=48, y=36, width=1190, height=780), action=PostbackAction(label='Materi', text='Materi', data='action=material')), RichMenuArea(bounds=RichMenuBounds(x=1290, y=44, width=1174, height=760), action=PostbackAction(label='Latihan UN', text='Latihan UN', data='action=final_quiz')), ]) rich_menu['home'] = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) with open(constant.RICH_MENU_HOME, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu['home'], 'image/png', f) # material rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name='Materi', chat_bar_text='Materi', areas=[ RichMenuArea(bounds=RichMenuBounds(x=28, y=32, width=587, height=784), action=PostbackAction(label='Kembali', text='Kembali', data='action=home')), RichMenuArea(bounds=RichMenuBounds(x=651, y=32, width=1817, height=788), action=PostbackAction(label='Latihan UN', text='Latihan UN', data='action=final_quiz')), ]) rich_menu['material'] = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) with open(constant.RICH_MENU_MATERIAL, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu['material'], 'image/png', f) # final_quiz rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=False, name='Latihan UN', chat_bar_text='Latihan UN', areas=[ RichMenuArea(bounds=RichMenuBounds(x=28, y=32, width=587, height=784), action=PostbackAction(label='Kembali', text='Kembali', data='action=home')), RichMenuArea(bounds=RichMenuBounds(x=651, y=32, width=1817, height=788), action=PostbackAction(label='Materi', text='Materi', data='action=material')), ]) rich_menu['final_quiz'] = line_bot_api.create_rich_menu( rich_menu=rich_menu_to_create) with open(constant.RICH_MENU_FINAL_QUIZ, 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu['final_quiz'], 'image/png', f) return rich_menu
# #set default rich menu # url=f'https://api.line.me/v2/bot/user/all/richmenu/{non_id}' # headers = { # 'Authorization': 'Bearer ' + settings.access_token # } # res=requests.post(url, headers=headers) # print(res) # create richmenu rich_menu_to_create = RichMenu( size=RichMenuSize(width=2500, height=843), selected=True, name="none_room", chat_bar_text="メニューを開く・閉じる", areas=[ RichMenuArea(bounds=RichMenuBounds(x=0, y=0, width=1250, height=843), action=MessageAction(text='部屋を作る')), RichMenuArea(bounds=RichMenuBounds(x=1250, y=0, width=1250, height=843), action=MessageAction(text='部屋に入る')) ]) rich_menu_id = line_bot_api.create_rich_menu(rich_menu=rich_menu_to_create) # upload image with open('static/none_room.png', 'rb') as f: line_bot_api.set_rich_menu_image(rich_menu_id, 'image/png', f) print(f'richmenu_id = "{rich_menu_id}"') # # create richmenu # rich_menu_to_create = RichMenu( # size=RichMenuSize(width=2500, height=843),