예제 #1
0
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)
예제 #2
0
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))
        ])
예제 #3
0
def detect_json_array_to_new_message_array(fileName):
    # 開啟檔案,轉成json
    with open(fileName, 'r', encoding="utf-8") as f:
        jsonArray = json.load(f)

    # 解析json
    returnArray = []
    for jsonObject in jsonArray:

        # 讀取其用來判斷的元件
        message_type = jsonObject.get('type')

        # 轉換
        if message_type == 'text':
            returnArray.append(TextSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'imagemap':
            returnArray.append(ImagemapSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'template':
            returnArray.append(TemplateSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'image':
            returnArray.append(ImageSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'sticker':
            returnArray.append(StickerSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'audio':
            returnArray.append(AudioSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'location':
            returnArray.append(LocationSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'flex':
            returnArray.append(FlexSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'video':
            returnArray.append(FlexSendMessage.new_from_json_dict(jsonObject))

            # 回傳
    return returnArray
예제 #4
0
파일: app.py 프로젝트: shih674/HEROKU_DEMO
def handle_message(event):
    # 用json產生Imagemap物件
    #with open('test1.json', 'r',encoding='utf8') as jsonfile:
    #    json_object = json.load(jsonfile)
    json_object = {
        "type":
        "imagemap",
        "baseUrl":
        "https://i.imgur.com/lRAVpQ9.jpg",
        "altText":
        "This is an imagemap",
        "baseSize": {
            "width": 1040,
            "height": 868
        },
        "actions": [{
            "type": "message",
            "area": {
                "x": 66,
                "y": 40,
                "width": 932,
                "height": 523
            },
            "text": "機車"
        }]
    }
    Imagemap_from_json = ImagemapSendMessage.new_from_json_dict(json_object)
    # 請line bot api回復文字訊息
    line_bot_api.reply_message(
        event.reply_token,
        [TextSendMessage(text=event.message.text), Imagemap_from_json])
예제 #5
0
 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())
예제 #6
0
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)
예제 #7
0
파일: wt.py 프로젝트: catchsob/wtit
def detect_json_array_to_new_message_array(fn):    
    with open(fn, encoding='utf8') as f:
        jsonArray = json.load(f)
    
    returnArray = []
    for jsonObject in jsonArray:
        message_type = jsonObject.get('type')
        if message_type == 'text':
            returnArray.append(TextSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'imagemap':
            returnArray.append(ImagemapSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'template':
            returnArray.append(TemplateSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'image':
            returnArray.append(ImageSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'sticker':
            returnArray.append(StickerSendMessage.new_from_json_dict(jsonObject))  
        elif message_type == 'audio':
            returnArray.append(AudioSendMessage.new_from_json_dict(jsonObject))  
        elif message_type == 'location':
            returnArray.append(LocationSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'flex':
            returnArray.append(FlexSendMessage.new_from_json_dict(jsonObject))    

    return returnArray
예제 #8
0
def detect_json_array_to_new_message_array(fileName):
    ''' message_type 判斷器

        讀取指定的 json檔,解析成不同格式的 SendMessage
    '''
    with open(fileName, 'r', encoding='utf8') as f:
        jsonArray = json.load(f)
    
    newmessage_Array = []
    for jsonObject in jsonArray:
        message_type = jsonObject.get('type')
        
        if message_type == 'text':
            newmessage_Array.append(TextSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'sticker':
            newmessage_Array.append(StickerSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'image':
            newmessage_Array.append(ImageSendMessage.new_from_json_dict(jsonObject))  
        elif message_type == 'video':
            newmessage_Array.append(VideoSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'audio':
            newmessage_Array.append(AudioSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'location':
            newmessage_Array.append(LocationSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'imagemap':
            newmessage_Array.append(ImagemapSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'template':
            newmessage_Array.append(TemplateSendMessage.new_from_json_dict(jsonObject))
        elif message_type == 'flex':
            newmessage_Array.append(FlexSendMessage.new_from_json_dict(jsonObject))        

    return newmessage_Array
예제 #9
0
def make_reversi_imagemap(data, putable):
    imagemap_message = ImagemapSendMessage(
        base_url=hostname + "/boards/{}".format(data),
        alt_text='reversi board',
        base_size=BaseSize(height=1040, width=1040),
        actions=[make_reversi_action(p) for p in putable])
    return imagemap_message
예제 #10
0
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='發生錯誤!'))
예제 #11
0
파일: app.py 프로젝트: yb300k/5secvote
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
예제 #12
0
파일: app.py 프로젝트: yb300k/5secvote
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
예제 #13
0
파일: app.py 프로젝트: johshisha/resas2017
def googlemap_imagemap_view(text):
    googlemap_geocoding_api_key = app.config['GOOGLE_MAP_API_KEY']
    googlemap_geocoding_base_url = "https://maps.googleapis.com/maps/api/geocode/json?"
    googlemap_geocoding_query = urllib.parse.urlencode({
        "address":
        text,
        "key":
        googlemap_geocoding_api_key
    })
    try:
        req = requests.get(googlemap_geocoding_base_url +
                           googlemap_geocoding_query)
        result = json.loads(req.text)
        lat = result["results"][0]["geometry"]["location"]["lat"]
        lng = result["results"][0]["geometry"]["location"]["lng"]
        googlemap_staticmap_api_key = app.config['GOOGLE_STATIC_MAPS_API_KEY']
        googlemap_staticmap_base_url = "https://maps.googleapis.com/maps/api/staticmap?"
        googlemap_staticmap_query = urllib.parse.urlencode({
            "center":
            "%s,%s" % (lat, lng),
            "size":
            "520x520",
            "sensor":
            "false",
            "scale":
            2,
            "maptype":
            "roadmap",
            "zoom":
            18,
            "markers":
            "%s,%s" % (lat, lng),
            "key":
            googlemap_staticmap_api_key
        })
        googlemap_staticmap_url = googlemap_staticmap_base_url + googlemap_staticmap_query

        view = ImagemapSendMessage(
            base_url='https://{}/imagemap/{}'.format(
                request.host,
                urllib.parse.quote_plus(googlemap_staticmap_url)),
            alt_text='googlemap',
            base_size=BaseSize(height=1040, width=1040),
            actions=[
                URIImagemapAction(
                    # link_uri='comgooglemaps://?ll=%f,%f&q=%s' % (lat, lng, text),
                    link_uri='http://maps.google.co.jp/maps?q=%f,%f' %
                    (lat, lng),
                    area=ImagemapArea(x=0, y=0, width=1040, height=1040))
            ])

    except:
        view = TextSendMessage(text="ん〜〜「%s」はGoogleMapにないなぁ..." % text)

    return view
예제 #14
0
    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
                    }
                }
            ]
        }]
예제 #15
0
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
예제 #16
0
def push_ads(user_id):
    #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'
    photo_url, link_url, action_list = get_ads_info()
    imagemap_message = ImagemapSendMessage(
        base_url=photo_url,
        alt_text='this is an imagemap',
        base_size=BaseSize(height=1024, width=1024),
        actions=action_list
    )
    push_message(user_id, imagemap_message)
예제 #17
0
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
예제 #18
0
 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
예제 #19
0
 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)
예제 #20
0
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)
예제 #21
0
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_text_message(event):
    message_content: str = event.message.text

    if message_content in keywords_template_menu:
        with open(message_content + '/reply.json', 'r', encoding='utf8') as f:
            reply_json = json.load(f)
        reply_send_message = TemplateSendMessage.new_from_json_dict(reply_json)
        line_bot_api.reply_message(event.reply_token, reply_send_message)
    elif message_content in keywords_query_product_text:  #之後建立好營養標示section要合併/刪除
        with open("product_info_buttun/" + message_content + '/reply.json',
                  'r',
                  encoding='utf8') as f:
            reply_json = json.load(f)
        reply_send_message = TemplateSendMessage.new_from_json_dict(reply_json)
        line_bot_api.reply_message(event.reply_token, reply_send_message)

    elif message_content in keywords_text:
        line_bot_api.reply_message(
            event.reply_token, TextSendMessage(keywords_text[message_content]))
    elif message_content in keywords_change_rich_menu:
        if message_content == '怎麼運送?':
            line_bot_api.reply_message(
                event.reply_token,
                TextSendMessage(
                    '冷鏈(Cold Chain),是冷凍供應鏈,由冷凍加工、貯藏、物流運輸、銷售構成。\n\n冷鏈技術是消費者最終能否買到高品質產品重要的因素。'
                ))
            line_bot_api.link_rich_menu_to_user(
                event.source.user_id,
                keywords_change_rich_menu[message_content])
        else:
            line_bot_api.link_rich_menu_to_user(
                event.source.user_id,
                keywords_change_rich_menu[message_content])
    elif message_content in keywords_imagemap:
        if message_content == '產品選單':
            with open(message_content + '/reply.json', 'r',
                      encoding='utf8') as f:
                reply_json = json.load(f)
            image_message = ImagemapSendMessage.new_from_json_dict(reply_json)
            line_bot_api.reply_message(event.reply_token, image_message)

    else:
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage('看看選單其他功能吧'))
예제 #23
0
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 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)
예제 #25
0
    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')
예제 #26
0
def create_img_map_msg():
    actions = []
    actions.append(URIImagemapAction(
        link_uri='line://app/1614481927-WbXaLGy0',
        area=ImagemapArea(
            x=0, y=0, width=520, height=520
    )
    ))
    actions.append(URIImagemapAction(
        link_uri='line://app/1614481927-BqrGLbvl',
        area=ImagemapArea(
            x=0, y=520, width=520, height=520
        )
    ))
    actions.append(URIImagemapAction(
        link_uri='line://app/1614481927-2N50kX34',
        area=ImagemapArea(
            x=520, y=0, width=520, height=520
        )
    ))
    actions.append(URIImagemapAction(
        link_uri='line://app/1614481927-WLrPnOXQ',
        area=ImagemapArea(
            x=520, y=520, width=520, height=520
        )

    ))

    message = ImagemapSendMessage(
        base_url='https://' + request.host + '/imagemap/' + uuid.uuid4().hex,
        alt_text='こんにちは!',
        base_size=BaseSize(height=1040, width=1040),
        actions=actions
    )

    return message
예제 #27
0
        ]
    )
)

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 (
예제 #28
0
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))
        ])
예제 #29
0
# In[ ]:

#小遊戲imagemap
from linebot.models import (ImagemapArea, BaseSize, URIImagemapAction,
                            MessageImagemapAction, ImagemapSendMessage)

game_imagemap_message = ImagemapSendMessage(
    base_url='https://is.gd/b6IhTz',
    alt_text='小遊戲',
    base_size=BaseSize(height=624, width=1040),
    actions=[
        URIImagemapAction(link_uri="https://play.famobi.com/surfer-archers",
                          area=ImagemapArea(x=4, y=4, width=341, height=312)),
        URIImagemapAction(
            link_uri="https://play.famobi.com/highway-rider-extreme",
            area=ImagemapArea(x=347, y=0, width=341, height=312)),
        URIImagemapAction(link_uri="https://play.famobi.com/high-hills",
                          area=ImagemapArea(x=699, y=0, width=341,
                                            height=312)),
        URIImagemapAction(link_uri="https://play.famobi.com/pizza-ninja-3",
                          area=ImagemapArea(x=5, y=312, width=341,
                                            height=312)),
        URIImagemapAction(
            link_uri="https://play.famobi.com/billiard-blitz-challenge",
            area=ImagemapArea(x=349, y=312, width=341, height=312)),
        URIImagemapAction(
            link_uri="https://play.famobi.com/angry-flappy-wings",
            area=ImagemapArea(x=692, y=312, width=341, height=312))
    ])
예제 #30
0
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)))
    ])