Exemplo n.º 1
0
def broadcast_image():
    users = mongo.db.USER_CMS
    bc = mongo.db.BROADCAST
    check_user_activation_key = users.find_one(
        {'user_activation_key': request.form['user_activation_key']})
    if bool(check_user_activation_key):
        url = request.form['url']
        dt = request.form['timestamp']
        # 'Jun 1 2005  1:33PM'
        datetime_object = datetime.strptime(dt, '%Y-%m-%d %H:%M')
        # for user in USER.find():
        #     page.send(user['id_user'], Attachment.Image(url))

        page.send("1370330196399177", Attachment.Image(url))
        page.send("1437973719614452", Attachment.Image(url))
        # luu broadcast
        new_bc = {
            'type': 'image',
            'content': url,
            'timestamp': datetime_object
        }
        bc.insert_one(new_bc)
        return 'True'
    else:
        return 'False'
Exemplo n.º 2
0
def broadcast_news_broadcast():
    users = mongo.db.USER_CMS
    bc = mongo.db.BROADCAST
    # check_user_activation_key = users.find_one(
    #     {'user_activation_key': request.form['user_activation_key']})
    username = users.find_one({'username': request.form['username']})
    password = users.find_one({'password': request.form['password']})
    if bool(password):
        if bool(username):
            element = Template.GenericElement(
                title=request.form['title'],
                subtitle=request.form['subtitle'],
                image_url=request.form['image_url'],
                buttons=[
                    Template.ButtonWeb('Đọc tin', request.form['item_url']),
                    Template.ButtonPostBack('Về Home', 'home')
                ])
            # dt = request.form['timestamp']
            # datetime_object = datetime.strptime(dt, '%Y-%m-%d %H:%M')
            # page.send(sender_id, Template.Generic(element))
            page.send("1370330196399177", Template.Generic(element))
            page.send("1437973719614452", Template.Generic(element))
            # luu broadcast
            # new_bc = {
            #     'type': 'news',
            #     'content': item_url,
            #     'timestamp': bc['timestamp']
            # }
            # bc.insert_one(new_bc)
            return 'True'
        else:
            return 'False'
    else:
        return 'False'
Exemplo n.º 3
0
def broadcast_message_button():
    users = mongo.db.USER_CMS
    bc = mongo.db.BROADCAST
    check_user_activation_key = users.find_one(
        {'user_activation_key': request.form['user_activation_key']})
    if bool(check_user_activation_key):
        # for user in USER.find():
        #     message = request.form['message']
        #     buttons = [
        #         Template.ButtonPostBack("Home", "home")
        #     ]
        #     page.send(user['id_user'], Template.Buttons(message, buttons))

        message = request.form['message']
        dt = request.form['timestamp']
        # 'Jun 1 2005  1:33PM'
        datetime_object = datetime.strptime(dt, '%Y-%m-%d %H:%M')
        buttons = [
            Templatsae.ButtonPostBack("Home", "home")
        ]
        page.send("1370330196399177", Template.Buttons(message, buttons))
        page.send("1437973719614452", Template.Buttons(message, buttons))
        # luu broadcast
        new_bc = {
            'type': 'message_button',
            'content': message,
            'timestamp': datetime_object
        }
        bc.insert_one(new_bc)
        return 'True'
    else:
        return 'False'
Exemplo n.º 4
0
def send_message(recipient_id, text):
    # If we receive a text message, check to see if it matches any special
    # keywords and send back the corresponding example. Otherwise, just echo
    # the text we received.
    special_keywords = {
        "image": send_image,
        "gif": send_gif,
        "audio": send_audio,
        "video": send_video,
        "file": send_file,
        "button": send_button,
        "generic": send_generic,
        "receipt": send_receipt,
        "quick reply": send_quick_reply,
        "read receipt": send_read_receipt,
        "typing on": send_typing_on,
        "typing off": send_typing_off,
        "account linking": send_account_linking
    }

    if text in special_keywords:
        special_keywords[text](recipient_id)
    else:
        page.send(recipient_id, text, callback=send_text_callback,
                  notification_type=NotificationType.REGULAR)
Exemplo n.º 5
0
def broadcast_video_broadcast():
    users = mongo.db.USER_CMS
    bc = mongo.db.BROADCAST
    # check_user_activation_key = users.find_one(
    #     {'user_activation_key': request.form['user_activation_key']})
    username = users.find_one({'username': request.form['username']})
    password = users.find_one({'password': request.form['password']})
    if bool(password):
        if bool(username):

            url = request.form['url']
            dt = request.form['timestamp']
            # 'Jun 1 2005  1:33PM'
            datetime_object = datetime.strptime(dt, '%Y-%m-%d %H:%M')
            # for user in USER.find():
            #     page.send(user['id_user'], Attachment.Video(url))

            page.send("1370330196399177", Attachment.Video(url))
            page.send("1437973719614452", Attachment.Video(url))

            # luu broadcast
            # new_bc = {
            #     'type': 'video',
            #     'content': url,
            #     'timestamp': datetime_object
            # }
            # bc.insert_one(new_bc)
            return 'True'
        else:
            return 'False'
    else:
        return 'False'
Exemplo n.º 6
0
def minigame1_rule(sender_id):
    text = "- Mỗi bạn tham gia sẽ có 01 lựa chọn cho việc dự đoán đội huấn luyện viên có thí sinh đạt được giải quán quân 🎊 của chương trình.\n- Nếu bạn thay đổi ý kiến, dự đoán được BTC ghi nhận là dự đoán cuối cùng mà bạn chọn.\n- Nếu dự đoán đúng và may mắn, bạn sẽ nhận được 01 phần quà 🎁 hấp dẫn từ ban tổ chức.\n Hãy tận dụng “giác quan thứ 6” của mình để 'rinh' quà về nhà nào!\n👉👉👉 “Giọng Hát Việt Nhí” 2017 sẽ chính thức được phát sóng vào lúc 21h10 thứ 7 hằng tuần trên kênh VTV3"
    buttons = [
        Template.ButtonPostBack("Home", "home")
    ]
    page.send(sender_id, Template.Buttons(text, buttons))
    return
Exemplo n.º 7
0
def subscribe_news(sender_id):

    user_profile = page.get_user_profile(sender_id)  # return dict
    first_name = user_profile["first_name"]
    last_name = user_profile["last_name"]
    id_user = user_profile["id"]

    # kiem tra user, neu chua co thi them vao database
    check_user = USER.find_one({'id_user': sender_id})
    if bool(check_user):
        # pass
        # page.send(sender_id, "user da co trong database")
        print('user da co trong database')
    else:
        insert_new_user(first_name, last_name, id_user)

    question = "Bằng cách đồng ý theo dõi tin tức dưới đây, bạn sẽ nhận được thông báo mỗi khi tin tức mới của chương trình “Giọng Hát Việt Nhí” 2017 được cập nhật.\nBạn muốn nhận thông báo chứ?"
    quick_replies = [
        QuickReply(title="1 tuần 1 lần 😋", payload="yes1"),
        QuickReply(title="1 tuần 2 lần 😈", payload="yes2"),
        QuickReply(title="Nhắc lại sau 😜", payload="no")
    ]
    page.send(sender_id,
              question,
              quick_replies=quick_replies,
              metadata="DEVELOPER_DEFINED_METADATA")

    return
Exemplo n.º 8
0
def greeting(sender_id):
    # get user info
    user_profile = page.get_user_profile(sender_id)  # return dict
    first_name = user_profile["first_name"]
    last_name = user_profile["last_name"]
    id_user = user_profile["id"]
    print (user_profile)

    # kiem tra user, neu chua co thi them vao database
    check_user = USER.find_one({'id_user': sender_id})
    if bool(check_user):
        # pass
        # page.send(sender_id, "user da co trong database")
        print('day la ham greeting, user da co trong database')
    else:
        insert_new_user(first_name, last_name, id_user)

    space = " "
    a = "Chào"
    b = "đến với Giọng Hát Việt Nhí. Tại đây, bạn có thể đặt câu hỏi, chơi Mini game và theo dõi những tin tức “nóng hổi” nhất từ chương trình. Còn chần chừ gì mà không bắt đầu cuộc “trò chuyện thân mật” ngay nào !!! ;) ;)\n⏩⏩⏩ Quay về tính năng chính bằng cách ấn phím “Home” hoặc gõ vào chữ “Home” hoặc “Menu” 👇\n⏩⏩⏩ Chương trình “Giọng Hát Việt Nhí” 2017 sẽ được phát sóng vào lúc 21h10 thứ 7 hằng tuần trên kênh VTV3📺 "
    seq = (a, first_name, b)
    text = space.join(seq)
    buttons = [
        Template.ButtonPostBack(
            "Home", "home")
    ]
    page.send(sender_id, Template.Buttons(text, buttons))

    return
Exemplo n.º 9
0
def minigame2_rule(sender_id):
    text = "- Mỗi bạn tham gia được dự đoán không giới hạn ‘Từ khóa’ may mắn để nhận được trọn bộ Sticker hình vẽ HLV Giọng Hát Việt Nhí 2017.\n- ‘Từ khóa’ có thể gồm 1 từ hoặc 1 cụm từ miêu tả gần giống với các HLV nhất.\n- Nếu dự đoán đúng từ khóa. Bạn sẽ nhận được những Sticker ‘Siêu Đáng Yêu’.\nNgại gì không thử??\n\n👉👉👉 “Giọng Hát Việt Nhí” 2017 sẽ chính thức được phát sóng vào lúc 21h10 thứ 7 hằng tuần (từ ngày 12/8/2017) trên kênh VTV3"
    buttons = [
        Template.ButtonPostBack("Home", "home")
    ]
    page.send(sender_id, Template.Buttons(text, buttons))
    return
Exemplo n.º 10
0
def send_receipt(recipient):
    receipt_id = "order1357"
    element = Template.ReceiptElement(title="Oculus Rift",
                                      subtitle="Includes: headset, sensor, remote",
                                      quantity=1,
                                      price=599.00,
                                      currency="USD",
                                      image_url=CONFIG['SERVER_URL'] +
                                      "/assets/riftsq.png"
                                      )

    address = Template.ReceiptAddress(street_1="1 Hacker Way",
                                      street_2="",
                                      city="Menlo Park",
                                      postal_code="94025",
                                      state="CA",
                                      country="US")

    summary = Template.ReceiptSummary(subtotal=698.99,
                                      shipping_cost=20.00,
                                      total_tax=57.67,
                                      total_cost=626.66)

    adjustment = Template.ReceiptAdjustment(
        name="New Customer Discount", amount=-50)

    page.send(recipient, Template.Receipt(recipient_name='Peter Chang',
                                          order_number=receipt_id,
                                          currency='USD',
                                          payment_method='Visa 1234',
                                          timestamp="1428444852",
                                          elements=[element],
                                          address=address,
                                          summary=summary,
                                          adjustments=[adjustment]))
Exemplo n.º 11
0
def send_generic(recipient):
    page.send(recipient, Template.Generic([
        Template.GenericElement("rift",
                                subtitle="Next-generation virtual reality",
                                item_url="https://www.oculus.com/en-us/rift/",
                                image_url=CONFIG['SERVER_URL'] +
                                "/assets/rift.png",
                                buttons=[
                                    Template.ButtonWeb(
                                        "Open Web URL", "https://www.oculus.com/en-us/rift/"),
                                    Template.ButtonPostBack(
                                        "tigger Postback", "DEVELOPED_DEFINED_PAYLOAD"),
                                    Template.ButtonPhoneNumber(
                                        "Call Phone Number", "+16505551234")
                                ]),
        Template.GenericElement("touch",
                                subtitle="Your Hands, Now in VR",
                                item_url="https://www.oculus.com/en-us/touch/",
                                image_url=CONFIG['SERVER_URL'] +
                                "/assets/touch.png",
                                buttons=[
                                    {'type': 'web_url', 'title': 'Open Web URL',
                                     'value': 'https://www.oculus.com/en-us/rift/'},
                                    {'type': 'postback', 'title': 'tigger Postback',
                                     'value': 'DEVELOPED_DEFINED_PAYLOAD'},
                                    {'type': 'phone_number', 'title': 'Call Phone Number',
                                        'value': '+16505551234'},
                                ])
    ]))
Exemplo n.º 12
0
def fansign_menu(sender_id):
    user_profile = page.get_user_profile(sender_id)
    first_name = user_profile["first_name"]
    last_name = user_profile["last_name"]
    id_user = user_profile["id"]
    print(last_name + ' ' + first_name)

    check_user = USER.find_one({'id_user': sender_id})
    if bool(check_user):
        print('user da co trong database')
    else:
        insert_new_user(first_name, last_name, id_user)

    space = " "
    a = "ơi, bạn muốn nhận fansign từ HLV nào?"
    seq = (last_name, first_name, a)
    question = space.join(seq)

    quick_replies = [
        QuickReply(title="Soobin", payload="sb"),
        QuickReply(title="Vũ Cát Tường", payload="vct"),
        QuickReply(title="Hương Tràm", payload="ht"),
        QuickReply(title="Tiên Cookie", payload="tc")
    ]
    page.send(sender_id, question, quick_replies=quick_replies,
              metadata="DEVELOPER_DEFINED_METADATA")
    return
Exemplo n.º 13
0
def find_cat(sender_id, word_dict, message):
    dict_cat = {}
    count_word_in_cat = 0
    chosen_cat = {}
    for cat_document in FAQ2.find({'level': '1'}):
        for word in word_dict:
            if word in cat_document['cat_keyword']:
                count_word_in_cat = count_word_in_cat + 1
        dict_cat.update({cat_document['cat_title']: count_word_in_cat})
        count_word_in_cat = 0
        # print (dict_cat)

    # gom cac cat_title co count_word_in_cat giong nhau lai
    flipped = {}
    for key, value in dict_cat.items():
        if value not in flipped:
            flipped[value] = [key]
        else:
            flipped[value].append(key)
    # print(flipped)

    # xep lai de thanh maximum
    maximum_key = max(flipped)
    maximum_value = flipped[maximum_key]
    # print('maximum value cua find_cat la ', maximum_value, maximum_key)

    if len(maximum_value) == 1 and maximum_key > 0:  # chi co 1 cat co so luong keyword la max
        # print(maximum_value[0])
        chosen_cat = FAQ2.find_one(
            {'level': '1', 'cat_title': maximum_value[0]})
        # text = 'da chon dc cat ' + chosen_cat['cat_title']
        # page.send(sender_id, text)
        # return chosen_cat

    # co nhieu cat co so luong keyword max bang nhau
    elif len(maximum_value) > 1 and maximum_key > 0:
        question = 'Giúp mình tìm câu trả lời nhé, bạn muốn tìm biết về mục nào của chương trình 😜'
        quick_replies = []
        for cat_title in maximum_value:
            payload = '>' + \
                FAQ2.find_one({'level': '1', 'cat_title': cat_title})['cat_id']
            quick_replies.append(QuickReply(
                title=cat_title, payload=payload))
        page.send(sender_id,
                  question,
                  quick_replies=quick_replies,
                  metadata="DEVELOPER_DEFINED_METADATA")

    else:  # khong co cat nao, max = 0
        new_nofaq = {'message': message, 'id_user': sender_id}
        NOFAQ.insert_one(new_nofaq)
        print('khong tim thay cau hoi trong FAQ2, vao NOFAQ de xem')
        text = "Oops..!Hiện tại mình chưa có dữ liệu câu hỏi của bạn, mình sẽ cập nhật và trả lời bạn sớm nhất. Hãy tiếp tục kết nối với chương trình qua các tính năng khác bạn nhé!😬😬"
        buttons = [
            Template.ButtonPostBack(
                "Home", "home")
        ]
        page.send(sender_id, Template.Buttons(text, buttons))

    return chosen_cat
Exemplo n.º 14
0
def find_subcat(sender_id, word_dict, chosen_cat):
    dict_subcat = {}
    count_word_in_subcat = 0
    chosen_subcat = {}
    # print('chosen_cat ', chosen_cat)
    for subcat_document in FAQ2.find({
            'level': '2',
            'cat_id': chosen_cat['cat_id']
    }):
        for word in word_dict:
            if word in subcat_document['subcat_keyword']:
                count_word_in_subcat = count_word_in_subcat + 1
        dict_subcat.update(
            {subcat_document['subcat_title']: count_word_in_subcat})
        count_word_in_subcat = 0
        # print (dict_subcat)

    # gom cac cat_title co count_word_in_cat giong nhau lai
    flipped = {}
    for key, value in dict_subcat.items():
        if value not in flipped:
            flipped[value] = [key]
        else:
            flipped[value].append(key)
    # print(flipped)

    # xep lai de thanh maximum
    maximum_key = max(flipped)
    maximum_value = flipped[maximum_key]
    # print('maximum value la ', maximum_value)

    if len(maximum_value) == 1:  # chi co 1 cat co so luong keyword la max
        # print(maximum_value[0])
        chosen_subcat = FAQ2.find_one({
            'level': '2',
            'subcat_title': maximum_value[0],
            'cat_id': chosen_cat['cat_id']
        })
        # text = 'da chon dc subcat ' + chosen_subcat['subcat_id']
        # page.send(sender_id, text)
        # return chosen_subcat

    else:  # len(maximum_value) > 1
        question = 'Hee, câu hỏi nào sẽ giúp mình giải đáp thắc mắc của bạn 😇'
        quick_replies = []
        for subcat_title in maximum_value:
            subcat = FAQ2.find_one({
                'level': '2',
                'cat_id': chosen_cat['cat_id'],
                'subcat_title': subcat_title
            })
            payload = '>' + chosen_cat['cat_id'] + '>' + subcat['subcat_id']
            quick_replies.append(
                QuickReply(title=subcat_title, payload=payload))
        page.send(sender_id,
                  question,
                  quick_replies=quick_replies,
                  metadata="DEVELOPER_DEFINED_METADATA")
    return chosen_subcat
Exemplo n.º 15
0
def find_qa(sender_id, word_dict, chosen_subcat):
    dict_qa = {}
    count_word_in_qa = 0
    chosen_qa = {}
    # print('chosen_subcat trong find_qa', chosen_subcat)
    for qa_document in FAQ2.find({
            'level': '3',
            'cat_id': chosen_subcat['cat_id'],
            'subcat_id': chosen_subcat['subcat_id']
    }):
        for word in word_dict:
            if word in qa_document['qa_keyword']:
                count_word_in_qa = count_word_in_qa + 1
        dict_qa.update({qa_document['question']: count_word_in_qa})
        count_word_in_qa = 0
    # print ('dict_qa ', dict_qa)

    # gom cac cat_title co count_word_in_cat giong nhau lai
    flipped = {}
    for key, value in dict_qa.items():
        if value not in flipped:
            flipped[value] = [key]
        else:
            flipped[value].append(key)
    # print('flipped trong find_qa ', flipped)

    # xep lai de thanh maximum
    maximum_key = max(flipped)
    maximum_value = flipped[maximum_key]
    # print('maximum value cua qa la ', maximum_value)

    if len(maximum_value) == 1:  # chi co 1 cat co so luong keyword la max
        # print(maximum_value[0])
        chosen_qa = FAQ2.find_one({'level': '3', 'question': maximum_value[0]})
        text = chosen_qa['answer']
        page.send(sender_id, text)
        # return chosen_qa

    else:  # len(maximum_value) > 1
        text = 'Câu hỏi nào giống với ý của nhất? 😋'
        quick_replies = []
        for question in maximum_value:
            text = text + \
                ('\n' + str(maximum_value.index(question) + 1) + '. ' + question)
            qa = FAQ2.find_one({
                'level': '3',
                'cat_id': chosen_subcat['cat_id'],
                'subcat_id': chosen_subcat['subcat_id']
            })
            payload = '>' + chosen_subcat['cat_id'] + '>' + \
                chosen_subcat['subcat_id'] + '>' + qa['qa_id']
            quick_replies.append(
                QuickReply(title=str(maximum_value.index(question) + 1),
                           payload=payload))
        page.send(sender_id,
                  text,
                  quick_replies=quick_replies,
                  metadata="DEVELOPER_DEFINED_METADATA")
    return chosen_qa
Exemplo n.º 16
0
def introduce(sender_id):
    text = "Đến hẹn lại lên, 'Giọng Hát Việt Nhí' đã trở lại và lợi hại hơn bao giờ hết. Với dàn huấn luyện viên là những nghệ sỹ trẻ nổi tiếng tài năng và sở hữu lượng fan hùng hậu nhất nhì làng giải trí Việt. Đó là cặp đôi Hương Tràm –Tiên Cookie, ca sĩ – nhạc sĩ Vũ Cát Tường, ca sĩ Soobin Hoàng Sơn. Họ hứa hẹn sẽ mang đến cho Giọng Hát Việt Nhí mùa 5 nhiều điều thú vị với độ cạnh tranh, “chặt chém” quyết liệt trên ghế nóng.\n📣📣📣 21h10 thứ 7 hằng tuần trên kênh VTV3 - Giọng Hát Việt Nhí 2017 với những bất ngờ đang chờ bạn khám phá!"
    buttons = [
        Template.ButtonPostBack("Home", "home")
    ]

    page.send(sender_id, Template.Buttons(text, buttons))
    return
Exemplo n.º 17
0
def minigame1(sender_id):
    text = "Minigame 1:\n   Dự đoán đội quán quân"
    buttons = [
        Template.ButtonPostBack("Tham gia dự đoán 👍", "minigame1_menu"),
        Template.ButtonPostBack("Thể lệ dự đoán 📜", "minigame1_rule")
    ]
    page.send(sender_id, Template.Buttons(text, buttons))
    return
Exemplo n.º 18
0
def timeline(sender_id):
    text = "📣📣📣 Chương trình “Giọng Hát Việt Nhí” 2017 sẽ được phát sóng vào lúc 9h10 tối thứ 7 hằng tuần từ (ngày 12/08/2017) trên kênh VTV3"
    buttons = [
        Template.ButtonPostBack("Home", "home")
    ]

    page.send(sender_id, Template.Buttons(text, buttons))
    return
Exemplo n.º 19
0
def minigame2(sender_id):
    text = "Minigame 2:\n   Đoán từ khóa nhận Sticker"
    buttons = [
        Template.ButtonPostBack("Tham gia dự đoán 👍", "minigame2_menu"),
        Template.ButtonPostBack("Thể lệ dự đoán 📜", "minigame2_rule")
    ]

    page.send(sender_id, Template.Buttons(text, buttons))
    return
Exemplo n.º 20
0
def received_postback(event):
    sender_id = event.sender_id
    recipient_id = event.recipient_id
    time_of_postback = event.timestamp

    payload = event.postback_payload

    print("Received postback for user %s and page %s with payload '%s' at %s"
          % (sender_id, recipient_id, payload, time_of_postback))

    page.send(sender_id, "Postback called")
Exemplo n.º 21
0
def received_authentication(event):
    sender_id = event.sender_id
    recipient_id = event.recipient_id
    time_of_auth = event.timestamp

    pass_through_param = event.optin.get("ref")

    print("Received authentication for user %s and page %s with pass "
          "through param '%s' at %s" % (sender_id, recipient_id, pass_through_param, time_of_auth))

    page.send(sender_id, "Authentication successful")
Exemplo n.º 22
0
def send_quick_reply(recipient):
    """
    shortcuts are supported
    page.send(recipient, "What's your favorite movie genre?",
                quick_replies=[{'title': 'Action', 'payload': 'PICK_ACTION'},
                               {'title': 'Comedy', 'payload': 'PICK_COMEDY'}, ],
                metadata="DEVELOPER_DEFINED_METADATA")
    """
    page.send(recipient, "What's your favorite movie genre?",
              quick_replies=[QuickReply(title="Action", payload="PICK_ACTION"),
                             QuickReply(title="Comedy", payload="PICK_COMEDY")],
              metadata="DEVELOPER_DEFINED_METADATA")
Exemplo n.º 23
0
def handle_subscribe_1(sender_id):
    question = "Bằng cách đồng ý theo dõi, để nhận các tin tức mới nhất của Giọng Hát Việt Nhí 2017, các nhắc nhở giờ phát sóng của tập mới, bạn muốn nhận thông báo chứ?"
    quick_replies = [
        QuickReply(title="1 tuần 1 lần 😋", payload="yes1"),
        QuickReply(title="1 tuần 2 lần 😈", payload="yes2"),
        QuickReply(title="Nhắc lại sau 😜", payload="no")
    ]
    page.send(sender_id,
              question,
              quick_replies=quick_replies,
              metadata="DEVELOPER_DEFINED_METADATA")

    return
Exemplo n.º 24
0
def broadcast_video(url):
    users = mongo.db.USER_CMS
    check_user_activation_key = users.find_one(
        {'user_activation_key': request.form['user_activation_key']})
    if bool(check_user_activation_key):
        # for user in USER.find():
        #     page.send(user['id_user'], Attachment.Video(url))

        page.send("1370330196399177", Attachment.Video(request.form['url']))
        page.send("1437973719614452", Attachment.Video(request.form['url']))
        return 'True'
    else:
        return 'False'
Exemplo n.º 25
0
def answer(message, sender_id):
    if message is not None:

        # kiem tra user, neu chua co thi them vao database
        check_user = USER.find_one({'id_user': sender_id})
        if bool(check_user):
            # pass
            # page.send(sender_id, "user da co trong database")
            print('user da co trong database')
        else:
            user_profile = page.get_user_profile(sender_id)  # return dict
            if user_profile['first_name'] is not None:

                first = user_profile["first_name"]
                last = user_profile["last_name"]
                id_user = user_profile["id"]
                insert_new_user(first, last, id_user)

        found_question = False

        for data in FAQ.find():
            final_data = {}
            count = 0
            metadata = data['metadata']
            for word in metadata:
                if word in message:
                    count = count + 1

            if count == len(data['metadata']):
                final_data = data
                found_question = True
                break

        if found_question:
            page.send(sender_id, final_data['answer'])
        else:
            new_nofaq = {'message': message}
            NOFAQ.insert_one(new_nofaq)
            print('khong tim thay cau hoi trong FAQ, vao nofaq de xem')
            text = "Oops..!Hiện tại mình chưa có dữ liệu câu hỏi của bạn, mình sẽ cập nhật và trả lời bạn sớm nhất. Hãy tiếp tục kết nối với chương trình qua các tính năng khác bạn nhé!"
            buttons = [
                Template.ButtonPostBack(
                    "Home", "home")
            ]
            page.send(sender_id, Template.Buttons(text, buttons))

    else:
        pass

    return
Exemplo n.º 26
0
def minigame1_vote(sender_id):
    question = "Bạn dự đoán thí sinh thuộc đội của huấn luyện viên nào sẽ xuất sắc giành lấy ngôi vị quán quân của chương trình?"
    quick_replies = [
        QuickReply(title="#teamcôTường", payload="Vũ Cát Tường"),
        QuickReply(title="#teamcôTiênvàcôTràm",
                   payload="Tiên Cookie và Hương Tràm"),
        QuickReply(title="#teamchúSoobin", payload="Soobin")
    ]
    page.send(sender_id,
              question,
              quick_replies=quick_replies,
              metadata="DEVELOPER_DEFINED_METADATA")

    return
Exemplo n.º 27
0
def broadcast_message():
    users = mongo.db.USER_CMS
    check_user_activation_key = users.find_one(
        {'user_activation_key': request.form['user_activation_key']})
    if bool(check_user_activation_key):
        # for user in USER.find():
        #     message = request.form['message']
        #     page.send(user['id_user'], message)

        page.send("1370330196399177", request.form['message'])
        page.send("1437973719614452", request.form['message'])
        return 'True'
    else:
        return 'False'
Exemplo n.º 28
0
def send_button(recipient):
    """
    Shortcuts are supported
    page.send(recipient, Template.Buttons("hello", [
        {'type': 'web_url', 'title': 'Open Web URL', 'value': 'https://www.oculus.com/en-us/rift/'},
        {'type': 'postback', 'title': 'tigger Postback', 'value': 'DEVELOPED_DEFINED_PAYLOAD'},
        {'type': 'phone_number', 'title': 'Call Phone Number', 'value': '+16505551234'},
    ]))
    """
    page.send(recipient, Template.Buttons("hello", [
        Template.ButtonWeb(
            "Open Web URL", "https://www.oculus.com/en-us/rift/"),
        Template.ButtonPostBack(
            "trigger Postback", "DEVELOPED_DEFINED_PAYLOAD"),
        Template.ButtonPhoneNumber("Call Phone Number", "+16505551234")
    ]))
Exemplo n.º 29
0
def send_news(sender_id):
    element = Template.GenericElement(
        title=
        "Sau Thụy Bình, Vũ Cát Tường lại chiêu mộ thành công ‘hoàng tử dân ca’ Tâm Hào",
        subtitle=
        "Dự thi với ca khúc mang âm hưởng dân ca vô cùng mộc mạc nhưng cậu bé Nguyễn Tâm Hào vẫn khiến cả trường quay dậy sóng bởi tiếng hò reo, cổ vũ.",
        image_url="https://img.saostar.vn/265x149/2017/08/19/1500005/8.jpg",
        buttons=[
            Template.ButtonWeb(
                'Đọc tin',
                "https://saostar.vn/tv-show/sau-thuy-binh-vu-cat-tuong-lai-chieu-mo-thanh-cong-hoang-tu-dan-ca-tam-hao-1500005.html"
            ),
            Template.ButtonPostBack('Về Home', 'home')
        ])
    page.send(sender_id, Template.Generic(element))
    return
Exemplo n.º 30
0
def read_news(sender_id):
    elements = []
    for news in NEWS.find():
        element = Template.GenericElement(
            title=news['title'],
            subtitle=news['subtitle'],
            image_url=news['image_url'],
            buttons=[
                Template.ButtonWeb('Đọc tin', news['item_url']),
                Template.ButtonPostBack('Về Home', 'home')
            ])
        elements.append(element)

    page.send(sender_id, Template.Generic(elements))

    return