コード例 #1
0
ファイル: postback.py プロジェクト: hoangphuc17/cdhh-ttb
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
コード例 #2
0
ファイル: postback.py プロジェクト: hoangphuc17/cdhh-ttb
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
コード例 #3
0
ファイル: postback.py プロジェクト: hoangphuc17/cdhh-ttb
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
コード例 #4
0
ファイル: postback.py プロジェクト: hoangphuc17/Bot
def fansign_handle_quick_reply(sender_id, quickreply):
    user_profile = page.get_user_profile(sender_id)
    first = user_profile["first_name"]
    last = user_profile["last_name"]
    userName = last + ' ' + first

    def fs_vct():
        if len(userName) < 11:
            image_fs(sender_id, 90, "vct", first, last, 180, 370)
        else:
            image_fs(sender_id, 80, "vct", first, last, 90, 370)

    def fs_ht():
        if len(userName) < 11:
            image_fs(sender_id, 80, "ht", first, last, 180, 330)
        else:
            image_fs(sender_id, 65, "ht", first, last, 180, 330)

    def fs_tc():
        if len(userName) < 11:
            image_fs(sender_id, 90, "tc", first, last, 180, 390)
        else:
            image_fs(sender_id, 80, "tc", first, last, 90, 380)

    def fs_sb():
        if len(userName) < 11:
            image_fs(sender_id, 85, "sb", first, last, 30, 450)
        else:
            image_fs(sender_id, 70, "sb", first, last, 30, 455)

    fs_hlv_list = {'sb': fs_sb, 'vct': fs_vct, 'ht': fs_ht, 'tc': fs_tc}

    if quickreply in fs_hlv_list:
        fs_hlv_list[quickreply]()
コード例 #5
0
ファイル: message.py プロジェクト: hoangphuc17/Bot
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
コード例 #6
0
def save_message(sender_id, message):
    if message is not None:
        check_user = USER.find_one({'id_user': sender_id})
        if bool(check_user):
            print("Day la ham save_message(). User da co trong database")
        else:
            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"]
            insert_new_user(first_name, last_name, id_user)

        USER.update_one(
            {'id_user': sender_id},
            {'$push': {'message': {'content': message,
                                   'time': datetime.datetime.now()}}}
        )
    else:
        pass
コード例 #7
0
ファイル: message.py プロジェクト: hoangphuc17/Bot
def handle_faq_message(sender_id, message):
    if message is not None:
        print('message la: ', message)
        # 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)

        # TACH TU (word_segmentation)
        word_dict = word_sent(message)
        print('Word Segmentation: ', word_dict)

        chosen_cat = find_cat(sender_id, word_dict, message)
        if chosen_cat != {}:
            print('da tim thay chosen_cat')
            chosen_subcat = find_subcat(sender_id, word_dict, chosen_cat)
            if chosen_subcat != {}:
                print('da tim thay chosen_subcat')
                chosen_qa = find_qa(sender_id, word_dict, chosen_subcat)

                if chosen_qa != {}:
                    print('da tim thay chosen_qa')
                else:
                    print(
                        'tim thay chosen_cat,tim thay chosen_subcat, khong tim thay chosen_qa')
            else:
                print('tim thay chosen_cat, khong tim thay chosen_subcat')
        else:
            print('khong tim thay chosen_cat')
    else:
        print('Message is None')
コード例 #8
0
ファイル: postback.py プロジェクト: hoangphuc17/cdhh-ttb
def home(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):
        print('user da co trong database')
    else:
        insert_new_user(first_name, last_name, id_user)

    elements = [
        Template.GenericElement("Fansign",
                                subtitle="Cùng đón nhận những lời chúc từ các huấn luyện viên Giọng Hát Việt Nhí 2017!!!",
                                image_url="http://210.211.109.211/weqbfyretnccbsaf/home_hinh1_tin_tuc.jpg",
                                buttons=[
                                    Template.ButtonPostBack(
                                        "Lấy Fansign", "fansign")
                                ]),
        Template.GenericElement("Tin tức mới nhất từ chương trình “Giọng Hát Việt Nhí” 2017",
                                subtitle="Nơi cập nhật những tin tức mới nhất từ chương trình “Giọng Hát Việt Nhí” 2017",
                                image_url="http://210.211.109.211/weqbfyretnccbsaf/home_hinh1_tin_tuc.jpg",
                                buttons=[
                                    Template.ButtonPostBack(
                                        "Xem tin tức 👓", "read_news"),
                                    Template.ButtonPostBack(
                                        "Theo dõi tin tức 📸", "subscribe_news")
                                ]),
        Template.GenericElement("Video Full - The Voice Kids 2017 | Giọng Hát Việt Nhí mùa 5",
                                subtitle="Xem lại bản đầy dủ các tập đã được phát sóng trên Youtube, Live Streaming",
                                image_url="http://210.211.109.211/weqbfyretnccbsaf/home_hinh2_xem_video.jpg",
                                buttons=[
                                    Template.ButtonWeb(
                                        "Xem lại tập đã phát", "https://www.youtube.com/user/btcgionghatvietnhi"),
                                    Template.ButtonWeb(
                                        "Oh my kids", "https://www.youtube.com/playlist?list=PLEhBV4sOYnBml5RPOlILDvj5DqNwmG9AI"),
                                    Template.ButtonWeb(
                                        "Off the air", "https://www.youtube.com/playlist?list=PLEhBV4sOYnBk1BX8Jks9152rkNTIZQWuK")
                                ]),

        Template.GenericElement("Dự đoán kết quả và giành lấy cơ hội nhận quà",
                                subtitle="Tham gia dự đoán kết quả của cuộc thi để nhận được những phần quà hấp dẫn nhất từ ban tổ chức",
                                image_url="http://210.211.109.211/weqbfyretnccbsaf/home_hinh3_du_doan.jpg",
                                buttons=[
                                    Template.ButtonPostBack(
                                        "Minigame 1", "minigame1"),
                                    Template.ButtonPostBack(
                                        "Minigame 2", "minigame2")
                                ]),
        Template.GenericElement("About us",
                                subtitle="Theo dõi chương trình Giọng Hát Việt Nhí 2017 tại các kênh truyền thông",
                                image_url="http://210.211.109.211/weqbfyretnccbsaf/home_hinh4_about_us.jpg",
                                buttons=[
                                    Template.ButtonWeb(
                                        "Facebook", "https://www.facebook.com/gionghatvietnhi/"),
                                    Template.ButtonPostBack(
                                        "Giờ phát sóng", "time line"),
                                    Template.ButtonPostBack(
                                        "Giới thiệu", "introduce")
                                ])
    ]
    page.send(sender_id, Template.Generic(elements))
    return