def compose_img_buttons(alt_text, thumbnail_url, title, description, actions):
    img_actions = []
    for action in actions:
        if action['type'] == 'postback':
            img_actions.append(
                PostbackTemplateAction(label=action['label'],
                                       data=action['data']))
        elif action['type'] == 'message':
            img_actions.append(
                MessageTemplateAction(label=action['label'],
                                      text=action['text']))
        elif action['type'] == 'uri':
            img_actions.append(
                URITemplateAction(label=action['label'], uri=action['uri']))
    return TemplateSendMessage(alt_text=alt_text,
                               template=ButtonsTemplate(
                                   thumbnail_image_url=thumbnail_url,
                                   title=title,
                                   text=description,
                                   actions=img_actions))
Пример #2
0
def sendBooking(event, user_id):  #房間預約
    try:
        if not (booking.objects.filter(bid=user_id).exists()):  #沒有訂房記錄
            message = TemplateSendMessage(
                alt_text="房間預約",
                template=ButtonsTemplate(
                    thumbnail_image_url='https://i.imgur.com/1NSDAvo.jpg',
                    title='房間預約',
                    text='您目前沒有訂房記錄,可以開始預訂房間。',
                    actions=[
                        URITemplateAction(label='房間預約',
                                          uri='line://app/1580167687-86z4YMdx'
                                          )  #開啟LIFF讓使用者輸入訂房資料
                    ]))
        else:  #已有訂房記錄
            message = TextSendMessage(text='您目前已有訂房記錄,不能再訂房。')
        line_bot_api.reply_message(event.reply_token, message)
    except:
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text='發生錯誤!'))
Пример #3
0
def sendButton(event):  #按鈕樣版
    try:
        message = TemplateSendMessage(
            alt_text='洗錢小知識',
            template=ButtonsTemplate(
                thumbnail_image_url='https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTAbBLFzkUIGJndS970UI6i0B2jfTDs6Uy1AtyVMtMDuHwPWlWV&usqp=CAU',  #顯示的圖片
                title=' ',  #主標題
                text='重要資訊:',  #副標題
                actions=[
                URITemplateAction(
                        label='最終受益人查詢',
                        uri='https://reurl.cc/lVAQl9'
                    ),

                ]
            )
        )
        line_bot_api.reply_message(event.reply_token, message)
    except:
        line_bot_api.reply_message(event.reply_token,TextSendMessage(text='發生錯誤!'))
Пример #4
0
def handle_message(event):
    if event.message.text == '最新展覽':
        datas = get_datas()  # 呼叫csrf_scraw裡的get_datas
        columns = []  # 準備一個空的columns陣列
        for i, d in enumerate(datas):
            column = CarouselColumn(  # column裡面的內容
                thumbnail_image_url=d['img'],
                title=d['title'],
                text=d['text'],
                actions=[
                    URITemplateAction(  #鏈接
                        label='展覽介紹連結', uri=d['url'])
                ])
            columns.append(column)

        carousel_template_message = TemplateSendMessage(
            alt_text="展覽輪播", template=CarouselTemplate(columns=columns))

        line_bot_api.reply_message(event.reply_token,
                                   carousel_template_message)
Пример #5
0
    def _create_hospitals_msgs(self, hospital_list):
        text = "您好,\n最近的三間快篩診所是:"
        carousel_messages = list()
        for index, hospital in enumerate(hospital_list, 1):
            name = hospital.get('name')
            address = hospital.get('address')
            phone = hospital.get('phone')

            text += "\n\n{index}.{name}\n{address}\n{phone}".format(
                index=index, name=name, address=address, phone=phone)

            carousel_messages.append(
                CarouselColumn(text=name,
                               actions=[
                                   PostbackTemplateAction(
                                       label=address[:20],
                                       text=' ',
                                       data='hosptial_address=' + address,
                                   ),
                                   MessageTemplateAction(label=phone[:20],
                                                         text=' '),
                               ]))

        carousel_messages.append(
            CarouselColumn(
                text='想要查看地區所有快篩點\n請點下面連結',
                actions=[
                    MessageTemplateAction(label=' ', text=' '),
                    URITemplateAction(
                        label='鄰近快篩診所',
                        uri=
                        'https://www.taiwanstat.com/realtime/dengue-vis-with-hospital/',
                    )
                ]))

        template_message = TemplateSendMessage(
            alt_text=text,
            template=CarouselTemplate(columns=carousel_messages))

        hospital_messages = [template_message]
        return hospital_messages
Пример #6
0
def buildCarouselList(liList):
    carouselColumnArray = []

    for li in liList:
        if len(carouselColumnArray) == 5:
            continue
        href = 'https://store.line.me' + li.a.get('href')
        packageId = li.a.find(class_='mdCMN06Img').img.get('src').split(
            'product/')[1].split('/ANDROID')[0]

        thumbnail_image_url = 'https://sdl-stickershop.line.naver.jp/products/0/0/1/' + packageId + '/iphone/[email protected]'

        title = li.a.find(class_='mdCMN06Ttl').getText()

        carouselColumnArray.append(
            CarouselColumn(
                thumbnail_image_url=thumbnail_image_url,
                title=title,
                text='Membantu!',
                actions=[URITemplateAction(label='melihat', uri=href)]))
    return carouselColumnArray
Пример #7
0
    def _create_carousel_template(self, freeword):
        url = self._build_URL_freeword_search(freeword)
        data = self._get_json_data(url)
        rest_info_list = self._parse_restaurant_data(data)

        columns = []
        for rest_info in rest_info_list:
            carousel = CarouselColumn(
                thumbnail_image_url=rest_info.shop_img,
                title=rest_info.name,
                # title = "aa",
                text=rest_info.text_pr,
                # text="bb",
                actions=[
                    URITemplateAction(label='URL', uri=rest_info.shop_url)
                ])
            columns.append(carousel)

        carousel_template_message = TemplateSendMessage(
            alt_text='ぐるなび検索結果', template=CarouselTemplate(columns=columns))
        return carousel_template_message
Пример #8
0
def send_template_message(reply_to, program):
    line_bot_api.reply_message(
        reply_to,
        TemplateSendMessage(
            alt_text='Buttons template',
            template=ButtonsTemplate(
                thumbnail_image_url=
                'https://upload.wikimedia.org/wikipedia/zh/thumb/8/83/National_Cheng_Kung_University_logo.svg/200px-National_Cheng_Kung_University_logo.svg.png',
                title=program.name,
                text=program.brief_intro,
                actions=[
                    MessageTemplateAction(
                        label='申請資格',
                        text=program.name + '的資格',
                    ),
                    MessageTemplateAction(label='相關時程與期限',
                                          text=program.name + '的期限'),
                    MessageTemplateAction(label='繳交文件',
                                          text=program.name + '要繳交的文件'),
                    URITemplateAction(label='詳細辦法', uri=program.details),
                ])))
Пример #9
0
def send_text_message(reply_token, title, text, imgurl, option1, option2):
    #line_bot_api.reply_message(reply_token, TextSendMessage(text=text))
    line_bot_api = LineBotApi(channel_access_token)

    buttons_template = TemplateSendMessage(
        alt_text="請到聊天視窗中確認訊息!",
        template=ButtonsTemplate(
            title=title,
            text=text,
            thumbnail_image_url=imgurl,
            actions=[
                MessageTemplateAction(label=option1, text=option1),
                MessageTemplateAction(label=option2, text=option2),
                URITemplateAction(
                    label='立即觀看玫瑰瞳鈴眼51集',
                    uri='https://www.youtube.com/watch?v=alD7ixZQKso'),
            ]))

    line_bot_api.reply_message(reply_token, buttons_template)

    return "OK"
Пример #10
0
def handle_message(event):
    # QuickMenu options
    optionList = ['ニュース']
    infoItems = [QuickReplyButton(action=MessageAction(
        label=f"{option}", text=f"{option}")) for option in optionList]
    
    # News columns
    if "ニュース" in event.message.text:
        # ニュースの送付
        js = News("jp", "general")
        newsColumns = [
            CarouselColumn(
                thumbnail_image_url=articles["urlToImage"],
                title=articles["title"][:40],  # titleが40文字までの規制されているので
                text=articles["source"]["name"],
                actions=[
                    URITemplateAction(
                        label="Check",
                        uri=articles["url"]
                    )
                ]
            )
            for articles in js["articles"]
        ]
        news_reply = TemplateSendMessage(
                        alt_text='ニュース送ったの',
                        template=CarouselTemplate(columns=newsColumns)
                     )
        
        # 送付後のリアクション
        random_news_reply = ["どうぞだぬ", "だぬ", "ぬてん", "ちょっと考えるの", "ぬう〜ん", "絶対読むの",
                             "しっかり読むの", "えらいの", "すてきだぬ", "わくわく", "難しいだぬ"]
        first_reply = TextSendMessage(text=random.choice(random_news_reply))

        line_bot_api.reply_message(event.reply_token,
                                   messages=[news_reply, first_reply])
    else:
        line_bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text=event.message.text+"だぬ"))
Пример #11
0
def getMythBusters():
    result = []
    res = requests.get(
        'https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public/myth-busters'
    )
    soup = BeautifulSoup(res.text, 'html.parser')
    myths = soup.find('div', attrs={'id': 'PageContent_C003_Col01'})
    # choose five myth busters
    for num in range(1, 6):
        myths_image = myths.select('.link-container')[num]
        url = myths_image['href']
        column = ImageCarouselColumn(image_url=str(url),
                                     action=URITemplateAction(label='Details',
                                                              uri=url))
        result.append(column)
    carousel = TemplateSendMessage(
        alt_text="5 myth busters",
        template=ImageCarouselTemplate(columns=result))
    result_text = 'Find more information about myth busters, please click: ' \
                  'https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public/myth-busters '
    result = [carousel, TextSendMessage(text=result_text)]
    return result
Пример #12
0
def getNews():
    result = []
    res = requests.get('https://www.who.int/news-room/releases')
    soup = BeautifulSoup(res.text, 'html.parser')
    news = soup.find_all('a', {'class': 'link-container'},
                         limit=5)  # choose 5 news
    for t in news:
        value = t.attrs
        title = value['aria-label']
        url = 'https://www.who.int/' + value['href']
        column = CarouselColumn(
            title=prepareTitle(title),
            text='views:' +
            str(r.incr(title)),  # Calculate the views of News through redis.
            actions=[URITemplateAction(label='More', uri=url)])
        result.append(column)
    carousel = TemplateSendMessage(alt_text="5 latest news",
                                   template=CarouselTemplate(columns=result))
    result_text = 'Find more information about coronavirus, please click: ' \
                  'https://www.who.int/emergencies/diseases/novel-coronavirus-2019 '
    result = [carousel, TextSendMessage(text=result_text)]
    return result
Пример #13
0
def handle_message(event):

    text = ""
    # 1を含んでいた場合は1に上書きして返答
    if "1" in event.message.text:
        text = "1に上書きした!!"
        line_bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text=text))
    else:
        text = event.message.text

    
    line_bot_api.reply_message(
            event.reply_token,
            TemplateSendMessage(
                alt_text='Buttons template',
                template=ButtonsTemplate(
                    thumbnail_image_url='https://www.sanyobussan.co.jp/products/santhree_pk_kujilucky/images/pc-top-img04.png',
                    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='https://www.sanyobussan.co.jp/products/santhree_pk_kujilucky/'
                        )
                    ]
                )
            )
        )
Пример #14
0
def sendBooking(event, user_id):  #房間預約
    try:
        if not (booking.objects.filter(bid=user_id).exists()):  #沒有訂房記錄
            message = TemplateSendMessage(
                alt_text="房間預約",
                template=ButtonsTemplate(
                    thumbnail_image_url='https://i.imgur.com/1NSDAvo.jpg',
                    title='房間預約',
                    text='您目前沒有訂房記錄,可以開始預訂房間。',
                    actions=[
                        URITemplateAction(label='房間預約',
                                          uri='line://app/1654001451-Ggd1RVZa'
                                          )  #開啟LIFF讓使用者輸入訂房資料
                        ##2020.0516開啟LIFF(與LINE Bot(hotelbotliff) 的連結 )讓使用者輸入訂房資料
                        ## Heroku app URL  >>> https://hotelbotliff.herokuapp.com/index_form.html
                    ]))
        else:  #已有訂房記錄
            message = TextSendMessage(text='您目前已有訂房記錄,不能再訂房。')
        line_bot_api.reply_message(event.reply_token, message)
    except:
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text='發生錯誤!'))
Пример #15
0
def handle_text_message(event):  # default
    msg = event.message.text  # message from user
    uid = event.source.user_id  # user id

    user_intent = "WhatToEatForLunch"

    # 3. 根據使用者的意圖做相對應的回答
    if user_intent == "WhatToEatForLunch":  # 當使用者意圖為詢問午餐時
        # 建立一個 button 的 template
        buttons_template_message = TemplateSendMessage(
            alt_text="請告訴我你在哪兒",
            template=ButtonsTemplate(text="請告訴我你在哪兒",
                                     actions=[
                                         URITemplateAction(
                                             label="傳送我的位置訊息",
                                             uri="line://nv/location")
                                     ]))
        line_bot_api.reply_message(event.reply_token, buttons_template_message)
    else:  # 聽不懂時的回答
        msg = "抱歉,我聽不懂你在說什麼"
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=msg))
Пример #16
0
 def template_buttons(self, message):
     """produce template with buttons
     
     Arguments:
         message {[MessageEvent.Message]} -- [the message event from user pass]
     """
     buttons_template_message = TemplateSendMessage(
         alt_text='Buttons template',
         template=ButtonsTemplate(
             thumbnail_image_url='https://i.imgur.com/ZgVAAMV.jpg',
             title='LYC電玩展',
             text='您今天想看什麼任天堂Switch遊戲',
             actions=[
                 PostbackTemplateAction(label='最新的',
                                        text='最新的',
                                        data='action=buy&itemid=1'),
                 MessageTemplateAction(label='特價中的', text='特價中的'),
                 URITemplateAction(
                     label='我自己看吧',
                     uri='https://lycnsbot.herokuapp.com/games')
             ]))
     return buttons_template_message
Пример #17
0
    def test_create_rich_menu(self):
        responses.add(
            responses.POST,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/richmenu',
            json={"richMenuId": "richMenuId"}, status=200
        )

        rich_menu = RichMenu(
            size=RichMenuSize(
                width=2500,
                height=1686
            ),
            selected=False,
            name="nice richmenu",
            chatBarText="touch me",
            areas=[
                RichMenuArea(
                    RichMenuBounds(
                        x=0,
                        y=0,
                        width=833,
                        height=843
                    ),
                    URITemplateAction(
                        uri='line://nv/location'
                    )
                )
            ]
        )

        result = self.tested.create_rich_menu(rich_menu)

        request = responses.calls[0].request
        self.assertEqual(request.method, 'POST')
        self.assertEqual(
            request.url,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/richmenu'
        )
        self.assertEqual(result, "richMenuId")
Пример #18
0
def handle_text_message(event):                  # default
    msg = event.message.text # message from user
    uid = event.source.user_id # user id
    # 1. 傳送使用者輸入到 dialogflow 上
    ai_request = ai.text_request()
    #ai_request.lang = "en"
    ai_request.lang = is_alphabet(msg)
    ai_request.session_id = uid
    ai_request.query = msg

    # 2. 獲得使用者的意圖
    ai_response = json.loads(ai_request.getresponse().read())
    user_intent = ai_response['result']['metadata']['intentName']

    # 3. 根據使用者的意圖做相對應的回答
    if user_intent == "CanGetWater":
        # 建立一個 button 的 template
        buttons_template_message = TemplateSendMessage(
            alt_text="告訴我你現在的位置",
            template=ButtonsTemplate(
                text="告訴我你現在的位置",
                actions=[
                    URITemplateAction(
                        label="Send my location",
                        uri="line://nv/location"
                    )
                ]
            )
        )
        line_bot_api.reply_message(
            event.reply_token,
            buttons_template_message)

    else: # 聽不懂時的回答
        msg = "Sorry,I don't understand"
        line_bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text=msg))
Пример #19
0
    def _create_hospitals_msgs(self, hospital_list):
        carousel_messages = list()
        for hospital in hospital_list:
            name = hospital.get('name')
            address = hospital.get('address')
            phone = hospital.get('phone')

            carousel_messages.append(
                CarouselColumn(text=name,
                               actions=[
                                   PostbackTemplateAction(
                                       label=address[:20],
                                       text=' ',
                                       data='hosptial_address=' + address,
                                   ),
                                   MessageTemplateAction(label=phone[:20],
                                                         text=' '),
                               ]))

        carousel_messages.append(
            CarouselColumn(
                text=self.render_text('nearby_hospital/all_nearby.j2'),
                actions=[
                    MessageTemplateAction(label=' ', text=' '),
                    URITemplateAction(
                        label=self.render_text('nearby_hospital/label.j2'),
                        uri=
                        'https://www.taiwanstat.com/realtime/dengue-vis-with-hospital/',
                    )
                ]))

        template_message = TemplateSendMessage(
            alt_text=self.render_text('nearby_hospital/alt_text.j2',
                                      {'hospitals': hospital_list}),
            template=CarouselTemplate(columns=carousel_messages))

        hospital_messages = [template_message]
        return hospital_messages
Пример #20
0
def sendHeadline(event,mycategory):
    if(mycategory == 'everything'):
        top_headlines = newsapi.get_top_headlines(language='zh',
                                                  country='tw')
    else:
        top_headlines = newsapi.get_top_headlines(language='zh',
                                                  country='tw',
                                                  category=mycategory)

    try:
        results =  top_headlines['articles'][0]
    except:
        line_bot_api.reply_message(event.reply_token,TextSendMessage(text = '請求資料時發生錯誤,麻煩重試一次!'))
        return
    time.sleep(3)
    
    try:
        if(results['urlToImage'] == None):
                ImageURL = 'https://images.pexels.com/photos/3866816/pexels-photo-3866816.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
        else:
            ImageURL = results['urlToImage']
        message = TemplateSendMessage(
            alt_text = '按鈕樣板',
            template = ButtonsTemplate(
                thumbnail_image_url = ImageURL,
                title = results['title'],
                text = results['description'],
                actions = [
                    URITemplateAction(
                        label = '查看原文',
                        uri = results['url']
                    )
                ]
            )
        )
        line_bot_api.reply_message(event.reply_token,message)
    except:
        line_bot_api.reply_message(event.reply_token,TextSendMessage(text = "發生錯誤!"))
def handle_message(event):
    # QuickMenu options
    optionList = ['<News>', '<Weather>']
    infoItems = [
        QuickReplyButton(
            action=MessageAction(label=f"{option}", text=f"{option}"))
        for option in optionList
    ]
    # Call up the Informant
    if event.message.text == "Informant":
        line_bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text="What information do you want?",
                            quick_reply=QuickReply(infoItems)))
    # News columns
    elif event.message.text == "<News>":
        js = fetchNews("jp", "general")
        newsColumns = [
            CarouselColumn(thumbnail_image_url=articles["urlToImage"],
                           title=articles["source"]["name"],
                           text="Powered by NewsAPI.org",
                           actions=[
                               URITemplateAction(label="Check",
                                                 uri=articles["url"])
                           ]) for articles in js["articles"]
        ]

        newsCarousel = TemplateSendMessage(
            alt_text='news carousel',
            template=CarouselTemplate(columns=newsColumns))

        line_bot_api.reply_message(event.reply_token, messages=newsCarousel)
    # Weather location prompt
    elif event.message.text == "<Weather>":
        line_bot_api.reply_message(event.reply_token, [
            TextSendMessage(text="Send your location information."),
            TextSendMessage(text='line://nv/location')
        ])
def _get_carousel_column_from_google_news_entry(entry):
    summary_soup = BeautifulSoup(entry.summary, "html.parser")
    # summary has img tag which has no src attribute like:
    # <img alt="" height="1" width="1"/>
    images = [x for x in summary_soup.find_all('img') if x.has_attr('src')]
    if len(images) == 0:
        return
    thumbnail_url = images[0]['src']

    # carousel column text is accepted until 60 characters when set the thumbnail image.
    carousel_text = summary_soup.find_all('font')[5].contents[0]
    carousel_text = carousel_text[:57] + '...' if len(
        carousel_text) > 60 else carousel_text

    # carousel column title is accepted until 40 characters.
    title = entry.title[:37] + '...' if len(entry.title) > 40 else entry.title

    return CarouselColumn(
        thumbnail_image_url=thumbnail_url,
        title=title,
        text=carousel_text,
        actions=[URITemplateAction(label='Open in Browser', uri=entry.link)],
    )
Пример #23
0
def handle_text_message(event):  # default
    msg = event.message.text  # message from user
    uid = event.source.user_id  # user id

    user_intent = "WhatToEatForLunch"

    # 3. 根據使用者的意圖做相對應的回答
    if user_intent == "WhatToEatForLunch":  # 當使用者意圖為詢問午餐時
        # 建立一個 button 的 template
        buttons_template_message = TemplateSendMessage(
            alt_text="Please tell me where you are",
            template=ButtonsTemplate(text="Please tell me where you are",
                                     actions=[
                                         URITemplateAction(
                                             label="Send my location",
                                             uri="line://nv/location")
                                     ]))
        line_bot_api.reply_message(event.reply_token, buttons_template_message)

    else:  # 聽不懂時的回答
        msg = "Sorry,I don't understand"
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=msg))
Пример #24
0
def sendButton(event):  #按鈕樣版
    try:
        message = TemplateSendMessage(
            alt_text='按鈕樣板',
            template=ButtonsTemplate(
                thumbnail_image_url='https://pse.is/S7LMV',  #顯示的圖片
                title='我可愛嗎?',  #主標題
                text='旺旺旺:',  #副標題
                actions=[
                    MessageTemplateAction(  #顯示文字計息
                        label='可愛', text='@可愛'),
                    URITemplateAction(  #開啟網頁
                        label='連結網頁', uri='https://web.mcu.edu.tw/'),
                    PostbackTemplateAction(  #執行Postback功能,觸發Postback事件
                        label='不可愛',  #按鈕文字
                        text='@不可愛',  #顯示文字計息
                        data='action=buy'  #Postback資料
                    ),
                ]))
        line_bot_api.reply_message(event.reply_token, message)
    except:
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text='發生錯誤!'))
Пример #25
0
def createCarousel(titles, links, imgs, push_num):
	carousel_message = TemplateSendMessage(
		type = 'template',
		alt_text = 'TowerSaviors Template',
		template = CarouselTemplate(
			type = 'carousel',
			columns = [
				CarouselColumn(
					thumbnail_image_url = imgs[i],
					title = helper.activity_order[i],
					text = titles[i],
					actions = [
						URITemplateAction(
							type = 'uri',
							label = 'Detail',
							uri = links[i]
						)
					]
				) for i in range(push_num)
			]
		)
	)
	return carousel_message
Пример #26
0
def getMoreKnowledge():
    result = []
    res = requests.get(
        'https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public/videos'
    )
    soup = BeautifulSoup(res.text, 'html.parser')
    videos = soup.find('div', attrs={'id': 'PageContent_C054_Col01'})
    for num in range(0, 5):
        url = videos.select('iframe')[num]['src']
        soup_url = BeautifulSoup(requests.get(url).text, 'html.parser')
        title = prepareTitle(soup_url.title.text)
        column = CarouselColumn(title=title,
                                text='views:' + str(r.incr(title)),
                                actions=[
                                    URITemplateAction(label='More', uri=url),
                                ])
        result.append(column)
    carousel = TemplateSendMessage(alt_text="5 more pieces of knowledge",
                                   template=CarouselTemplate(columns=result))
    result_text = 'Find more videos about coronavirus, please click: ' \
                  'https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public/videos '
    result = [carousel, TextSendMessage(text=result_text)]
    return result
Пример #27
0
def sendFix(event, user_id):    #修繕表單申請
    try:
        if not (fix.objects.filter(fid=user_id).filter(status__exact = '未處理').exists()):
            message = TemplateSendMessage(
                alt_text = "修繕申請",
                template = ButtonsTemplate(
                    thumbnail_image_url='https://i.imgur.com/zJg4ib0.png',
                    title='修繕申請',
                    text='您目前沒有未完成的修繕申請,可以開始填寫表單。',
                    actions=[
                        URITemplateAction(label='修繕表單填寫',
                         uri='line://app/1653654903-myrYZGgb')
                        #開啟LIFF讓使用者輸入訂房資料
                    ]
                )
            )
        else:  #已有訂房記錄
            message = TextSendMessage(
                text = '您目前已有申請修繕並還未修繕,一個人不能同時申請兩次。'
            )
        line_bot_api.reply_message(event.reply_token,message)
    except:
        line_bot_api.reply_message(event.reply_token,TextSendMessage(text='發生錯誤!'))
Пример #28
0
def sendButton(event):  #按鈕樣版
    try:
        message = TemplateSendMessage(
            alt_text='按鈕樣板',
            template=ButtonsTemplate(
                thumbnail_image_url="https://i.imgur.com/SKw73MQ.png",  #顯示的圖片
                title='alice',  #主標題
                text='個人頁面:',  #副標題
                actions=[
                    MessageTemplateAction(  #顯示文字計息
                        label='文字訊息', text='@自己'),
                    URITemplateAction(  #開啟網頁
                        label='連結銘傳網頁', uri="http://wed.mcu.edu.tw/"),
                    PostbackTemplateAction(  #執行Postback功能,觸發Postback事件
                        label='回傳訊息',  #按鈕文字
                        #text='@資料',  #顯示文字計息
                        data='action=buy'  #Postback資料
                    ),
                ]))
        line_bot_api.reply_message(event.reply_token, message)
    except:
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text='發生錯誤!'))
Пример #29
0
def sendSearch(event,query):
    all_articles = newsapi.get_everything(q=query,
                                      from_param=datetime.date.today() - datetime.timedelta(days=3),
                                      to=datetime.date.today(),
                                      language='zh',
                                      sort_by='relevancy')

    try:
        results =  all_articles['articles'][0]

    except:
        line_bot_api.reply_message(event.reply_token,TextSendMessage(text = '請求資料時發生錯誤,麻煩重試一次!'))
        return  
    time.sleep(3)
    
    try:
        if(results['urlToImage'] == None):
                ImageURL = 'https://images.pexels.com/photos/3866816/pexels-photo-3866816.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
        else:
            ImageURL = results['urlToImage']
        message = TemplateSendMessage(
            alt_text = '按鈕樣板',
            template = ButtonsTemplate(
                thumbnail_image_url = ImageURL,
                title = results['title'],
                text = results['description'],
                actions = [
                    URITemplateAction(
                        label = '查看原文',
                        uri = results['url']
                    )
                ]
            )
        )
        line_bot_api.reply_message(event.reply_token,message)
    except:
        line_bot_api.reply_message(event.reply_token,TextSendMessage(text = '發生錯誤'))
Пример #30
0
def sendButton4(event):  #按鈕樣版
    try:
        message = TemplateSendMessage(
            alt_text='按鈕樣板',
            template=ButtonsTemplate(
                thumbnail_image_url='https://i.imgur.com/ZGaXkKd.jpg',
                title='demo',
                text='pizza demo',
                actions=[
                    MessageTemplateAction(  #顯示文字計息
                        label='文字訊息', text='@購買披薩'),
                    URITemplateAction(  #開啟網頁
                        label='website mcu',
                        uri='https://web.mcu.edu.tw/'),
                    PostbackTemplateAction(  #執行Postback功能,觸發Postback事件
                        label='回傳訊息',  #按鈕文字
                        #text='@購買披薩',  #顯示文字計息
                        data='action=buy'  #Postback資料
                    ),
                ]))
        line_bot_api.reply_message(event.reply_token, message)
    except:
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text='發生錯誤!'))