Exemple #1
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='發生錯誤!'))
Exemple #2
0
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
Exemple #3
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
                    }
                }
            ]
        }]
Exemple #4
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
Exemple #5
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))
        ])
Exemple #6
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)
Exemple #7
0
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
Exemple #8
0
#!/usr/bin/env python
# coding: utf-8

# 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))
Exemple #9
0
    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
Exemple #10
0
def art(reply_token):
    image_url1 = createUri('/static/pics/AI1.jpg')
    image_url2 = createUri('/static/pics/PI1.jpg')
    image_url3 = createUri('/static/pics/PI2.png')
    image_url4 = createUri('/static/pics/PS2.jpg')
    image_url5 = createUri('/static/pics/PS2-1.png')
    image_url6 = createUri('/static/pics/PS3.jpg')
    image_url7 = createUri('/static/pics/PS3-1.jpg')
    image_url8 = createUri('/static/pics/PS5.jpg')
    image_url9 = createUri('/static/pics/PS5-1.png')

    imagemap_message1 = ImagemapSendMessage(
        base_url=createUri('/static/pics/imagemap'),
        alt_text='繪畫作品',
        base_size=BaseSize(height=1040, width=1040),
        actions=[
            URIImagemapAction(link_uri=image_url1,
                              area=ImagemapArea(x=0,
                                                y=0,
                                                width=520,
                                                height=520)),
            URIImagemapAction(link_uri=image_url2,
                              area=ImagemapArea(x=520,
                                                y=0,
                                                width=520,
                                                height=520)),
            URIImagemapAction(link_uri=image_url3,
                              area=ImagemapArea(x=0,
                                                y=520,
                                                width=1040,
                                                height=520))
        ])

    imagemap_message2 = ImagemapSendMessage(
        base_url=createUri('/static/pics/imagemap2'),
        alt_text='修圖作品',
        base_size=BaseSize(height=1040, width=1040),
        actions=[
            URIImagemapAction(link_uri=image_url4,
                              area=ImagemapArea(x=0,
                                                y=0,
                                                width=475,
                                                height=325)),
            URIImagemapAction(link_uri=image_url5,
                              area=ImagemapArea(x=565,
                                                y=0,
                                                width=475,
                                                height=325)),
            URIImagemapAction(link_uri=image_url6,
                              area=ImagemapArea(x=0,
                                                y=325,
                                                width=475,
                                                height=325)),
            URIImagemapAction(link_uri=image_url7,
                              area=ImagemapArea(x=565,
                                                y=325,
                                                width=475,
                                                height=325)),
            URIImagemapAction(link_uri=image_url8,
                              area=ImagemapArea(x=0,
                                                y=650,
                                                width=475,
                                                height=390)),
            URIImagemapAction(link_uri=image_url9,
                              area=ImagemapArea(x=565,
                                                y=650,
                                                width=475,
                                                height=390))
        ])

    line_bot_api.reply_message(reply_token,
                               [imagemap_message1, imagemap_message2])
Exemple #11
0
from linebot.models import ImagemapArea
from linebot.models import ImagemapSendMessage
from linebot.models import MessageImagemapAction
from linebot.models import URIImagemapAction

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',
Exemple #12
0
    def setUp(self):
        self.tested = LineBotApi('channel_secret')

        self.imagemap_message = ImagemapSendMessage(
            base_url='https://example.com/base',
            alt_text='this is an imagemap',
            base_size=BaseSize(height=1040, width=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(
                    link_uri='https://example.com/see_more.html',
                    label='See More',
                ),
            ),
            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
            },
            "video": {
                "originalContentUrl": "https://example.com/video.mp4",
                "previewImageUrl": "https://example.com/video_preview.jpg",
                "area": {
                    "x": 0,
                    "y": 0,
                    "width": 1040,
                    "height": 585
                },
                "externalLink": {
                    "linkUri": "https://example.com/see_more.html",
                    "label": "See More"
                }
            },
            "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
                    }
                }
            ]
        }]
Exemple #13
0
def handle_message(event):
    logging.error(event)
    model = 'w2v.mod'
    model_loaded = Word2Vec.load(model)
    candidates = []
    with open('target.txt', 'r', encoding='utf-8') as f:
        for line in f:
            candidates.append(line.strip().split())
    Ans = []
    with open('A.txt', 'r', encoding='utf-8') as fs:
        for line in fs:
            a = line.replace("\\n", " ")
            Ans.append(a.strip())

    if (event.message.text == "時價登錄"):
        answer = " 請輸入欲查詢地區(只限台北市),仿照下列格式 — 例: [台北市信義區] "
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=answer))

    elif (event.message.text == "GPS定位功能"):
        answer = " 只要上傳你的定位資訊,我們便會提供給你:\n該地區(限台北市)商業活絡程度及房屋資訊喔!!"
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=answer))

    elif (event.message.text == "商業活絡程度"):
        answer = " 請輸入欲查詢地區(只限台北市),仿照下列格式 — 例: [台北市信義區資訊] "
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=answer))

    elif ((len(event.message.text) == 10) and event.message.text[1:4] == "台北市"
          and event.message.text[6] == "區" and event.message.text[0] == "["
          and event.message.text[9] == "]"
          and event.message.text[7:9] == '資訊'):
        find = event.message.text[1:7]
        uri = 'https://jshare.com.cn/temp/' + str(areafin(
            find[3:6])) + '/share/pure'
        answer = find + '的商業活絡程度請連結至以下網址:  \n' + uri
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=answer))

    elif ((len(event.message.text) == 8) and event.message.text[1:4] == "台北市"
          and event.message.text[6] == "區" and event.message.text[0] == "["
          and event.message.text[7] == "]"):
        columns = []
        House_Name = []
        Price_Num = []
        House_Site = []
        House_Web = []
        sqlsearch(event.message.text[1:7], House_Name, Price_Num, House_Site,
                  House_Web)

        max_num = 0
        if (len(House_Name) >= 10):
            max_num = 10
        else:
            max_num = len(House_Name)
        r2 = []
        for i in range(0, len(House_Name), 1):
            r2.append(i)
        r1 = random.sample(r2, k=max_num)
        count = 0
        if (max_num > 0):
            if (count == 0):
                columns.append(
                    CarouselColumn(
                        # thumbnail_image_url=str(House_Img[count]),
                        title='台北市的標準住宅單價(萬元/坪)趨勢',
                        text='提供近幾年該地區的每坪價格的趨勢給你參考',
                        actions=[
                            URITemplateAction(
                                label='連結網址',
                                uri='https://www.itushuo.com/embed/wqgsi')
                        ]))
                count += 1
            while (count < max_num - 1):
                columns.append(
                    CarouselColumn(
                        # thumbnail_image_url=str(House_Img[count]),
                        title=str(House_Name[r1[count]]),
                        text='價錢:' + str(Price_Num[r1[count]]) + '萬元\n位置:' +
                        str(House_Site[r1[count]]),
                        actions=[
                            URITemplateAction(label='連結網址',
                                              uri=str(House_Web[r1[count]]))
                        ]))
                count += 1
            columns.append(
                CarouselColumn(
                    # thumbnail_image_url=str(House_Img[count]),
                    title=str(House_Name[r1[count]]),
                    text='價錢:' + str(Price_Num[r1[count]]) + '萬元\n位置:' +
                    str(House_Site[r1[count]]),
                    actions=[
                        URITemplateAction(label='連結網址',
                                          uri=str(House_Web[r1[count]]))
                    ]))
            logging.error(columns)
            Carousel_template = TemplateSendMessage(
                alt_text='Carousel template',
                template=CarouselTemplate(columns))
            line_bot_api.reply_message(event.reply_token, Carousel_template)
        else:
            ar = '抱歉沒有找到該地區房價,請搜尋其他地區!'
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text=ar))

    elif ((len(event.message.text) == 5)
          and event.message.text[0:5] == "生活小幫手"):
        imagemap_message = ImagemapSendMessage(
            base_url='https://i.imgur.com/MNlaWgX.jpg',
            alt_text='this is an imagemap',
            base_size=BaseSize(height=1040, width=1040),
            actions=[
                URIImagemapAction(
                    link_uri=
                    'https://drive.google.com/open?id=1jyyA5J5OudRCsykJI4yWcqdXKoYgN3rY&usp=sharing',
                    area=ImagemapArea(x=0, y=0, width=519, height=440)),
                URIImagemapAction(
                    link_uri=
                    'https://drive.google.com/open?id=1j9MZriaPTJVcQGzhGxNql2-uWOfII-vB&usp=sharing',
                    area=ImagemapArea(x=520, y=0, width=519, height=440)),
                URIImagemapAction(
                    link_uri=
                    'https://drive.google.com/open?id=1hvKl65mWcmfDQRywnLsmcqJSgo3pJPTI&usp=sharing',
                    area=ImagemapArea(x=0, y=441, width=519, height=440)),
                URIImagemapAction(
                    link_uri=
                    'https://drive.google.com/open?id=1CKWg04o8Sq-tEgbcVmWQZEf68CZJdJsI&usp=sharing',
                    area=ImagemapArea(x=520, y=441, width=519, height=440)),
            ])
        line_bot_api.reply_message(event.reply_token, imagemap_message)

    else:
        while True:
            text = event.message.text
            words = list(jieba.cut(text.strip(), cut_all=False))
            res = []
            index = 0
            for candidate in candidates:
                # print candidate
                score = model_loaded.n_similarity(words, candidate)
                res.append(ResultInfo(index, score, " ".join(candidate)))
                index += 1
            res.sort(key=lambda x: x.score, reverse=True)
            k = 0
            count = 0
            dans = ""
            dans += "我們將從資料庫中找出幾筆最相關的Q&A給您\n"
            for i in res:
                k += 1
                if i.score > 0.6:
                    dans += "Q" + str(count + 1) + " : " + (i.text) + "\n"
                    dans += "A" + str(count + 1) + " : " + Ans[i.id] + "\n"
                    count += 1
                    if k > 9 or count == 3:
                        break
            if count == 0:
                ans = "請換個方式問問看"
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=ans))
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text=dans))
Exemple #14
0
def handle_message(event):
    #--將使用者發送的訊息儲存再msg變數
    msg = event.message.text
    msglist = event.message.text.split()
    #--透過datetime取的目前UTC+8的時間,並且編排樣式
    nowTime = (datetime.datetime.utcnow() +
               datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S")
    today = (datetime.datetime.utcnow() +
             datetime.timedelta(hours=8)).strftime("%Y-%m-%d")
    week = (datetime.datetime.utcnow() + datetime.timedelta(hours=8) +
            datetime.timedelta(days=6)).strftime("%Y-%m-%d")
    #--透過LINE API取的使用者ID
    UID = event.source.user_id
    #--透過LINE API和使用者ID取的使用者資料
    profile = line_bot_api.get_profile(UID)
    #--透過使用者資料取得使用者的名稱
    displayName = profile.display_name
    #--透過使用者資料取的使用者的照片
    pictureUrl = profile.picture_url
    #--尚未註冊訊息回復
    Not_registered = [
        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))
            ])
    ]
    if msg == "註冊":
        if len(UID) > 0:
            data = chk_user(UID)
            if data is None:
                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)
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text="已經註冊過!"))

    elif msglist[0] == "$註冊":
        data = chk_user(UID)
        if data is None:
            if len(msglist) == 3:
                SQL = "select Student_ID from basic_info where Del_YN='N' and cName='" + msglist[
                    1] + "' and Student_ID='" + msglist[2] + "'"
                data = SQL_select(SQL)
                if data is not None:
                    SQL = "INSERT INTO userdata (Line_UID,cName,Student_ID,AddDate) VALUES ('" + UID + "',N'" + msglist[
                        1] + "','" + msglist[2] + "','" + nowTime + "')"
                    SQL_commit(SQL)
                    line_bot_api.reply_message(
                        event.reply_token,
                        TextSendMessage(text="已完成註冊! 請在手機使用選單功能~"))
                else:
                    line_bot_api.reply_message(
                        event.reply_token, TextSendMessage(text="您不符合註冊資格!"))
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text="資料不完整!"))
        else:
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text="已經註冊過!"))

    elif msg == "課表查詢":
        data = chk_user(UID)
        if data is not None:
            student_ID = chk_student_ID(UID)
            Class = chk_class(student_ID)
            SQL = "select Class,Date,Course,T_course from course_table where Del_YN='N' and Class='" + Class + "' and Date between '" + today + "' and '" + week + "' order BY Date"
            data = SQL_select_all(SQL)
            if data is not None:
                Date = ""
                for x in range(0, len(data)):
                    data2 = data[x]
                    T_course = list(str(data2[3]))
                    T_course_type = ""
                    for y in range(0, len(T_course)):
                        if T_course[y] == "1":
                            T_course_type = T_course_type + "上午 "
                        elif T_course[y] == "2":
                            T_course_type = T_course_type + "下午 "
                        elif T_course[y] == "3":
                            T_course_type = T_course_type + "夜間 "
                    Date = Date + "日期:" + str(
                        data2[1].strftime("%Y-%m-%d")) + "\n" + "課程名稱:" + str(
                            data2[2]) + " " + T_course_type + "\n\n"
                content = "班級:" + str(Class) + "\n" + Date
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(content))
            else:
                content = str(today) + "~" + str(week) + " 沒課"
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(content))
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msg == "缺勤查詢":
        data = chk_user(UID)
        if data is not None:
            student_ID = chk_student_ID(UID)
            cName = data[1]
            SQL = "select Hours,status from missing_class where Del_YN='N' and student_ID='" + student_ID + "'"
            data = SQL_select_all(SQL)
            if data is not None:
                Absentee = 0
                sick = 0
                Casual = 0
                Statutory = 0
                Maternity = 0
                Funeral = 0
                for x in range(0, len(data)):
                    data2 = data[x]
                    if data2[1] == 0:
                        Absentee = int(Absentee) + int(data2[0])
                    elif data2[1] == 1:
                        sick = int(sick) + int(data2[0])
                    elif data2[1] == 2:
                        Casual = int(Casual) + int(data2[0])
                    elif data2[1] == 3:
                        Statutory = int(Statutory) + int(data2[0])
                    elif data2[1] == 4:
                        Maternity = int(Maternity) + int(data2[0])
                    elif data2[1] == 5:
                        Funeral = int(Funeral) + int(data2[0])
                Count = int(Absentee) * 2 + int(sick) + int(Casual) + int(
                    Statutory) + int(Maternity) + int(Funeral)
                content = "查詢人:" + cName + "\n" + "曠課時數:" + str(
                    Absentee) + "\n" + "病假時數:" + str(
                        sick) + "\n" + "事假時數:" + str(Casual) + "\n"
                content = content + "公假時數:" + str(
                    Statutory) + "\n" + "娩假時數:" + str(
                        Maternity) + "\n" + "喪假時數:" + str(
                            Funeral) + "\n" + "缺勤總時數:" + str(Count)
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(content))
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text="無缺勤紀錄!"))
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msg == "維修申請":
        data = chk_user(UID)
        if data is not None:
            buttons_template_message = TemplateSendMessage(
                alt_text='維修申請選單',
                template=ButtonsTemplate(
                    #thumbnail_image_url='',
                    title='維修申請選單',
                    text='請選擇',
                    actions=[
                        MessageAction(label='報修紀錄查詢', text='報修紀錄查詢'),
                        MessageAction(label='申請設備維修', text='申請設備維修')
                    ]))
            line_bot_api.reply_message(event.reply_token,
                                       buttons_template_message)
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msg == "報修紀錄查詢":
        data = chk_user(UID)
        if data is not None:
            student_ID = chk_student_ID(UID)
            SQL = "select Class,Student_ID,Device,Remark,Room,Seat,AddDate from device_service where Del_YN='N' and student_ID='" + student_ID + "' order BY AddDate desc"
            data = SQL_select(SQL)
            if data is not None:
                cName_apply = chk_cName(data[1])
                content = "最新一筆紀錄如下\n申請人班級:" + str(
                    data[0]) + "\n" + "申請者:" + str(
                        cName_apply) + "\n" + "報修設備:" + str(data[2]) + "\n"
                content = content + "設備徵狀:" + str(
                    data[3]) + "\n" + "教室:" + str(
                        data[4]) + "\n" + "座位座標:" + str(
                            data[5]) + "\n" + "申請日期:" + str(
                                data[6].strftime("%Y-%m-%d"))
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(content))
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text="無報修紀錄!"))
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msg == "申請設備維修":
        data = chk_user(UID)
        if data is not None:
            sendMessage = [
                ImagemapSendMessage(
                    base_url='https://dc10101.serveo.net/static/3/',
                    alt_text='3',
                    base_size=BaseSize(height=1040, width=1040),
                    actions=[
                        URIImagemapAction(
                            link_uri=
                            'https://dc10101.serveo.net/static/3/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)
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msglist[0] == "$維修":
        data = chk_user(UID)
        if data is not None:
            if len(msglist) == 5:
                student_ID = chk_student_ID(UID)
                Class = chk_class(student_ID)
                SQL = "INSERT INTO device_service (Class,Student_ID,Device,Remark,Room,Seat,AddDate) VALUES ('" + Class + "','" + student_ID + "','" + msglist[
                    1] + "','" + msglist[2] + "','" + msglist[
                        3] + "','" + msglist[4] + "','" + nowTime + "')"
                SQL_commit(SQL)
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text="報修成功!"))
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text="資料不完整!"))
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msg == "機房申請":
        data = chk_user(UID)
        if data is not None:
            sendMessage = [
                ImagemapSendMessage(
                    base_url='https://dc10101.serveo.net/static/5/',
                    alt_text='5',
                    base_size=BaseSize(height=1040, width=1040),
                    actions=[
                        URIImagemapAction(
                            link_uri=
                            'https://dc10101.serveo.net/static/5/1040.png',
                            area=ImagemapArea(x=0,
                                              y=0,
                                              width=1040,
                                              height=1040)),
                        MessageImagemapAction(text='辦法',
                                              area=ImagemapArea(x=520,
                                                                y=0,
                                                                width=50,
                                                                height=50))
                    ]),
                TemplateSendMessage(
                    alt_text='機房申請選單',
                    template=ButtonsTemplate(
                        #thumbnail_image_url='',
                        title='機房申請選單',
                        text='請選擇',
                        actions=[
                            MessageAction(label='機房申請查詢', text='機房申請查詢'),
                            MessageAction(label='申請機房使用', text='申請機房使用'),
                            URIAction(label='機房借用情況一覽表',
                                      uri='http://bit.ly/2E7emtS')
                        ]))
            ]
            line_bot_api.reply_message(event.reply_token, sendMessage)
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msg == "機房申請查詢":
        data = chk_user(UID)
        if data is not None:
            student_ID = chk_student_ID(UID)
            Class = chk_class(student_ID)
            SQL = "select Class,Student_ID,Date,Room,Pepole,AddDate from room_apply where Del_YN='N' and Class='" + Class + "' and Date>='" + today + "' order BY Date"
            data = SQL_select(SQL)
            if data is not None:
                cName_apply = chk_cName(data[1])
                Date = data[2].strftime("%Y-%m-%d")
                content = "離本日最近一筆紀錄如下\n申請人班級:" + str(
                    data[0]) + "\n" + "申請者:" + str(
                        cName_apply) + "\n" + "使用日期:" + str(Date) + "\n"
                content = content + "申請機房:" + str(
                    data[3]) + "\n" + "使用人數:" + str(
                        data[4]) + "\n" + "申請日期:" + str(
                            data[5].strftime("%Y-%m-%d"))
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(content))
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text="無機房申請紀錄!"))
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msg == "申請機房使用":
        data = chk_user(UID)
        if data is not None:
            sendMessage = [
                ImagemapSendMessage(
                    base_url='https://dc10101.serveo.net/static/4/',
                    alt_text='4',
                    base_size=BaseSize(height=1040, width=1040),
                    actions=[
                        URIImagemapAction(
                            link_uri=
                            'https://dc10101.serveo.net/static/4/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)
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msglist[0] == "$機房":
        data = chk_user(UID)
        if data is not None:
            if len(msglist) == 4:
                student_ID = chk_student_ID(UID)
                Class = chk_class(student_ID)
                if msglist[1] >= today:
                    if msglist[1] <= week:
                        if int(msglist[3]) > 5:
                            SQL = "select Date from room_apply where Del_YN='N' and Class='" + Class + "' and Date='" + msglist[
                                1] + "' and Room='" + msglist[2] + "'"
                            data = SQL_select(SQL)
                            if data is None:
                                SQL = "INSERT INTO room_apply (Class,Student_ID,Date,Room,Pepole,AddDate) VALUES ('" + Class + "','" + student_ID + "','" + msglist[
                                    1] + "','" + msglist[2] + "','" + msglist[
                                        3] + "','" + nowTime + "')"
                                SQL_commit(SQL)
                                line_bot_api.reply_message(
                                    event.reply_token,
                                    TextSendMessage(text="機房申請成功!"))
                            else:
                                line_bot_api.reply_message(
                                    event.reply_token,
                                    TextSendMessage(text="此日期的機房已被申請!"))
                        else:
                            line_bot_api.reply_message(
                                event.reply_token,
                                TextSendMessage(text="使用人數不得小於6人!"))
                    else:
                        line_bot_api.reply_message(
                            event.reply_token,
                            TextSendMessage(text="僅能申請一周內日期!"))
                else:
                    line_bot_api.reply_message(
                        event.reply_token, TextSendMessage(text="不可申請過去日期!"))
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text="資料不完整!"))
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msg == "意見回饋":
        data = chk_user(UID)
        if data is not None:
            sendMessage = [
                ImagemapSendMessage(
                    base_url='https://dc10101.serveo.net/static/2/',
                    alt_text='2',
                    base_size=BaseSize(height=1040, width=1040),
                    actions=[
                        URIImagemapAction(
                            link_uri=
                            'https://dc10101.serveo.net/static/2/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)
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msglist[0] == "$意見":
        data = chk_user(UID)
        if data is not None:
            if len(msglist) >= 2:
                student_ID = chk_student_ID(UID)
                Class = chk_class(student_ID)
                cName = data[1]
                content = msg[4:]
                SQL = "SELECT COUNT(Student_ID) from feedback where Del_YN='N' and Student_ID='" + student_ID + "' AND DATE_FORMAT(AddDate, '%Y-%m-%d')='" + today + "'"
                data = SQL_select(SQL)
                if data[0] < 4:
                    SQL = "INSERT INTO feedback (Line_UID,Class,Student_ID,cName,content,AddDate) VALUES ('" + UID + "','" + Class + "','" + student_ID + "','" + cName + "',N'" + content + "','" + nowTime + "')"
                    SQL_commit(SQL)
                    line_bot_api.reply_message(event.reply_token,
                                               TextSendMessage(text="意見發送成功!"))
                else:
                    line_bot_api.reply_message(
                        event.reply_token, TextSendMessage(text="當日意見不可超過5次!"))
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text="資料不完整!"))
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    elif msg == "test":
        data = chk_user(UID)
        if data is not None:
            sendMessage = [
                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)
        else:
            line_bot_api.reply_message(event.reply_token, Not_registered)

    else:
        data = chk_user(UID)
        if data is None:
            line_bot_api.reply_message(event.reply_token, Not_registered)
        else:
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(text="請使用功能選單!"))
    def message_event(event):
        if buttonRegex.search(event.message.text):
            line_bot_api.reply_message(
                event.reply_token,
                TemplateSendMessage(
                    alt_text='Buttons template',
                    template=ButtonsTemplate(
                        thumbnail_image_url=demo_image_url,
                        title='Menu',
                        text='Please select',
                        actions=[
                            PostbackTemplateAction(
                                label='postback',
                                display_text='postback text',
                                data='action=buy&itemid=1'),
                            MessageTemplateAction(label='message',
                                                  text='message text'),
                            URITemplateAction(label='uri',
                                              uri='http://example.com/')
                        ])))
        elif stickerRegex.search(event.message.text.lower()):
            # https://developers.line.me/en/docs/messaging-api/reference/#sticker-message
            # https://developers.line.me/media/messaging-api/sticker_list.pdf
            line_bot_api.reply_message(
                event.reply_token,
                StickerSendMessage(package_id='1', sticker_id='116'))
        elif imageRegex.search(event.message.text.lower()):
            # https://developers.line.me/en/docs/messaging-api/reference/#image-message
            line_bot_api.reply_message(
                event.reply_token,
                ImageSendMessage(
                    original_content_url=
                    f'{PUBLIC_URL}/static/images/spring.jpg',
                    preview_image_url=f'{PUBLIC_URL}/static/images/spring.jpg')
            )
        elif videoRegex.search(event.message.text.lower()):
            # https://developers.line.me/en/docs/messaging-api/reference/#video-message
            line_bot_api.reply_message(
                event.reply_token,
                VideoSendMessage(
                    original_content_url=
                    f'{PUBLIC_URL}/static/videos/linebot_video_sample.mp4',
                    preview_image_url=
                    f'{PUBLIC_URL}/static/images/video_preview.jpg'))
        elif locationRegex.search(event.message.text.lower()):
            # https://developers.line.me/en/docs/messaging-api/reference/#location-message
            line_bot_api.reply_message(
                event.reply_token,
                LocationSendMessage(title='京都アスニー',
                                    address='京都市中京区聚楽廻松下町9-2',
                                    latitude=35.0190007,
                                    longitude=135.7362375))
        elif event.message.text == 'カルーセル':
            # https://developers.line.me/en/docs/messaging-api/reference/#carousel
            line_bot_api.reply_message(
                event.reply_token,
                TemplateSendMessage(
                    alt_text='Carousel template',
                    template=CarouselTemplate(columns=[
                        CarouselColumn(
                            thumbnail_image_url=
                            f'{PUBLIC_URL}/static/images/image_carousel_1.jpg',
                            title='マンホール',
                            text='函館、十字街電停周辺で見つけた',
                            actions=[
                                PostbackAction(label='いいね',
                                               display_text='いいね!',
                                               data='action=like&item_id=1'),
                                MessageAction(label='何かしらのラベル',
                                              text='何かしらのメッセージ'),
                                URIAction(label='詳細を見る',
                                          uri='http://example.com/1')
                            ]),
                        CarouselColumn(
                            thumbnail_image_url=
                            f'{PUBLIC_URL}/static/images/image_carousel_2.jpg',
                            title='白鷺',
                            text='平安神宮で撮った白鷺',
                            actions=[
                                PostbackAction(label='いいね',
                                               display_text='いいね!',
                                               data='action=like&item_id=2'),
                                MessageAction(label='何かしらのラベル',
                                              text='何かしらのメッセージ'),
                                URIAction(label='詳細を見る',
                                          uri='http://example.com/2')
                            ])
                    ])))
        elif event.message.text == 'イメージカルーセル':
            # https://developers.line.me/en/docs/messaging-api/reference/#image-carousel
            line_bot_api.reply_message(
                event.reply_token,
                TemplateSendMessage(
                    alt_text='ImageCarousel template',
                    template=ImageCarouselTemplate(columns=[
                        ImageCarouselColumn(
                            image_url=
                            f'{PUBLIC_URL}/static/images/image_carousel_1.jpg',
                            action=PostbackAction(
                                label='函館のマンホール',
                                display_text='いいね',
                                data='action=like&item_id=1')),
                        ImageCarouselColumn(
                            image_url=
                            f'{PUBLIC_URL}/static/images/image_carousel_2.jpg',
                            action=URIAction(
                                label='白鷺について',
                                uri=
                                'https://ja.wikipedia.org/wiki/%E7%99%BD%E9%B7%BA'
                            ))
                    ])))
        elif event.message.text == 'アカウント連携':
            try:
                line = Line.objects.select_related('service_user').get(
                    pk=event.source.user_id)
                if not line.is_active:
                    raise LineAccountInactiveError()

                line_bot_api.reply_message(
                    event.reply_token,
                    TemplateSendMessage(
                        alt_text='すでに連携されています',
                        template=ConfirmTemplate(
                            text=
                            f'{line.service_user.username}さん、アカウント連携を解除しますか?',
                            actions=[
                                PostbackAction(
                                    label='キャンセル',
                                    display_text='アカウント連携を解除しない',
                                    data='action=accountLink&confirm=0'),
                                PostbackAction(
                                    label='解除',
                                    display_text='アカウント連携を解除する',
                                    data='action=accountLink&confirm=1')
                            ])))

            except (Line.DoesNotExist, LineAccountInactiveError):
                response = requests.post(
                    f'https://api.line.me/v2/bot/user/{event.source.user_id}/linkToken',
                    headers=line_bot_api.headers).json()

                if 'linkToken' not in response:
                    return

                link_token = response['linkToken']

                url = f'{PUBLIC_URL}{reverse("accounts:line_login_view", kwargs={"link_token": link_token})}'

                line_bot_api.reply_message(event.reply_token, [
                    ImagemapSendMessage(
                        base_url=f'{PUBLIC_URL}/static/images',
                        alt_text='ImageMap sample.',
                        base_size=BaseSize(width=1040, height=520),
                        actions=[
                            URIImagemapAction(
                                link_uri=url,
                                area=ImagemapArea(
                                    x=0, y=0, width=1040, height=520))
                        ]),
                    TextSendMessage(f'連携解除機能の提供及び連携解除機能のユーザへの通知'),
                ])
        elif event.message.text == '終わり':
            image_url = f'{PUBLIC_URL}/static/images/finish_response.jpg'
            line_bot_api.reply_message(
                event.reply_token,
                ImageSendMessage(original_content_url=image_url,
                                 preview_image_url=image_url))
        elif event.message.text == 'アカウント情報取得':
            try:
                line = Line.objects.select_related('service_user').get(
                    pk=event.source.user_id, is_active=True)
                text = f'サービスユーザ名: {line.service_user.username}\nLINEユーザ名: {line.display_name}\n' \
                       f'ステータスメッセージ: {line.status_message}'
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage(text))
            except Line.DoesNotExist:
                line_bot_api.reply_message(
                    event.reply_token,
                    TemplateSendMessage(
                        alt_text='アカウント連携しますか?',
                        template=ConfirmTemplate(
                            text=f'アカウントを連携することで情報取得ができるようになります。アカウントを連携しますか?',
                            actions=[
                                PostbackAction(label='キャンセル',
                                               display_text='キャンセル',
                                               data='action=skip'),
                                PostbackAction(label='連携',
                                               text='アカウント連携',
                                               data='action=skip')
                            ])))
        else:
            line_bot_api.reply_message(
                event.reply_token, TextSendMessage(text=event.message.text))
Exemple #16
0
def handle_message(event):
    if event.message.text == 'packages':
        gc = get_credential(json_keyfile)
        sheetkey = '15uhQm6tkd69dEthC-Vc9tb-Orsjnywlw85GOBsZgxmY'
        sh = gc.open_by_key(sheetkey)
        ws = sh.worksheet('packages')
        df = DataFrame(ws.get_all_records())
        bubbles = []
        for idx, row in df.iterrows():
            bubbles.append(
                BubbleContainer(hero=ImageComponent(
                    layout='vertical',
                    url="https://drive.google.com/uc?id={}".format(
                        row['cover']),
                    size='full',
                    aspect_mode='cover',
                    aspect_ratio='20:13',
                    action=MessageAction(
                        label='Test List',
                        text='Tests will be shown here in the future.')),
                                body=BoxComponent(
                                    layout='vertical',
                                    contents=[
                                        TextComponent(text=row['title'],
                                                      weight='bold',
                                                      size='xl',
                                                      wrap=True),
                                        TextComponent(text=row['description'],
                                                      wrap=True,
                                                      color='#cfcecc')
                                    ]),
                                footer=BoxComponent(
                                    layout='vertical',
                                    contents=[
                                        ButtonComponent(
                                            MessageAction(label='รายการตรวจ',
                                                          text=row['code']))
                                    ])))
        line_bot_mumthealth.reply_message(
            event.reply_token,
            FlexSendMessage(alt_text='Health Packages',
                            contents=CarouselContainer(contents=bubbles)))
    elif event.message.text == 'health-services':
        imageUrl = '1Z63x6wA08ATfWr1SgBCkMhiMbD3h2lhP'
        line_bot_mumthealth.reply_message(
            event.reply_token,
            ImagemapSendMessage(
                base_url='https://drive.google.com/uc?id={}&_ignored='.format(
                    imageUrl),
                alt_text='Health Services',
                base_size=BaseSize(width=1040, height=1040),
                actions=[
                    MessageImagemapAction(text='packages',
                                          area=ImagemapArea(x=122,
                                                            y=123,
                                                            width=381,
                                                            height=305)),
                    URIImagemapAction(
                        link_uri='https://liff.line.me/1655424321-ovYzaqOz',
                        area=ImagemapArea(x=124, y=430, width=377,
                                          height=301)),
                    MessageImagemapAction(text='Available soon..',
                                          area=ImagemapArea(x=126,
                                                            y=734,
                                                            width=374,
                                                            height=302)),
                    MessageImagemapAction(text='Available soon..',
                                          area=ImagemapArea(x=507,
                                                            y=125,
                                                            width=435,
                                                            height=301)),
                    MessageImagemapAction(text='Available soon..',
                                          area=ImagemapArea(x=508,
                                                            y=431,
                                                            width=434,
                                                            height=299)),
                ]))
    elif event.message.text.startswith('pkg'):
        gc = get_credential(json_keyfile)
        sheetkey = '15uhQm6tkd69dEthC-Vc9tb-Orsjnywlw85GOBsZgxmY'
        sh = gc.open_by_key(sheetkey)
        ws = sh.worksheet('tests')
        df = DataFrame(ws.get_all_records())
        bubbles = []
        total = 0
        for idx, row in df.iterrows():
            if row['package'] == event.message.text:
                total += row['price']
                bubbles.append(
                    BubbleContainer(body=BoxComponent(
                        layout='vertical',
                        contents=[
                            TextComponent(
                                text=row['test'],
                                weight='bold',
                                size='xl',
                                wrap=True,
                                align='center',
                            ),
                            TextComponent(text=row['description'],
                                          wrap=True,
                                          gravity='center'),
                            FillerComponent(flex=2),
                            TextComponent(text=u'{} บาท'.format(row['price']),
                                          wrap=True,
                                          weight='bold',
                                          size='xl',
                                          gravity='bottom',
                                          color='#4287f5',
                                          align='center')
                        ])))
        if len(bubbles) > 0:
            bubbles.append(
                BubbleContainer(
                    body=BoxComponent(layout='vertical',
                                      contents=[
                                          FillerComponent(flex=2, ),
                                          TextComponent(
                                              text='รวม {} บาท'.format(total),
                                              weight='bold',
                                              size='xl',
                                              gravity='center',
                                              align='center',
                                              color='#4287f5')
                                      ]),
                    footer=BoxComponent(
                        layout='vertical',
                        contents=[
                            ButtonComponent(action=URIAction(
                                label=u'นัดหมายเพื่อรับบริการ',
                                uri='https://liff.line.me/1655713713-L9yW3XWK')
                                            ),
                            ButtonComponent(action=MessageAction(
                                label=u'ข้อมูลเพิ่มเติม', text='Here you go!'))
                        ])))
            line_bot_mumthealth.reply_message(
                event.reply_token,
                FlexSendMessage(alt_text='Health Packages',
                                contents=CarouselContainer(contents=bubbles)))
    else:
        line_bot_mumthealth.reply_message(
            event.reply_token,
            TextSendMessage(text='Sorry, this feature will be available soon.'.
                            format(event.message.text)))