Ejemplo n.º 1
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'
Ejemplo n.º 2
0
def image_fs(sender_id, sizeFont, hlv, first_name, last_name, x_Text, y_Text):
    userName = last_name + ' ' + first_name
    font = ImageFont.truetype("./font.ttf", sizeFont)
    imageFile = "image/" + hlv + ".jpg"
    im = Image.open(imageFile)
    draw = ImageDraw.Draw(im)
    draw.text((x_Text, y_Text), userName, (0, 0, 0), font=font)
    draw = ImageDraw.Draw(im)
    name_fansigned = "/home/hoangphuc/Bot_Pictures/fs_" + hlv + \
        sender_id + ".jpg"
    im.save(name_fansigned)

    hlv_dict = {
        'sb': 'Soobin',
        'vct': 'Vũ Cát Tường',
        'ht': 'Hương Tràm',
        'tc': 'Tiên Cookie'
    }

    text1 = hlv_dict.get(
        hlv) + " đang viết lời chúc dành cho bạn. " + userName + " chờ xíu nhé 😉"
    page.send(sender_id, text1)

    page.send(sender_id, Attachment.Image(
        "http://210.211.109.211/weqbfyretnccbsaf/fs_" + hlv + sender_id + ".jpg"))
    text2 = 'Phía trên là hình fansign của ' + \
        hlv_dict.get(
            hlv) + ' dành riêng cho bạn. Hãy chia sẻ món quà này ngay kèm hashtag #gionghatvietnhifansign nha bạn ơi'
    buttons = [
        Template.ButtonPostBack("Fansign khác", "fansign"),
        Template.ButtonPostBack("Home", "home")
    ]
    page.send(sender_id, Template.Buttons(text2, buttons))
    print('da gui hinh fansign')
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
0
def handle_faq_quickreply(sender_id, quickreply_dict):
    length = len(quickreply_dict)
    print('length of quick_reply_dict ', length)
    print(quickreply_dict)

    if length > 3:
        # length = 4
        cat_id = quickreply_dict[1]
        subcat_id = quickreply_dict[2]
        qa_id = quickreply_dict[3]
        result = FAQ2.find_one(
            {'level': '3', 'cat_id': cat_id, 'subcat_id': subcat_id, 'qa_id': qa_id})
        # print(result)
        text = result['answer']
        buttons = [
            Template.ButtonPostBack(
                "Home", "home")
        ]
        page.send(sender_id, Template.Buttons(text, buttons))

    elif length > 2:
        # length = 3
        print('quick_reply: co cat_id, co subcat_id, khong co qa_id')
        cat_id = quickreply_dict[1]
        subcat_id = quickreply_dict[2]
        question = 'Hee, câu hỏi nào sẽ giúp mình giải đáp thắc mắc của bạn 😇'
        cursor_qa = FAQ2.find(
            {'level': '3', 'cat_id': cat_id, 'subcat_id': subcat_id})
        dict_qa = []
        for i in cursor_qa:
            dict_qa.append(i)
        # print('dict_qa la ', dict_qa)
        quick_replies = []
        for qa in dict_qa:
            question = question + \
                ('\n' + str(dict_qa.index(qa) + 1) + '. ' + qa['question'])
            payload = '>' + cat_id + '>' + subcat_id + '>' + qa['qa_id']
            quick_replies.append(QuickReply(
                title=str(dict_qa.index(qa) + 1), payload=payload))
        page.send(sender_id,
                  question,
                  quick_replies=quick_replies,
                  metadata="DEVELOPER_DEFINED_METADATA")
    else:
        # length = 2
        print('quick_reply: co cat_id, khong co subcat_id')
        cat_id = quickreply_dict[1]
        dict_subcat = FAQ2.find({'level': '2', 'cat_id': cat_id})
        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 subcat in dict_subcat:
            payload = '>' + cat_id + '>' + subcat['subcat_id']
            quick_replies.append(QuickReply(
                title=subcat['subcat_title'], payload=payload))
        page.send(sender_id,
                  question,
                  quick_replies=quick_replies,
                  metadata="DEVELOPER_DEFINED_METADATA")
Ejemplo n.º 11
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
Ejemplo n.º 12
0
def broadcast_message_button():
    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']
        #     buttons = [
        #         Template.ButtonPostBack("Home", "home")
        #     ]
        #     page.send(user['id_user'], Template.Buttons(message, buttons))

        message = request.form['message']
        buttons = [Template.ButtonPostBack("Home", "home")]
        page.send("1370330196399177", Template.Buttons(message, buttons))
        page.send("1437973719614452", Template.Buttons(message, buttons))
        return 'True'
    else:
        return 'False'
Ejemplo n.º 13
0
def minigame2_handle_result(message, sender_id):
    message = message.lower()
    huong_tram = ["đỉnh", "xinh", "bánh bèo"]
    vu_cat_tuong = ["chất", "cá tính", "phũ"]
    soobin = ["đẹp trai", "ế", "cao"]
    tien_cookie = ["hit", "cute", "nhọ"]
    if message in huong_tram:
        game2_hlv_url = "http://210.211.109.211/weqbfyretnccbsaf/game2_huongtram.jpg"
        page.send(sender_id, Attachment.Image(game2_hlv_url))
        text = "Chính xác!!!!!!!!"
        buttons = [
            Template.ButtonPostBack("Đoán thêm lần nữa 😻", "minigame2_menu"),
            Template.ButtonPostBack("Home", "home")
        ]
        page.send(sender_id, Template.Buttons(text, buttons))
    elif message in vu_cat_tuong:
        game2_hlv_url = "http://210.211.109.211/weqbfyretnccbsaf/game2_vucattuong.jpg"
        page.send(sender_id, Attachment.Image(game2_hlv_url))
        text = "Chính xác!!!!!!!!"
        buttons = [
            Template.ButtonPostBack("Đoán thêm lần nữa 😻", "minigame2_menu"),
            Template.ButtonPostBack("Home", "home")
        ]
        page.send(sender_id, Template.Buttons(text, buttons))
    elif message in soobin:
        game2_hlv_url = "http://210.211.109.211/weqbfyretnccbsaf/game2_soobin.jpg"
        page.send(sender_id, Attachment.Image(game2_hlv_url))
        text = "Chính xác!!!!!!!!"
        buttons = [
            Template.ButtonPostBack("Đoán thêm lần nữa 😻", "minigame2_menu"),
            Template.ButtonPostBack("Home", "home")
        ]
        page.send(sender_id, Template.Buttons(text, buttons))
    elif message in tien_cookie:
        game2_hlv_url = "http://210.211.109.211/weqbfyretnccbsaf/game2_tiencookie.jpg"
        page.send(sender_id, Attachment.Image(game2_hlv_url))
        text = "Chính xác!!!!!!!!"
        buttons = [
            Template.ButtonPostBack("Đoán thêm lần nữa 😻", "minigame2_menu"),
            Template.ButtonPostBack("Home", "home")
        ]
        page.send(sender_id, Template.Buttons(text, buttons))
Ejemplo n.º 14
0
def handle_subscribe_news(sender_id, quick_reply_payload):
    if quick_reply_payload == 'no':
        text = "Okey. Bất cứ khi nào bạn cần đăng ký nhận tin tức thì quay lại đây nhé!"
        buttons = [Template.ButtonPostBack("Home", "home")]

        page.send(sender_id, Template.Buttons(text, buttons))
        USER.update_one({'id_user': sender_id},
                        {'$set': {
                            'subscribe_news': quick_reply_payload
                        }})
    else:
        text = "Bạn đã đăng ký nhận thông báo thành công. \nMỗi khi có thông báo mới về chương trình The Voice Kid 2017, mình sẽ gửi tới bạn."
        buttons = [Template.ButtonPostBack("Home", "home")]

        page.send(sender_id, Template.Buttons(text, buttons))
        USER.update_one({'id_user': sender_id},
                        {'$set': {
                            'subscribe_news': quick_reply_payload
                        }})
    return
Ejemplo n.º 15
0
def vote_handler(sender_id, quickreply):
    space = " "
    a = "Bạn đã dự đoán thành công. Dự đoán của bạn đang dành cho"
    seq = (a, quickreply)
    text = space.join(seq)
    buttons = [
        Template.ButtonPostBack("Bình chọn lại", "vote_menu"),
        Template.ButtonPostBack("Home", "home")
    ]
    cdhh.send(sender_id, Template.Buttons(text, buttons))

    USER.update_one({'id_user': sender_id}, {'$set': {'vote': quickreply}})
    return 'vote handler OK'
Ejemplo n.º 16
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
Ejemplo n.º 17
0
def cdhh_greeting(sender_id):
    user_profile = cdhh.get_user_profile(sender_id)
    print(user_profile)
    first = user_profile["first_name"]
    last = user_profile["last_name"]

    check_user(sender_id)

    space = " "
    a = "Chào"
    b = "đến với Cặp Đôi Hoàn Hảo - Trữ Tình & Bolero. \nMình là LERO, rất vui được gặp bạn. Bạn có thể cùng mình cập nhật thông tin về chương trình một cách nhanh nhất. Cùng khám phá nào! 👇👇"
    seq = (a, last, first, b)
    text = space.join(seq)
    buttons = [Template.ButtonPostBack("Home", "home")]
    cdhh.send(sender_id, Template.Buttons(text, buttons))
    return 'cdhh_greeting OK'
Ejemplo n.º 18
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")
    ]))
Ejemplo n.º 19
0
def minigame1_handle_quick_reply(sender_id, quick_reply_payload):
    hinh_hlv = "http://210.211.109.211/weqbfyretnccbsaf/" + \
        danh_sach_hinh_anh_HLV[quick_reply_payload]
    page.send(sender_id, Attachment.Image(hinh_hlv))

    space = " "
    a = "Bạn đã dự đoán dự đoán thành công đội có thí sinh đạt được vị trí cao nhất của chương trình. Dự đoán của bạn đang dành cho team của"
    seq = (a, quick_reply_payload)
    text = space.join(seq)
    buttons = [
        Template.ButtonPostBack("Bình chọn lại", "minigame1_vote"),
        Template.ButtonPostBack("Home", "home")
    ]
    page.send(sender_id, Template.Buttons(text, buttons))

    USER.update_one(
        {'id_user': sender_id},
        {'$set': {'HLV_da_binh_chon': quick_reply_payload}}
    )

    return
Ejemplo n.º 20
0
def minigame1_menu(sender_id):
    check_vote = USER.find_one({'id_user': sender_id})

    if check_vote["HLV_da_binh_chon"] == "":
        # user chua binh chon
        minigame1_vote(sender_id)
    else:
        # user da binh chon
        space = " "
        a = "Bạn đã dự đoán dự đoán thành công đội có thí sinh đạt được vị trí cao nhất của chương trình. Dự đoán của bạn đang dành cho team của"
        # a = a.decode('utf-8')
        b = check_vote["HLV_da_binh_chon"]
        seq = (a, b)
        text = space.join(seq)

        buttons = [
            Template.ButtonPostBack("Bình chọn lại", "minigame1_vote"),
            Template.ButtonPostBack("Home", "home")
        ]

        page.send(sender_id, Template.Buttons(text, buttons))
    return
Ejemplo n.º 21
0
def vote(sender_id):
    check_vote = USER.find_one({'id_user': sender_id})

    if check_vote['vote'] == '':
        # user chua binh chon
        vote_menu(sender_id)
    else:
        # user da binh chon
        space = " "
        a = "Bạn đã dự đoán thành công. Dự đoán của bạn đang dành cho"
        b = check_vote["vote"]
        seq = (a, b)
        text = space.join(seq)

        buttons = [
            Template.ButtonPostBack("Bình chọn lại", "vote_menu"),
            Template.ButtonPostBack("Home", "home")
        ]

        cdhh.send(sender_id, Template.Buttons(text, buttons))

    return 'vote OK'
Ejemplo n.º 22
0
def broadcast_message(sender_id, text):
    buttons = [
        Template.ButtonPostBack("Home", "home")
    ]
    page.send(sender_id, Template.Buttons(text, buttons))
Ejemplo n.º 23
0
def broadcast_message_link_button(sender_id, text, link):
    buttons = [
        Template.ButtonWeb('👉 Xem tiết mục', link),
        Template.ButtonPostBack("Home", "home")
    ]
    page.send(sender_id, Template.Buttons(text, buttons))