def handle_message(event): if event.type == "message": if event.message.type == "text": actions = [] actions.append( MessageImagemapAction(text='', area=ImagemapArea(x=2, y=2, width=1031, height=343))) actions.append( MessageImagemapAction(text='', area=ImagemapArea(x=2, y=346, width=1029, height=346))) actions.append( MessageImagemapAction(text='', area=ImagemapArea(x=0, y=690, width=1037, height=346))) message = ImagemapSendMessage( base_url='https://' + request.host + '/imagemap/' + uuid.uuid4().hex, # prevent cache alt_text='MAP', base_size=BaseSize(height=1040, width=1040), actions=actions) line_bot_api.reply_message(event.reply_token, message)
def floor_plan(): floor = ImagemapSendMessage( base_url='https://i.imgur.com/dMk5Vrj.png', alt_text='請用手機點選該位置!', base_size=BaseSize(height=1040, width=1040), actions=[ MessageImagemapAction(text='上左', area=ImagemapArea(x=0, y=0, width=357, height=357)), MessageImagemapAction(text='上中', area=ImagemapArea(x=357, y=0, width=357, height=357)), MessageImagemapAction(text='上右', area=ImagemapArea(x=715, y=0, width=357, height=357)), MessageImagemapAction(text='中左', area=ImagemapArea(x=0, y=357, width=357, height=357)), MessageImagemapAction(text='中中', area=ImagemapArea(x=357, y=357, width=357, height=357)), MessageImagemapAction(text='中右', area=ImagemapArea(x=715, y=357, width=357, height=357)), MessageImagemapAction(text='下左', area=ImagemapArea(x=0, y=715, width=357, height=357)), MessageImagemapAction(text='下中', area=ImagemapArea(x=357, y=715, width=357, height=357)), MessageImagemapAction(text='下右', area=ImagemapArea(x=715, y=715, width=357, height=357)), ]) return floor
def test_message_actions(self): arg = { 'text': 'Hey', 'area': ImagemapArea(x=0, y=58, width=52, height=40) } self.assertEqual(self.serialize_as_dict(arg, type=self.MESSAGE), MessageImagemapAction(**arg).as_json_dict())
def test_image_map(self): arg = { 'base_url': 'https://example.com/bot/images/rm001', 'alt_text': 'This is an imagemap', 'base_size': BaseSize(width=1040, height=1040), 'video': Video(original_content_url='https://example.com/video.mp4', preview_image_url='https://example.com/video_preview.jpg', area=ImagemapArea(x=0, y=0, width=1040, height=585), external_link=ExternalLink( label='See more', link_uri='https://example.com/see_more.html')), 'actions': [ URIImagemapAction(link_uri='https://example.com/', area=ImagemapArea(x=0, y=585, width=520, height=454)), MessageImagemapAction(text='Hey', area=ImagemapArea(x=0, y=58, width=52, height=40)) ] } self.assertEqual(self.serialize_as_dict(arg, type=self.IMAGEMAP), ImagemapSendMessage(**arg).as_json_dict())
def sendImgmap(event): #圖片地圖 try: image_url = 'https://i.imgur.com/Yz2yzve.jpg' #圖片位址 imgwidth = 1040 #原始圖片寛度一定要1040 imgheight = 300 message = ImagemapSendMessage( base_url=image_url, alt_text="圖片地圖範例", base_size=BaseSize(height=imgheight, width=imgwidth), #圖片寬及高 actions=[ MessageImagemapAction( #顯示文字訊息 text='你點選了紅色區塊!', area=ImagemapArea( #設定圖片範圍:左方1/4區域 x=0, y=0, width=imgwidth*0.25, height=imgheight ) ), URIImagemapAction( #開啟網頁 link_uri='http://www.e-happy.com.tw', area=ImagemapArea( #右方1/4區域(藍色1) x=imgwidth*0.75, y=0, width=imgwidth*0.25, height=imgheight ) ), ] ) line_bot_api.reply_message(event.reply_token, message) except: line_bot_api.reply_message(event.reply_token,TextSendMessage(text='發生錯誤!'))
def sendImgmap(event): #try: image_url = 'https://i.imgur.com/Yz2yzve.jpg' imgwidth = 1040 imgheight = 300 message = ImagemapSendMessage( base_url=image_url, alt_text= "圖片地圖範例", base_size=BaseSize(height=imgheight, width=imgwidth), actions=[ MessageImagemapAction( text="你點選了紅色區域!", area=ImagemapArea( x=0, y=0, width=imgwidth*0.25, height=imgheight ) ), URIImagemapAction( link_url='https://www1.cycu.edu.tw/', area=ImagemapArea( x=imgwidth*0.75, y=0, width=imgwidth*0.25, height=imgheight ) ), ] ) line_bot_api.reply_message(event.reply_token, message)
def map_image() -> ImagemapSendMessage: main_photo = blackman_pic_url preview_text = 'this is an imagemap' return ImagemapSendMessage( base_url=main_photo, alt_text=preview_text, base_size=BaseSize(height=1040, width=1040), actions=[ URIImagemapAction(link_uri=blackman_pic_url, area=ImagemapArea(x=0, y=0, width=520, height=520)), MessageImagemapAction(text='hello', area=ImagemapArea(x=520, y=0, width=520, height=520)), URIImagemapAction(link_uri=blackman_pic_url, area=ImagemapArea(x=0, y=520, width=520, height=520)), URIImagemapAction(link_uri=blackman_pic_url, area=ImagemapArea(x=520, y=520, width=520, height=520)) ])
def generate_planning_poker_message(number): app.logger.info('[number] :' + number) data = redis.hgetall(number + '_member') tmpnum = generate_voting_target_image(number, data) count = len(data) if count < 3: vote_height = 260 row_count = 1 elif count < 7: vote_height = 520 row_count = 2 else: vote_height = 780 row_count = 3 message = ImagemapSendMessage(base_url=HEROKU_SERVER_URL + 'images/tmp/' + tmpnum, alt_text='vote board', base_size=BaseSize(height=vote_height, width=1040)) actions = [] location = 0 for i in range(0, row_count): for j in range(0, 4): if location == count + 1: #最後 actions.append( MessageImagemapAction( text=u'#' + str(number).encode('utf-8') + u' 11', area=ImagemapArea( x=j * POKER_IMAGEMAP_ELEMENT_WIDTH, y=i * POKER_IMAGEMAP_ELEMENT_HEIGHT, width=(j + 1) * POKER_IMAGEMAP_ELEMENT_WIDTH, height=(i + 1) * POKER_IMAGEMAP_ELEMENT_HEIGHT))) else: actions.append( MessageImagemapAction( text=u'#' + str(number).encode('utf-8') + u' ' + str(location).encode('utf-8'), area=ImagemapArea( x=j * POKER_IMAGEMAP_ELEMENT_WIDTH, y=i * POKER_IMAGEMAP_ELEMENT_HEIGHT, width=(j + 1) * POKER_IMAGEMAP_ELEMENT_WIDTH, height=(i + 1) * POKER_IMAGEMAP_ELEMENT_HEIGHT))) location += 1 message.actions = actions return message
def handle_message(event): profile = line_bot_api.get_profile(event.source.user_id) user_name = profile.display_name print(user_name + " :") print(event.source.user_id) print(event.message.text) if event.message.text == "寶寶": flex_message = baby_talk(event.source.user_id) line_bot_api.reply_message(event.reply_token, flex_message) elif event.message.text == "媽媽論壇": print("社群") message = [] message.append(TextSendMessage(text="請選擇想加入的社群分類~")) message.append(ImagemapSendMessage( base_url="https://i.imgur.com/Vuh7xIP.jpg", alt_text="This is an imagemap", base_size=BaseSize(1040,1040), actions=[ MessageImagemapAction(type='message',text="$素人媽媽", area=ImagemapArea(0, 0, 520, 520)), MessageImagemapAction(type='message',text="$醫生", area=ImagemapArea(0, 520, 520, 520)), MessageImagemapAction(type='message',text="$部落客", area=ImagemapArea(520, 0, 520, 520)), MessageImagemapAction(type='message',text="$其他", area=ImagemapArea(520, 520, 520, 520)) ] )) line_bot_api.reply_message(event.reply_token, message) elif event.message.text == "大補帖": template = template_env.get_template('quick_reply.json') with open('quick_reply/week%s.json' % (str(week))) as f: option = json.load(f) data = template.render(option) data = eval(data) message = TextSendMessage(text='請輸入欲搜尋文章的關鍵字~', quick_reply=QuickReply.new_from_json_dict(data)) line_bot_api.reply_message(event.reply_token, message) elif event.message.text.startswith("\\"): message = article_fetching((event.message.text).replace("\\", "")) line_bot_api.reply_message(event.reply_token, message) elif event.message.text.startswith("$"): if event.message.text == "$醫生": dir_name = './line_group/doctor/' elif event.message.text == "$素人媽媽": dir_name = './line_group/mommy/' elif event.message.text == "$部落客": dir_name = './line_group/blogger/' elif event.message.text == "$其他": dir_name = './line_group/others/' message = get_line_group(dir_name) line_bot_api.reply_message(event.reply_token,message)
def make_reversi_action(p): y, x = divmod(p, 8) i2a = str.maketrans("01234567", "abcdefgh") # int to alphabet text = '{}{}'.format(str(x).translate(i2a), y + 1) action = MessageImagemapAction( text=text, area=make_reversi_area(x, y), ) return action
def generateJoinButton(): message = ImagemapSendMessage(base_url=HEROKU_SERVER_URL + 'images/button', alt_text='join', base_size=BaseSize(height=178, width=1040)) actions = [] actions.append( MessageImagemapAction(text='join', area=ImagemapArea(x=0, y=0, width=BUTTON_ELEMENT_WIDTH, height=BUTTON_ELEMENT_HEIGHT))) actions.append( MessageImagemapAction(text='add', area=ImagemapArea(x=BUTTON_ELEMENT_WIDTH, y=0, width=BUTTON_ELEMENT_WIDTH * 2, height=BUTTON_ELEMENT_HEIGHT))) message.actions = actions return message
def setUp(self): self.tested = LineBotApi('d42b9b5dc4df7ad44e9bddd5ee915fc7') self.imagemap_message = ImagemapSendMessage( base_url='https://example.com/base', alt_text='this is an imagemap', base_size=BaseSize(height=1040, width=1040), actions=[ URIImagemapAction( link_uri='https://example.com/', area=ImagemapArea( x=0, y=0, width=520, height=1040 ) ), MessageImagemapAction( text='hello', area=ImagemapArea( x=520, y=0, width=520, height=1040 ) ) ] ) self.message = [{ "type": "imagemap", "baseUrl": "https://example.com/base", "altText": "this is an imagemap", "baseSize": { "height": 1040, "width": 1040 }, "actions": [ { "type": "uri", "linkUri": "https://example.com/", "area": { "x": 0, "y": 0, "width": 520, "height": 1040 } }, { "type": "message", "text": "hello", "area": { "x": 520, "y": 0, "width": 520, "height": 1040 } } ] }]
def _create_zapper_imgmap(self, event): zapper_imgmap = ImagemapSendMessage( base_url=ZAPPER_IMGMAP_URL, alt_text='user zapper information', base_size=BaseSize(height=1040, width=1040), actions=[ MessageImagemapAction( text=self.render_text('zapper_imgmap/bind_zapper.j2'), area=ImagemapArea(x=0, y=0, width=520, height=520)) ]) try: line_user = LineUser.objects.get(user_id=event.source.user_id) except LineUser.DoesNotExist: logger.error('Line User Does Not Exist') else: if line_user.zapper_id: # Use slice to prepend these three object to actions list. zapper_imgmap.actions[:0] = [ MessageImagemapAction(text=self.render_text( 'zapper_imgmap/self_zapper_cond.j2'), area=ImagemapArea(x=520, y=0, width=520, height=520)), MessageImagemapAction(text=self.render_text( 'zapper_imgmap/area_zapper_cond.j2'), area=ImagemapArea(x=0, y=520, width=520, height=520)), MessageImagemapAction(text=self.render_text( 'zapper_imgmap/zapper_assist.j2'), area=ImagemapArea(x=520, y=520, width=520, height=520)) ] return zapper_imgmap
def send_single_imagemap(self, user_ids, alt_text, image_url, keyword): payload = ImagemapSendMessage(base_url=image_url, alt_text=alt_text, base_size=BaseSize(height=1040, width=1040), actions=[ MessageImagemapAction( text=keyword, area=ImagemapArea(x=0, y=0, width=1040, height=1040)) ]) user_ids = user_ids.split(",") self.__send_multicast(user_ids, payload)
def get_ads_info(): photo_url = 'https://github.com/housekeepbao/flight_bot/blob/master/images/travel_test_img.png?raw=true' link_url = 'https://www.google.com.tw/maps/place/%E5%8F%A4%E6%97%A9%E5%91%B3%E5%B0%8F%E5%90%83%E5%BA%97/@25.0629705,121.5012555,23.8z/data=!4m8!1m2!2m1!1z5Y-w5YyX5qmLIOe-jumjnw!3m4!1s0x3442a92298613293:0xcff4aac1356b306!8m2!3d25.0629585!4d121.50107?hl=zh-TW' actions = [ URIImagemapAction( link_uri=link_url, area=ImagemapArea( x=0, y=0, width=520, height=1024 ) ), MessageImagemapAction( text='我是第二個區域', area=ImagemapArea( x=520, y=0, width=520, height=512 ) ), MessageImagemapAction( text='我是第三個區域', area=ImagemapArea( x=520, y=512, width=520, height=1024 ) ) ] return photo_url, link_url, actions
def reply(request): return ImagemapSendMessage( base_url='https://example.com/base', alt_text='this is an imagemap', base_size=BaseSize(height=1040, width=1040), actions=[ URIImagemapAction(link_uri='https://example.com/', area=ImagemapArea(x=0, y=0, width=520, height=1040)), MessageImagemapAction(text='hello', area=ImagemapArea(x=520, y=0, width=520, height=1040)) ])
def handle_follow(event): sendMessage = [ TextSendMessage(text='首次加入的朋友,請先註冊才能進行查詢及申請。'), ImagemapSendMessage( base_url='https://dc10101.serveo.net/static/1/', alt_text='1', base_size=BaseSize(height=1040, width=1040), actions=[ URIImagemapAction( link_uri='https://dc10101.serveo.net/static/1/1040.png', area=ImagemapArea(x=0, y=0, width=1040, height=1040)), MessageImagemapAction(text='註冊', area=ImagemapArea(x=520, y=0, width=50, height=50)) ]) ] line_bot_api.reply_message(event.reply_token, sendMessage)
def send_single_imagemap(self, user_ids, alt_text, image_url, keyword): payload = ImagemapSendMessage(base_url=image_url, alt_text=alt_text, base_size=BaseSize(height=1040, width=1040), actions=[ MessageImagemapAction( text=keyword, area=ImagemapArea(x=0, y=0, width=1040, height=1040)) ]) user_ids = user_ids.split(",") self.__send_multicast(user_ids, payload) # bot = Bot('jn/yYyTgYipzoNX7DmjxT41uhepnyu2CkqRrzBRRghfBpIRCxVyuso+k7YSl4ESPqdsjAm2kccVHSPN3SQO+hjnWrshmHzxWTqWMceCzYVro/GThips/r6MeDjpmClOD56LvFWQRzGo11IoS3jw8ca18BSl7lGXPAT9HRw/DX2c=') # print bot.get_profile('U6fb98eb0f44be13523bbabd566e47dc4') # print bot.get_profile('U6fb98eb0f44be13523bbabd566e47dc4')
def handle_message(event): if event.type == "message": if event.message.type == "text": actions = [] actions.append( MessageImagemapAction( text='Button Pushed!', area=ImagemapArea( # Button is 100px on 700px. So 149 on base size(1040px) x=0, y=0, width=149, height=149))) message = ImagemapSendMessage( base_url='https://' + request.host + '/imagemap/' + uuid.uuid4().hex, # prevent cache alt_text='代替テキスト', base_size=BaseSize(height=1040, width=1040), actions=actions) line_bot_api.reply_message(event.reply_token, message)
def generate_planning_poker_message(number): message = ImagemapSendMessage( base_url='https://scrummasterbot.herokuapp.com/images/planning_poker', alt_text='planning poker', base_size=BaseSize(height=790, width=1040)) actions = [] location = 0 for i in range(0, 3): for j in range(0, 4): actions.append( MessageImagemapAction( text=u'#' + number + u' ' + mapping[str(location).encode('utf-8')], area=ImagemapArea( x=j * POKER_IMAGEMAP_ELEMENT_WIDTH, y=i * POKER_IMAGEMAP_ELEMENT_HEIGHT, width=(j + 1) * POKER_IMAGEMAP_ELEMENT_WIDTH, height=(i + 1) * POKER_IMAGEMAP_ELEMENT_HEIGHT))) location += 1 message.actions = actions return message
def handle_location(event): user_id = event.source.user_id pins = [] address = [] lat = event.message.latitude lon = event.message.longitude zoomlevel = 18 imagesize = 1040 key = os.environ['GOOGLE_API_KEY'] types = 'convenience_store' query = 'トイレ' place_map_url_convenience = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?&language=ja&radius=50&location={},{}&types={}&key={}'.format( lat, lon, types, key) placeJson_convenience = requests.get(place_map_url_convenience) placeData_convenience = json.loads(placeJson_convenience.text) place_map_url_toilet = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?&language=ja&radius=50&location={},{}&query={}&key={}'.format( lat, lon, query, key) placeJson_toilet = requests.get(place_map_url_toilet) placeData_toilet = json.loads(placeJson_toilet.text) for store in placeData_convenience["results"][:6]: pins.append([ store["geometry"]["location"]["lat"], store["geometry"]["location"]["lng"] ]) address.append(store["name"], store["vicinity"]) for toilet in placeData_toilet["results"][:6]: pins.append([ toilet["geometry"]["location"]["lat"], toilet["geometry"]["location"]["lng"] ]) address.append([toilet["name"], toilet["vicinity"]]) print(pins) print(address) conn = psycopg2.connect("dbname=" + dbname + " host=" + host + " user="******" password="******"CREATE TABLE users (id serial PRIMARY KEY, user_id text, pins real[], address text[]);") #cur.execute("INSERT INTO users (user_id, pins, address) VALUES (%s, %s, %s)", (user_id, pins, address)) cur.execute("UPDATE users SET pins=%s, address=%s WHERE user_id=%s", (pins, address, user_id)) cur.execute("SELECT * FROM users;") row = cur.fetchone() print(row) conn.commit() cur.close() conn.close() map_image_url = 'https://maps.googleapis.com/maps/api/staticmap?center={},{}&zoom={}&size=520x520&scale=2&maptype=roadmap&key={}'.format( lat, lon, zoomlevel, key) map_image_url += '&markers=color:{}|label:{}|{},{}'.format( 'red', '', lat, lon) center_lat_pixel, center_lon_pixel = latlon_to_pixel(lat, lon) marker_color = 'blue' pin_width = 60 * 1.5 pin_height = 84 * 1.5 actions = [] for i, pin in enumerate(pins): target_lat_pixel, target_lon_pixel = latlon_to_pixel(pin[0], pin[1]) # (4) delta_lat_pixel = (target_lat_pixel - center_lat_pixel) >> (21 - zoomlevel - 1) delta_lon_pixel = (target_lon_pixel - center_lon_pixel) >> (21 - zoomlevel - 1) marker_lat_pixel = imagesize / 2 + delta_lat_pixel marker_lon_pixel = imagesize / 2 + delta_lon_pixel x = marker_lat_pixel y = marker_lon_pixel label = str(i) if (pin_width / 2 < x < imagesize - pin_width / 2 and pin_height < y < imagesize - pin_width): map_image_url += '&markers=color:{}|label:{}|{},{}'.format( marker_color, label, pin[0], pin[1]) actions.append( MessageImagemapAction(text=str(i), area=ImagemapArea(x=x - pin_width / 2, y=y - pin_height / 2, width=pin_width, height=pin_height))) if len(actions) > 10: break line_bot_api.reply_message(event.reply_token, [ ImagemapSendMessage(base_url='https://{}/imagemap/{}'.format( request.host, urllib.parse.quote_plus(map_image_url)), alt_text='地図', base_size=BaseSize(height=imagesize, width=imagesize), actions=actions), TextSendMessage( text='ピンをタップするかピンの番号を入力すると詳細が送られるよ!{}'.format(chr(0x100029))) ])
def handle_message(event): if event.type == "message": if (event.message.text == "Curry Menu") or (event.message.text == "chicken_curry_cancel") or (event.message.text == "green_curry_cancel") or (event.message.text == "keema_curry_cancel"): TextSendMessage( text='画像メニューから自分好みのカレーを選んでね。', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/images01', alt_text='curry_imagemap_no.01', base_size=BaseSize(height=453, width=1040), actions=[ MessageImagemapAction( text='chicken_curry', area=ImagemapArea( x=30, y=50, width=320, height=355 ) ), MessageImagemapAction( text='green_curry', area=ImagemapArea( x=360, y=50, width=320, height=355 ) ), MessageImagemapAction( text='keema_curry', area=ImagemapArea( x=690, y=50, width=320, height=355 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #img_powder if event.type == "message": if (event.message.text == "Powder Spice"): TextSendMessage( text='画像メニューから自分好みのスパイスを選んでね。', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/powder_img', alt_text='powder_spice_img', base_size=BaseSize(height=750, width=1040), actions=[ MessageImagemapAction( text='spice_clove', area=ImagemapArea( x=0, y=10, width=160, height=330 ) ), MessageImagemapAction( text='spice_cinnamon', area=ImagemapArea( x=160, y=0, width=160, height=330 ) ), MessageImagemapAction( text='spice_cumin', area=ImagemapArea( x=330, y=0, width=160, height=330 ) ), MessageImagemapAction( text='spice_tougarashi', area=ImagemapArea( x=860, y=10, width=170, height=320 ) ), MessageImagemapAction( text='spice_blackpepper', area=ImagemapArea( x=510, y=10, width=170, height=320 ) ), MessageImagemapAction( text='spice_mace', area=ImagemapArea( x=690, y=0, width=170, height=320 ) ), MessageImagemapAction( text='spice_tougarashi', area=ImagemapArea( x=860, y=0, width=170, height=320 ) ), MessageImagemapAction( text='spice_bigcardamon', area=ImagemapArea( x=0, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_nutmeg', area=ImagemapArea( x=160, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_allspice', area=ImagemapArea( x=330, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_bayleaf', area=ImagemapArea( x=510, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_greencardamon', area=ImagemapArea( x=680, y=340, width=170, height=320 ) ), MessageImagemapAction( text='spice_coriander', area=ImagemapArea( x=860, y=340, width=170, height=320 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #spice_flavor_ring if event.type == "message": if (event.message.text == "Whole Spice"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/s.f.h', alt_text='spice_flavor_ring', base_size=BaseSize(height=995, width=1040), actions=[ MessageImagemapAction( text='spicy_flavor', area=ImagemapArea( x=100, y=500, width=280, height=210 ) ), MessageImagemapAction( text='sweet_flavor', area=ImagemapArea( x=390, y=60, width=240, height=230 ) ), MessageImagemapAction( text='fresh_flavor', area=ImagemapArea( x=650, y=280, width=270, height=210 ) ), MessageImagemapAction( text='bitter_flavor', area=ImagemapArea( x=380, y=710, width=260, height=240 ) ), MessageImagemapAction( text='hot_flavor', area=ImagemapArea( x=110, y=250, width=250, height=240 ) ), MessageImagemapAction( text='herb_flavor', area=ImagemapArea( x=650, y=500, width=270, height=210 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_sweet if event.type == "message": if (event.message.text == "sweet_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/sweet', alt_text='spice_flavor_ring', base_size=BaseSize(height=994, width=1040), actions=[ MessageImagemapAction( text='sweet_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='sweet_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='sweet_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='sweet_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='sweet_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='sweet_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ), MessageImagemapAction( text='sweet_7', area=ImagemapArea( x = 50, y = 660, width = 309, height = 299 ) ), MessageImagemapAction( text='sweet_8', area=ImagemapArea( x = 369, y = 661, width = 304, height = 298 ) ), MessageImagemapAction( text='sweet_9', area=ImagemapArea( x = 680, y = 661, width = 320, height = 296 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_spicy if event.type == "message": if (event.message.text == "spicy_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/spicy', alt_text='spice_flavor_ring', base_size=BaseSize(height=773, width=1040), actions=[ MessageImagemapAction( text='spicy_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='spicy_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='spicy_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_hot if event.type == "message": if (event.message.text == "hot_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/hot', alt_text='spice_flavor_ring', base_size=BaseSize(height=994, width=1040), actions=[ MessageImagemapAction( text='hot_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='hot_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='hot_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='hot_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='hot_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='hot_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_harbr if event.type == "message": if (event.message.text == "herb_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/harbr', alt_text='spice_flavor_ring', base_size=BaseSize(height=957, width=1040), actions=[ MessageImagemapAction( text='harbr_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='harbr_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='harbr_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='harbr_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='harbr_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='harbr_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_fresh if event.type == "message": if (event.message.text == "fresh_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/fresh', alt_text='spice_flavor_ring', base_size=BaseSize(height=992, width=1040), actions=[ MessageImagemapAction( text='fresh_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='fresh_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='fresh_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='fresh_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='fresh_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='fresh_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ), MessageImagemapAction( text='fresh_7', area=ImagemapArea( x = 50, y = 660, width = 309, height = 299 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #hall_spice_bitter if event.type == "message": if (event.message.text == "bitter_flavor"): TextSendMessage( text='flavor_ring', ), imagemap_message = ImagemapSendMessage( base_url='https://foodseasoning.web.fc2.com/img/hall_spice/bitter', alt_text='spice_flavor_ring', base_size=BaseSize(height=994, width=1040), actions=[ MessageImagemapAction( text='bitter_1', area=ImagemapArea( x = 61, y = 40, width = 293, height = 296 ) ), MessageImagemapAction( text='bitter_2', area=ImagemapArea( x = 366, y = 42, width = 304, height = 296 ) ), MessageImagemapAction( text='bitter_3', area=ImagemapArea( x = 681, y = 45, width = 304, height = 291 ) ), MessageImagemapAction( text='bitter_4', area=ImagemapArea( x = 61, y = 355, width = 289, height = 291 ) ), MessageImagemapAction( text='bitter_5', area=ImagemapArea( x = 366, y = 356, width = 304, height = 291 ) ), MessageImagemapAction( text='bitter_6', area=ImagemapArea( x = 677, y = 351, width = 314, height = 305 ) ), MessageImagemapAction( text='bitter_7', area=ImagemapArea( x = 50, y = 660, width = 309, height = 299 ) ), MessageImagemapAction( text='bitter_8', area=ImagemapArea( x = 369, y = 661, width = 304, height = 298 ) ) ] ) line_bot_api.push_message(event.source.user_id, imagemap_message) #クイックリプライ(spice_g) #def spice_quantity if event.type == "message": if (event.message.text == "spice_clove") or (event.message.text == "spice_allspice") or (event.message.text == "spice_nutmeg") or (event.message.text == "spice_cinnamon") or (event.message.text == "spice_bigcardamon") or (event.message.text == "spice_mace") or (event.message.text == "spice_bayleaf"): line_bot_api.reply_message( event.reply_token, TextSendMessage( text='ブレンドする量を選択してください', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction(label="小さじ1/2", text="spice_小さじ1/2") ), ]))) if event.type == "message": if (event.message.text == "spice_blackpepper") or (event.message.text == "spice_tougarashi"): line_bot_api.reply_message( event.reply_token, TextSendMessage( text='ブレンドする量を選択してください', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction(label="小さじ1/2", text="spice_小さじ1/2") ), QuickReplyButton( action=MessageAction(label="小さじ1", text="spice_小さじ1") ), ]))) if event.type == "message": if (event.message.text == "spice_greencardamon"): line_bot_api.reply_message( event.reply_token, TextSendMessage( text='ブレンドする量を選択してください', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction(label="小さじ1/2", text="spice_小さじ1/2") ), QuickReplyButton( action=MessageAction(label="小さじ1", text="spice_小さじ1") ), QuickReplyButton( action=MessageAction(label="小さじ2", text="spice_小さじ2") ), ]))) if event.type == "message": if (event.message.text == "spice_cumin") or (event.message.text == "spice_coriander"): line_bot_api.reply_message( event.reply_token, TextSendMessage( text='ブレンドする量を選択してください', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction(label="小さじ1/2", text="spice_小さじ1/2") ), QuickReplyButton( action=MessageAction(label="小さじ1", text="spice_小さじ1") ), QuickReplyButton( action=MessageAction(label="小さじ2", text="spice_小さじ2") ), QuickReplyButton( action=MessageAction(label="小さじ4", text="spice_小さじ4") ), ]))) #チキンカレー_flex if event.type == "message": if (event.message.text == "chicken_curry"): bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='https://images.unsplash.com/photo-1585937421612-70a008356fbe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60', size='full', aspect_ratio='20:13', aspect_mode='cover', ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='チキンカレー', weight='bold', size='xl'), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='材料名', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=' ①鶏モモ肉\n ②タマネギ\n ③シメジ\n ④水\n ⑤オリーブオイル\n ⑥バター', wrap=True, color='#666666', size='sm', flex=5 ) ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='spice', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=" ⑦お好きな調味料\n (トマトソース)\n ⑧お好きなスパイス", wrap=True, color='#666666', size='sm', flex=5, ), ], ), ], ) ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='primary', height='sm', action=MessageAction(label='次へ進む', text='chicken_curry_next'), ), SeparatorComponent(), ButtonComponent( style='secondary', height='sm', action=MessageAction(label='カレーを選びなおす', text="chicken_curry_cancel") ) ] ), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message( event.reply_token, message ) #チキンカレー_flex #グリーンカレー_flex if event.type == "message": if (event.message.text == "green_curry"): bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='https://images.unsplash.com/photo-1560684352-8497838a2229?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60', size='full', aspect_ratio='20:13', aspect_mode='cover', ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='グリーンカレー', weight='bold', size='xl'), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='材料名', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=' ①鶏モモ肉\n ②タマネギ\n ③ほうれん草\n ④ナス\n ⑤エリンギ\n ⑥豆乳\n ⑦オリーブオイル', wrap=True, color='#666666', size='sm', flex=5 ) ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='spice', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=" ⑦お好きな調味料\n (グリーンペースト)\n ⑧お好きなスパイス", wrap=True, color='#666666', size='sm', flex=5, ), ], ), ], ) ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='primary', height='sm', action=MessageAction(label='次へ進む', text='green_curry_next'), ), SeparatorComponent(), ButtonComponent( style='secondary', height='sm', action=MessageAction(label='カレーを選びなおす', text="green_curry_cancel") ) ] ), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message( event.reply_token, message ) #グリーンカレー_flex #キーマカレー_flex if event.type == "message": if (event.message.text == "keema_curry"): bubble = BubbleContainer( direction='ltr', hero=ImageComponent( url='https://production-orp.s3.amazonaws.com/uploads/recipes/image/0000300319/20160801160506.jpg', size='full', aspect_ratio='20:13', aspect_mode='cover', ), body=BoxComponent( layout='vertical', contents=[ # title TextComponent(text='キーマカレー', weight='bold', size='xl'), # info BoxComponent( layout='vertical', margin='lg', spacing='sm', contents=[ BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='材料名', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=' ①豚挽肉\n ②ピーマン\n ③赤ピーマン\n ④タマネギ\n ⑤ニンジン\n ⑥コーン\n ⑦水\n ⑧オリーブオイル', wrap=True, color='#666666', size='sm', flex=5 ) ], ), BoxComponent( layout='baseline', spacing='sm', contents=[ TextComponent( text='spice', color='#aaaaaa', size='sm', flex=1 ), TextComponent( text=" ⑦お好きな調味料\n (味噌ソース)\n ⑧お好きなスパイス", wrap=True, color='#666666', size='sm', flex=5, ), ], ), ], ) ], ), footer=BoxComponent( layout='vertical', spacing='sm', contents=[ SpacerComponent(size='sm'), ButtonComponent( style='primary', height='sm', action=MessageAction(label='次へ進む', text='keema_curry_next'), ), SeparatorComponent(), ButtonComponent( style='secondary', height='sm', action=MessageAction(label='カレーを選びなおす', text="keema_curry_cancel") ) ] ), ) message = FlexSendMessage(alt_text="hello", contents=bubble) line_bot_api.reply_message( event.reply_token, message ) #キーマカレー_flex message_content = line_bot_api.get_message_content(event.message.id) with tempfile.NamedTemporaryFile(dir=static_tmp_path, prefix=ext + '-', delete=False) as tf: for chunk in message_content.iter_content(): tf.write(chunk) tempfile_path = tf.name dist_path = tempfile_path + '.' + ext dist_name = os.path.basename(dist_path) os.rename(tempfile_path, dist_path) line_bot_api.reply_message( event.reply_token, [ TextSendMessage(text='Save content.'), TextSendMessage(text=request.host_url + os.path.join('static', 'tmp', dist_name)) ])
def text_message_user(self, reply_token, text_message, profile): if not 'NotTest' in text_message: message = TextSendMessage('(=OωO=)') self.reply(reply_token, message) return user_id = profile.user_id if user_id is None: user_id = self._get_provider_id() if user_id != self._get_provider_id(): message = TextSendMessage('にゃー!\n(Permission denied)') self.reply(reply_token, message) return test_messages = [ TemplateSendMessage( alt_text='Buttons template', template=ButtonsTemplate( thumbnail_image_url='https://example.com/image.jpg', title='Menu', text='Please select', actions=[ PostbackTemplateAction(label='postback', text='postback text', data='action=buy&itemid=1'), MessageTemplateAction(label='message', text='message text'), URITemplateAction(label='uri', uri='http://example.com/') ])), TemplateSendMessage( alt_text='Confirm template', template=ConfirmTemplate( text='Are you sure?', actions=[ PostbackTemplateAction(label='postback', text='postback text', data='action=buy&itemid=1'), MessageTemplateAction(label='message', text='message text') ])), TemplateSendMessage( alt_text='Carousel template', template=CarouselTemplate(columns=[ CarouselColumn( thumbnail_image_url='https://example.com/item1.jpg', title='this is menu1', text='description1', actions=[ PostbackTemplateAction(label='postback1', text='postback text1', data='action=buy&itemid=1'), MessageTemplateAction(label='message1', text='message text1'), URITemplateAction(label='uri1', uri='http://example.com/1') ]), CarouselColumn( thumbnail_image_url='https://example.com/item2.jpg', title='this is menu2', text='description2', actions=[ PostbackTemplateAction(label='postback2', text='postback text2', data='action=buy&itemid=2'), MessageTemplateAction(label='message2', text='message text2'), URITemplateAction(label='uri2', uri='http://example.com/2') ]) ])), TemplateSendMessage( alt_text='ImageCarousel template', template=ImageCarouselTemplate(columns=[ ImageCarouselColumn( image_url='https://example.com/item1.jpg', action=PostbackTemplateAction( label='postback1', text='postback text1', data='action=buy&itemid=1')), ImageCarouselColumn( image_url='https://example.com/item2.jpg', action=PostbackTemplateAction( label='postback2', text='postback text2', data='action=buy&itemid=2')) ])), ImagemapSendMessage( base_url='https://example.com/base', alt_text='this is an imagemap', base_size=BaseSize(height=1040, width=1040), actions=[ URIImagemapAction(link_uri='https://example.com/', area=ImagemapArea(x=0, y=0, width=520, height=1040)), MessageImagemapAction(text='hello', area=ImagemapArea(x=520, y=0, width=520, height=1040)) ]) ] self.reply(reply_token, test_messages) return
def sendE2Floor(event, line_bot_api): # 圖片地圖 try: message = [ # 串列 TextSendMessage( # 傳送文字 text="請選擇檢查的樓層"), ImagemapSendMessage( base_url='https://i.imgur.com/jYnxzhV.png', alt_text="This is the E2 floor's imagemap", base_size=BaseSize(height=1040, width=1040), actions=[ MessageImagemapAction(text='E2-8F', area=ImagemapArea(x=0, y=90, width=1040, height=99)), MessageImagemapAction(text='E2-7F', area=ImagemapArea(x=0, y=191, width=1040, height=79)), MessageImagemapAction(text='E2-6F', area=ImagemapArea(x=0, y=273, width=1040, height=81)), MessageImagemapAction(text='E2-5F', area=ImagemapArea(x=0, y=357, width=1040, height=77)), MessageImagemapAction(text='E2-4F', area=ImagemapArea(x=0, y=437, width=1040, height=81)), MessageImagemapAction(text='E2-3F', area=ImagemapArea(x=0, y=519, width=1040, height=83)), MessageImagemapAction(text='E2-2F', area=ImagemapArea(x=0, y=604, width=1040, height=151)), MessageImagemapAction(text='E2-1F', area=ImagemapArea(x=0, y=754, width=1040, height=206)), MessageImagemapAction(text='E2-B1', area=ImagemapArea(x=0, y=963, width=1040, height=74)) ]) ] line_bot_api.reply_message(event.reply_token, message) except: line_bot_api.reply_message( event.reply_token, TextSendMessage(text='發生錯誤!sendFloorImgMap'))
def handle_location(event): lat = event.message.latitude lon = event.message.longitude zoomlevel = 18 imagesize = 1040 # 縦横1040ピクセルの画像を取得 map_image_url = 'https://maps.googleapis.com/maps/api/staticmap?center={},{}&zoom={}&size=520x520&scale=2&maptype=roadmap&key={}'.format( lat, lon, zoomlevel, 'AIzaSyAtbs1MG9dES1JhT1gRDmx-QQtyhYpr2_g') map_image_url += '&markers=color:{}|label:{}|{},{}'.format( 'blue', '', lat, lon) # タップ可能なピンを配置する center_lat_pixel, center_lon_pixel = latlon_to_pixel(lat, lon) marker_color = 'red' label = 'E' # タップエリアのサイズ pin_width = 60 * 1.5 pin_height = 84 * 1.5 actions = [] for i, pin in enumerate(pins): # 中心の緯度経度をピクセルに変換 target_lat_pixel, target_lon_pixel = latlon_to_pixel(pin[0], pin[1]) # 差分を計算 delta_lat_pixel = (target_lat_pixel - center_lat_pixel) >> (21 - zoomlevel - 1) delta_lon_pixel = (target_lon_pixel - center_lon_pixel) >> (21 - zoomlevel - 1) marker_lat_pixel = imagesize / 2 + delta_lat_pixel marker_lon_pixel = imagesize / 2 + delta_lon_pixel x = marker_lat_pixel y = marker_lon_pixel # 範囲外のを除外 if (pin_width / 2 < x < imagesize - pin_width / 2 and pin_height < y < imagesize - pin_width): map_image_url += '&markers=color:{}|label:{}|{},{}'.format( marker_color, label, pin[0], pin[1]) actions.append( MessageImagemapAction(text=str(i), area=ImagemapArea(x=x - pin_width / 2, y=y - pin_height / 2, width=pin_width, height=pin_height))) if len(actions) > 10: break # Imagemap Message message = ImagemapSendMessage(base_url='https://{}/imagemap/{}'.format( request.host, urllib.parse.quote_plus(map_image_url)), alt_text='地図', base_size=BaseSize(height=imagesize, width=imagesize), actions=actions) line_bot_api.reply_message( event.reply_token, [TextSendMessage(text='終電まで空いている出口一覧です'), message])
imagemaps = [{ "id": "example", "payload": ImagemapSendMessage(base_url='https://example.com/base', alt_text='this is an imagemap', base_size=BaseSize(height=1040, width=1040), actions=[ URIImagemapAction(link_uri='https://example.com/', area=ImagemapArea(x=0, y=0, width=520, height=1040)), MessageImagemapAction(text='hello', area=ImagemapArea( x=520, y=0, width=520, height=1040)) ]) }, { "id": "pulsa", "payload": ImagemapSendMessage( base_url='https://bangjoni.com/pulsa_images/pulsa1', alt_text='Rich Menu Pulsa', base_size=BaseSize(height=701, width=1040), actions=[ MessageImagemapAction(text='lima ribu', area=ImagemapArea(x=0, y=0,
def send_ifLineResult_message(self, reply_token, venue, status, dist, noLine_venues): if venue == "臺中市不動產開發公會竹跡館" or venue == "楷模創生館": buttons_template = ButtonsTemplate( title='想看看' + dist + '的其他資訊嗎?', text='請點擊以下按鈕', actions=[ MessageAction(label='查詢其他展館資訊', text='查詢特定展館資訊'), MessageAction(label='查詢不用排隊的展館', text='查詢不用排隊的展館') ]) else: buttons_template = ButtonsTemplate( title='想看看' + dist + '的其他資訊嗎?', text='請點擊以下按鈕', actions=[ PostbackAction(label="現場人潮照片", data='guest-currentSituation_' + venue), MessageAction(label='查詢其他展館資訊', text='查詢特定展館資訊'), MessageAction(label='查詢不用排隊的展館', text='查詢不用排隊的展館') ]) buttons_template_message = TemplateSendMessage( alt_text='想看看' + dist + '的其他資訊嗎?', template=buttons_template) if "不用排隊" in status: pic_url = quote(venue + "_0" + ".png") imagemap_message = ImagemapSendMessage( base_url="https://2018floraexpo.tk/static/sources/ifLine/" + pic_url + "#v1.0/1024", alt_text=venue + status, base_size=BaseSize(height=1024, width=1024), actions=[ MessageImagemapAction(text="目前不用排隊,\n可以快快去" + venue + "卡位喔^_^", area=ImagemapArea(x=0, y=0, width=1024, height=1024)) ]) self.line_bot_api.reply_message( reply_token, [imagemap_message, buttons_template_message]) return if "15" in status: pic_url = quote(venue + "_15" + ".png") imagemap_message = ImagemapSendMessage( base_url="https://2018floraexpo.tk/static/sources/ifLine/" + pic_url + "#v1.1/1024", alt_text=venue + status, base_size=BaseSize(height=1024, width=1024), actions=[ MessageImagemapAction(text="目前排隊時間很少,\n可以快快去" + venue + "卡位喔^_^", area=ImagemapArea(x=0, y=0, width=1024, height=1024)) ]) self.line_bot_api.reply_message( reply_token, [imagemap_message, buttons_template_message]) return if "30分鐘" in status or "45分鐘" in status: minute = status.split("分")[0].split("約莫")[1] pic_url = quote(venue + "_" + minute + ".png") elif "1小時" in status: pic_url = quote(venue + "_60" + ".png") imagemap_message = ImagemapSendMessage( base_url="https://2018floraexpo.tk/static/sources/ifLine/" + pic_url + "#v1.2/1024", alt_text=venue + status, base_size=BaseSize(height=1024, width=1024), actions=[ MessageImagemapAction(text="我要申請排隊提醒_" + venue, area=ImagemapArea(x=0, y=0, width=1024, height=1024)) ]) text_message = TextMessage(text=venue + "等待入館時間較久,歡迎您先前往" + dist + "內其他不用排隊的展館喔") carousel_template_message = self._generate_noLine_venues_message( noLine_venues=noLine_venues) self.line_bot_api.reply_message( reply_token, [imagemap_message, buttons_template_message])
def handle_location(event): global near_station_name global near_station_address global near_station_geo_lat global near_station_geo_lon lat = event.message.latitude lon = event.message.longitude zoomlevel = 18 imagesize = 1040 # SimpleAPIから最寄駅リストを取得 near_station_url = 'http://map.simpleapi.net/stationapi?x={}&y={}&output=xml'.format( lon, lat) near_station_req = urllib.request.Request(near_station_url) with urllib.request.urlopen(near_station_req) as response: near_station_XmlData = response.read() near_station_root = ET.fromstring(near_station_XmlData) near_station_list = near_station_root.findall(".//name") near_station_n = len(near_station_list) # 最寄駅名から座標を取得 near_station_geo_url = 'https://maps.googleapis.com/maps/api/place/textsearch/xml?query={}&key={}'.format( urllib.parse.quote_plus(near_station_list[0].text, encoding='utf-8'), google_places_api_key) near_station_geo_req = urllib.request.Request(near_station_geo_url) with urllib.request.urlopen(near_station_geo_req) as response: near_station_geo_XmlData = response.read() near_station_geo_root = ET.fromstring(near_station_geo_XmlData) #最寄駅情報(名前、住所、緯度経度)を取得 near_station_name = near_station_geo_root.findtext(".//name") near_station_address = near_station_geo_root.findtext( ".//formatted_address") near_station_geo_lat = near_station_geo_root.findtext(".//lat") near_station_geo_lon = near_station_geo_root.findtext(".//lng") #徒歩時間を取得 near_station_direction_url = 'https://maps.googleapis.com/maps/api/directions/xml?origin={},{}&destination={},{}&mode=walking&key={}'.format( lat, lon, near_station_geo_lat, near_station_geo_lon, google_directions_api_key) near_station_direction_req = urllib.request.Request( near_station_direction_url) with urllib.request.urlopen(near_station_direction_req) as response: near_station_direction_XmlData = response.read() near_station_direction_root = ET.fromstring(near_station_direction_XmlData) near_station_direction_time_second = int( near_station_direction_root.findtext(".//leg/duration/value")) near_station_direction_distance_meter = int( near_station_direction_root.findtext(".//leg/distance/value")) near_station_direction_time_min = near_station_direction_time_second // 60 near_station_direction_distance_kilo = near_station_direction_distance_meter // 1000 + ( (near_station_direction_distance_meter // 100) % 10) * 0.1 map_image_url = 'https://maps.googleapis.com/maps/api/staticmap?size=520x520&scale=2&maptype=roadmap&key={}'.format( google_staticmaps_api_key) map_image_url += '&markers=color:{}|label:{}|{},{}'.format( 'red', '', near_station_geo_lat, near_station_geo_lon) map_image_url += '&markers=color:{}|label:{}|{},{}'.format( 'blue', '', lat, lon) actions = [ MessageImagemapAction(text="位置情報教えて!", area=ImagemapArea(x=0, y=0, width=1040, height=1040)) ] line_bot_api.reply_message(event.reply_token, [ ImagemapSendMessage( base_url='https://{}/imagemap/{}'.format( request.host, urllib.parse.quote_plus(map_image_url)), alt_text='地図', base_size=BaseSize(height=imagesize, width=imagesize), actions=actions, ), TextSendMessage(text=near_station_list[0].text + 'が最寄り駅です。'), TextSendMessage(text='歩いて約' + str(near_station_direction_time_min) + '分。距離は約' + str(near_station_direction_distance_kilo) + 'kmです。'), TextSendMessage(text='画像をタップすると駅の位置情報を表示できます。'), ])
} ] ) ) from linebot.models import ( ImagemapArea, BaseSize, URIImagemapAction, MessageImagemapAction,ImagemapSendMessage ) camp_search_imagemap_message = ImagemapSendMessage( base_url='https://is.gd/VKXD9X', alt_text='?��?類�?', base_size=BaseSize(height=1473,width=1040) ,actions=[ MessageImagemapAction( text="[::text:]親�??��?", area=ImagemapArea(x=7,y=271,width=513,height=128) ), MessageImagemapAction( text="[::text:]?��??��?", area=ImagemapArea(x=5,y=404,width=513,height=132) ), MessageImagemapAction( text="[::text:]觀賞�???, area=ImagemapArea(x=4,y=540,width=513,height=132) ) ] ) from linebot.models import (
def imagemap_action_msg(action): text = action['text'] tup_area = (action['x'], action['y'], action['width'], action['height']) return MessageImagemapAction(text=text, area=imagemap_area(tup_area))