示例#1
0
文件: app.py 项目: Azmain946/demobot
def ipl(recipient_id):
    elements = []
    elements.append(
        Element(
            title="Kolkata Knight Riders",
            image_url=
            'https://www.kkr.in/static-assets/waf-images/62/73/6c/0/mN4BkixqiZ.JPG',
            subtitle=None,
            item_url='https://www.kkr.in/'))
    element1 = Element(
        title="Chennai Super Kings",
        image_url=
        "https://upload.wikimedia.org/wikipedia/en/thumb/2/2b/Chennai_Super_Kings_Logo.svg/250px-Chennai_Super_Kings_Logo.svg.png",
        subtitle=None,
        item_url="https://www.chennaisuperkings.com/CSK_WEB/index.html")
    element2 = Element(
        title="Indian Premier League ",
        image_url=
        "https://www.deccanherald.com/sites/dh/files/styles/article_detail/public/articleimages/2020/10/12/iplv1-889782-1602475398.jpg?itok=RsPGmjcr",
        subtitle=None,
        item_url='https://www.iplt20.com/')

    elements.append(element1)
    elements.append(element2)

    bot.send_generic_message(recipient_id, elements)
示例#2
0
文件: app.py 项目: Azmain946/demobot
def khoborakhobor(recipient_id):
    elements = []
    elements.append(
        Element(
            title="Al Jazeera",
            image_url=
            'http://logok.org/wp-content/uploads/2014/04/Aljazeera-logo-English-880x660.png',
            subtitle='Breaking News, World News and Video from Al Jazeera',
            item_url='https://www.aljazeera.com/'))
    element1 = Element(
        title="বিবিসি বাংলা",
        image_url=
        "https://d1yjjnpx0p53s8.cloudfront.net/styles/logo-thumbnail/s3/0023/3343/brand.gif?itok=1UXhEJs0",
        subtitle="খবর, সর্বশেষ খবর, ব্রেকিং নিউজ",
        item_url="http://bbcbangla.com/")
    element2 = Element(
        title="প্রথম আলো",
        image_url=
        "https://d1yjjnpx0p53s8.cloudfront.net/styles/logo-thumbnail/s3/052014/prthm_aalo.jpg?itok=i7S-cVgj",
        subtitle="Latest online bangla news",
        item_url='https://www.prothomalo.com/')
    element3 = Element(
        title="bdnews24.com",
        image_url=
        'https://d30fl32nd2baj9.cloudfront.net/media/2013/01/04/logo1.png1/BINARY/logo1.png',
        subtitle=
        "Bangladesh's first bilingual 24/7 news provider in any medium opened its content to public free of charge on 23 Oct 2006",
        item_url="https://bdnews24.com/")
    elements.append(element1)
    elements.append(element2)
    elements.append(element3)
    bot.send_generic_message(recipient_id, elements)
示例#3
0
文件: app.py 项目: Azmain946/demobot
def send_generic(recipient_id):
    elements = []
    element1 = Element(
        title="test",
        image_url=
        "https://cdn.jpegmini.com/user/images/slider_puffin_before_mobile.jpg",
        subtitle="subtitle",
        item_url="http://arsenal.com")
    element2 = Element(
        title="test2",
        image_url=
        "https://cdn.jpegmini.com/user/images/slider_puffin_before_mobile.jpg",
        subtitle="subtitle",
        item_url="http://arsenal.com")
    elements.append(element1)
    elements.append(element2)
    bot.send_generic_message(recipient_id, elements)
示例#4
0
def test_elements():
    image_url = 'https://lh4.googleusercontent.com/-dZ2LhrpNpxs/AAAAAAAAAAI/AAAAAAAA1os/qrf-VeTVJrg/s0-c-k-no-ns/photo.jpg'
    elements = []
    element = Element(title="Arsenal", image_url=image_url, subtitle="Click to go to Arsenal website.", item_url="http://arsenal.com")
    elements.append(element)
    result = bot.send_generic_message(recipient_id, elements)
    assert type(result) is dict
    assert result.get('message_id') is not None
    assert result.get('recipient_id') is not None
示例#5
0
文件: app.py 项目: sushen/facebookbot
def get_image_element(message):
    image_url = 'http://android.agrostar.in/static/Cotton.jpg'
    elements = []
    element = Element(title="Cotton",
                      image_url=image_url,
                      subtitle="Click to view more details",
                      item_url="http://crm.agrostar.in/#/products")
    elements.append(element)
    return elements
示例#6
0
def handle_attachments(sender, attachments):
    """ if user sends us a GIF, photo, video or any other non-text item """
    elements = []
    element = Element(title="Este es el adjunto que me mandaste",
                      image_url=attachments[0]['payload']['url'],
                      subtitle="",
                      item_url="https://www.cliengo.com/")
    elements.append(element)

    bot.send_generic_message(sender, elements)
示例#7
0
def pick_center_card(payload_str, title, subtitle):
    buttons = []
    for x in range(3):
        button_title = "Card {:d}".format(x + 1)
        buttons.append(
            Button(title=button_title, type='postback', payload=payload_str))
    element = Element(title=title,
                      image_url=urls.center_img,
                      subtitle=subtitle,
                      buttons=buttons)
    return [element]
示例#8
0
 def execute(self, command):
     if command == 'popular':
         movies = requests.get(HOST + '/movie/popular?api_key=' + API_KEY)
         elements = []
         for movie in movies.json()['results']:
             web_url = 'https://www.themoviedb.org/movie/{}'.format(
                 movie['id'])
             elements.append(
                 Element(title=movie['original_title'],
                         image_url=IMG_PATH + movie['poster_path'],
                         subtitle=movie['overview'],
                         item_url=web_url))
         bot.send_generic_message(self.user_id, elements[:10])
示例#9
0
    def format_article(self, microarticle, type):
        microarticle_formatted = False
        rapi = rAPI_Service()
        article_Service = articleService()

        article_title = microarticle.title.title()
        article_url = microarticle.url
        extracted_article = rapi.goosify_rapi_article(microarticle)
        try:
            thumb = extracted_article.top_image.src
        except:
            thumb = microarticle.thumbnail

        elements = []

        if type == 'article':
            try:
                article_summary = str(article_Service.summarize_article(extracted_article.cleaned_text))
                print("[i] Article Summary: ")
                print(article_summary)
            except Exception as e:
                print("Cant get summary::\t" + str(e))
                article_summary = "Fetched by Lilo!"
            element = Element(title=article_title, image_url=thumb, subtitle=article_summary, item_url=article_url)

        elif type == 'image':
            element = Element(title=article_title, image_url=thumb, subtitle="Click to view", item_url=article_url)


        elif type == 'video':
            element = Element(title=article_title, image_url=thumb, subtitle="Click to view", item_url=article_url)

        print("TYPE\t::\t" + str(type))
        elements.append(element)

        return elements
示例#10
0
def send_thank_you_message(fb_page, fb_user_id, signup_query):
    thank_you_text = {
        'eng': ('Thank you for reserving your admission badge to the '
                'following event(s):'),
        'chi': u'多謝閣下預留免費入場證參觀以下展覽:'
    }
    ref_num_text = {
        'eng': ('Please show your reference number at "Buyer Registration'
                ' Counter" to complete the registration process and redeem '
                'the admission badge. Thank You!'
                ),
        'chi': u'請到會場的「買家登記處」出示登記參考編號,以完成登記程序及索取免費入場證。'
    }
    share_text = {
        'eng': ('You can register again or share the event with your friends.'
                ),
        'chi': u'您可以為下一位來賓登記,或與您的好友分享這個展覽。'
    }
    lang = signup_query[0].fb_user.language
    post_text_message(
        fb_page, fb_user_id,
        thank_you_text.get(lang, 'eng'))
    for signup in signup_query:
        text, button = utils.more_info_button(signup, lang)
        post_button_message(fb_page, signup.fb_user.fbid, text, button)
    post_text_message(
        fb_page, signup.fb_user.fbid,
        ref_num_text.get(lang, 'eng'))

    elements = []
    for signup in signup_query:
        signup_page_url_str = {
            'eng': signup.event.signup_page_url_str + '&lang=eng',
            'chi': signup.event.signup_page_url_str + '&lang=chi',
        }
        title = signup.event.name_chi if lang == 'chi' else signup.event.name

        element = Element(title=title,
                          image_url=signup.event.event_image_url_str,
                          subtitle=share_text.get(lang, 'eng'),
                          item_url=signup_page_url_str.get(lang, 'eng'),
                          buttons=utils.after_registration_button(
                              signup.event, lang)
                          )

        elements.append(element)
    post_generic_message(fb_page, fb_user_id,
                         elements)
示例#11
0
 def do(self, entities):
     r = requests.get('https://newsapi.org/v1/articles',
                      params={
                          'source': entities['news_sources'],
                          'apiKey': os.environ['NEWSAPI_KEY']
                      })
     data = json.loads(r.text)
     val = []
     for x in data['articles'][:5]:
         elem = Element(title=x['title'],
                        subtitle=x['description'],
                        image_url=x['urlToImage'],
                        item_url=x['url'])
         val.append(elem)
     entities['news'] = ('Here\'s the news', val)
     return entities
示例#12
0
def send_templates(recipient_id):
    templates = []

    for temp in TEMPLATES:
        templates.append(
            Element(title="Vorlage",
                    image_url=asset_url(temp + "_preview.png"),
                    subtitle="Vorlage",
                    buttons=[
                        Button({
                            "type": "postback",
                            "title": "Vorlage wählen",
                            "payload": temp
                        })
                    ]))

    bot.send_generic_message(recipient_id, templates)
示例#13
0
def arbs_to_list_message(arbs):
    elements = []
    for arb in arbs:
        from_,to,coin,gain_perc = arb["from"],arb["to"],arb["coin"],arb["gain_perc"]
        subtitle = "%d %% @ %s -> %s" % (gain_perc, from_,to)
        elements.append(Element(title=coin,subtitle=subtitle))

    message = {
        "attachment" : {
            "type" : "template",
            "payload" : { 
                "template_type": "list",
                "top_element_style": "compact",
                "elements": elements
            }
        }
    }
    return message
示例#14
0
def webhook():
    data = request.get_json()
    log(data)

    # Necessary Code that extract json data facebook send
    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                # IDs
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    # Extracting text message
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'

                    # replace Echo Bot to wit ai
                    response = None

                    entity, value = wit_response(messaging_text)

                    # if entity == 'greetings':
                    #     response = 'Welcome, Now we re in Testing, Please Contact Later'

                    if entity == 'greetings':
                        elements = []
                        element = Element(title="test",
                                          image_url="<arsenal_logo.png>",
                                          subtitle="subtitle",
                                          item_url="http://arsenal.com")
                        elements.append(element)

                        bot.send_generic_message(recipient_id, elements)

                    if response == None:
                        response = "Sorry, What is your Question, I didn't understand"

                    bot.send_text_message(sender_id, response)

    return "ok", 200
示例#15
0
def player_carousel(player, action, do_nothing=False):
    elements = []
    players = player.game_state.players
    if do_nothing:
        nothing_button = Button(title="Do Nothing",
                                type='postback',
                                payload=player_payload(player, action))
    for k in players:
        if k != player.player_no:
            #player_no as k will be passed payload formatted in a dictionary
            #with key 0
            payload = player_payload(player, action, str(k))
            button = Button(title="Pick", type='postback', payload=payload)
            if do_nothing:
                buttons = [button, nothing_button]
            else:
                buttons = [button]
            elements.append(
                Element(title=players[k].first_name,
                        image_url=players[k].profile_pic,
                        buttons=buttons))
    return elements
示例#16
0
def handle_postback(messaging):
    fb_page = FacebookPage.objects.get(fbid=messaging['recipient']['id'])
    received_postback = utils.save_received_postback(fb_page, messaging)
    payload = messaging['postback']['payload']

    if payload.split('.')[0] != 'HELP_MESSAGE':
        fb_user = FacebookUser.objects.get_or_create(
            fb_page=fb_page, fbid=messaging['sender']['id'])[0]
        lang = fb_user.language
    else:
        fb_user = None
        lang = 'eng'

    if payload.split('.')[0] == 'REGISTER_EVENT':
        lang = payload.split('.')[1]
        fb_user.language = lang
        fb_user.save()
        RegisterReminderList.objects.create(
            fb_user=fb_user,
            event=Event.objects.get(pk=payload.split('.')[2]),
        )

        title_text = {
            'eng': 'Reserve Your Free Admission Badge: %s',
            'chi': u'預留免費入場證:%s'
        }
        subtitle_text = {
            'eng': 'Tap "Reserve Now" to begin.',
            'chi': u'按「現在預留」開始進行登記。'
        }
        elements = []
        for event_pk in payload.split('.')[2:]:
            event = Event.objects.get(pk=event_pk)
            signup_page_url_str = {
                'eng': event.signup_page_url_str + '&lang=eng',
                'chi': event.signup_page_url_str + '&lang=chi',
            }
            title = (title_text.get('chi') % event.name_chi if lang == 'chi'
                     else title_text.get('eng') % event.name)
            element = Element(
                title=title,
                image_url=event.event_image_url_str,
                subtitle=subtitle_text.get(lang, 'eng'),
                item_url=signup_page_url_str.get(lang, 'eng'),
                buttons=utils.registration_button(event, lang)
            )

            elements.append(element)
        post_generic_message(fb_page, messaging['sender']['id'],
                             elements)

    if payload.split('.')[0] == 'REMINDER_REFERENCE_NUM':
        signup_query = utils.get_signup_query(
            fb_page, messaging['sender']['id'], payload.split('.')[1])
        status = ''

        signup_info_text = {
            'eng': ('{0} - Your signup information\n'
                    'First Name: {1}\n'
                    'Last Name: {2}\n'
                    'Reference No.: {3}'),
            'chi': (u'{0} - 您的登記資料\n'
                    u'姓氏: {2}\n'
                    u'名字: {1}\n'
                    u'參考編號: {3}')
        }
        terms_text = {
            'eng': ('For Security reason, your passport or HK identity card '
                    'will be required to collect your admission badge. With '
                    'our enhanced security measures, all buyers are required '
                    'to present a valid photo bearing identity document for '
                    'on-site veification before entering the hall venues.'),
            'chi': (u'基於保安考慮,請攜帶您的護照或香港身份證領取入場證。所有參觀人士也會'
                    u'被要求檢查身份證明文件上的近照,以茲識別。')
        }

        for signup in signup_query:
            event_name = (signup.event.name_chi if lang == 'chi'
                          else signup.event.name)
            signup_info_message = signup_info_text.get(lang, 'eng').format(
                event_name,
                signup.contact_object.first_name,
                signup.contact_object.last_name,
                signup.signup_code
            )
            status = post_text_message(fb_page, fb_user.fbid,
                                       signup_info_message)
        post_text_message(
            fb_page, fb_user.fbid, terms_text.get(lang, 'eng'))
        if status == 'Success':
            received_postback.responded = True
            received_postback.save()

    if payload.split('.')[0] == 'WELCOME_GIFT':
        event = Event.objects.get(pk=payload.split('.')[1])
        text = event.gift_message if lang == 'eng' else event.gift_message_chi
        pre_gift_text = {
            'eng': ('The fair souvenirs are still being arranged at '
                    'the moment, please check back later for more information.'
                    ),
            'chi': u'感謝您對本展覽的興趣,我們正在準備閣下的精美禮品,請稍後再次查看。'
        }

        if text == '':
            post_text_message(fb_page, messaging['sender']['id'],
                              pre_gift_text.get(lang, 'eng'))
        else:
            post_text_message(fb_page, messaging['sender']['id'], text)

            text, button = utils.gift_message_button(
                payload.split('.')[1], lang)
            status = post_button_message(
                fb_page, messaging['sender']['id'], text, button)
            if status == 'Success':
                received_postback.responded = True
                received_postback.save()

    elif payload == 'GIFT_TERMS_COND':
        text_messages = utils.gift_terms_messages(lang)
        status = ''
        for text in text_messages:
            status = post_text_message(
                fb_page, messaging['sender']['id'], text)
        if status == 'Success':
            received_postback.responded = True
            received_postback.save()

    elif payload.split('.')[0] == 'GET_ALL_SIGNUP':
        signup_query = utils.get_all_signup_query(fb_page,
                                                  messaging['sender']['id'])
        event_query = set(signup.event for signup in signup_query
                          if signup.event.end_date > timezone.now().date())

        subtitle_text = {
            'eng': 'Tap for more details',
            'chi': u'按此查看更多資訊'
        }
        instruct_text = {
            'eng': ('If you need your reference number again, tap the '
                    '"Reference Number" button. Learn how to redeem fair '
                    'souvenirs by tapping the "Fair Souvenirs" button.'),
            'chi': (u'想查看您的參考編號? 請按「我的參考編號」。'
                    u'想查看領取的禮品及方法? 請按「領取精美禮品」。')
        }
        no_reg_text = {
            'eng': "You didn't register any upcoming events.",
            'chi': u'您還未注冊任何即將開始的香港貿發局展覽。'
        }

        elements = []
        status = ''
        if event_query:
            for event in event_query:
                event_page_url_str = {
                    'eng': event.event_page_url_str,
                    'chi': event.event_page_url_str.replace('-en', '-tc')
                }
                title = event.name_chi if lang == 'chi' else event.name

                element = Element(title=title,
                                  image_url=event.event_image_url_str,
                                  subtitle=subtitle_text.get(lang, 'eng'),
                                  item_url=event_page_url_str.get(lang, 'eng'),
                                  buttons=utils.view_event_buttons(event, lang)
                                  )
                elements.append(element)
            status = post_generic_message(fb_page, fb_user.fbid,
                                          elements)
            post_text_message(
                fb_page, messaging['sender']['id'],
                instruct_text.get(lang, 'eng'))
        else:
            status = post_text_message(
                fb_page, messaging['sender']['id'],
                no_reg_text.get(lang, 'eng'))
        if status == 'Success':
            received_postback.responded = True
            received_postback.save()

    elif payload.split('.')[0] == 'HELP_MESSAGE':
        status = post_text_message(fb_page,
                                   messaging['sender']['id'], HELP_MESSAGE)
        if status == 'Success':
            received_postback.responded = True
            received_postback.save()

    else:
        pass