Пример #1
0
def svtv_handle_subscribe(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", "svtv_home")
        ]
        svtv.send(sender_id, Template.Buttons(text, buttons))

        user = CUSTOMER.find_one({'id_user': sender_id})
        new_script = {
            'upload_status': user['SCRIPT']['upload_status'],
            'subscribe': quick_reply_payload
        }
        CUSTOMER.update_one(
            {'id_user': sender_id},
            {'$set': {'SCRIPT': new_script}}
        )
    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, mình sẽ gửi tới bạn."
        buttons = [
            Template.ButtonPostBack("HOME", "svtv_home")
        ]
        svtv.send(sender_id, Template.Buttons(text, buttons))

        user = CUSTOMER.find_one({'id_user': sender_id})
        new_script = {
            'upload_status': user['SCRIPT']['upload_status'],
            'subscribe': quick_reply_payload
        }
        CUSTOMER.update_one(
            {'id_user': sender_id},
            {'$set': {'SCRIPT': new_script}}
        )
Пример #2
0
def svtv_default_message(sender_id):
    text = 'Chào bạn! Sinh Viên TV có thể giúp gì cho bạn?'
    buttons = [
        Template.ButtonPostBack(
            "HOME", "svtv_home")
    ]
    svtv.send(sender_id, Template.Buttons(text, buttons))
Пример #3
0
def svtv_ads(sender_id):
    text = 'Liên hệ hợp tác quảng cáo & xuất bản nội dung: [email protected]\nhoặc Hotline: 097.674.6263 (Mr Dương).'
    buttons = [
        Template.ButtonPostBack(
            "Home", "svtv_home")
    ]
    svtv.send(sender_id, Template.Buttons(text, buttons))
Пример #4
0
def svtv_get_news(sender_id):
    elements = []
    news_list = []
    for news in NEWS.find({'chatbot': 'svtv'}):
        news_list.append(news)

    for news in news_list:
        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', 'svtv_home')
            ])
        elements.append(element)

    short_list_elements = random.sample(elements, 5)
    svtv.send(sender_id, Template.Generic(short_list_elements))

    question = 'Xem thêm'
    quick_replies = [
        QuickReply(title="Xem thêm", payload="svtv_get_news")

    ]
    svtv.send(sender_id,
              question,
              quick_replies=quick_replies,
              metadata="DEVELOPER_DEFINED_METADATA")
Пример #5
0
def svtv_menu_upload(sender_id):
    # text = 'nhấn chọn nút ở dưới để bắt đầu quy trình upload'
    text = 'Chào bạn, bạn muốn đóng góp nội dung gì cho Sinh Viên TV? Chọn nút bên dưới để bắt đầu Upload'
    buttons = [
        Template.ButtonPostBack(
            "Upload", "svtv_implement_upload")
    ]
    svtv.send(sender_id, Template.Buttons(text, buttons))
Пример #6
0
def svtv_implement_upload(sender_id):
    # text = 'hãy chọn hình ảnh để upload cho'
    text = 'hãy chọn 📷Ảnh – 🎬Video'

    # update upload_status = yes
    CUSTOMER.update_one(
        {'id_user': sender_id},
        {'$set': {'SCRIPT': {'id_user': sender_id, 'upload_status': 'on'}}}
    )

    svtv.send(sender_id, text)
Пример #7
0
def svtv_menu_subscribe(sender_id):
    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 đượ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")
    ]
    svtv.send(sender_id,
             question,
             quick_replies=quick_replies,
             metadata="DEVELOPER_DEFINED_METADATA")
Пример #8
0
def svtv_greeting(sender_id):
    user_profile = svtv.get_user_profile(sender_id)
    first = user_profile["first_name"]
    last = user_profile["last_name"]

    check_customer_by_id('svtv', sender_id)
    print(sender_id)
    text = 'Chào ' + first + ' ' + last + \
        '. Nhấn nút home bên dưới để tìm hiểu các tính năng Sinh viên TV có nhé'
    buttons = [
        Template.ButtonPostBack(
            "HOME", "svtv_home")
    ]
    svtv.send(sender_id, Template.Buttons(text, buttons))
Пример #9
0
def svtv_upload_success_continue(chatbot, sender_id, attachment_link):
    # check upload status
    # save hình đó lại
    # hiển thị thông báo đã upload thành công
    # hỏi upload tiếp tục không
    cus = CUSTOMER.find_one({'id_user': sender_id})
    if bool(cus):
        if cus['SCRIPT']['upload_status'] == 'on':
            save_attachments(chatbot, sender_id, attachment_link)

            text = 'Cảm ơn bạn đã đóng góp cho Sinh Viên TV nhé!'
            buttons = [
                Template.ButtonPostBack(
                    "HOME", "svtv_home")
            ]
            svtv.send(sender_id, Template.Buttons(text, buttons))
Пример #10
0
def svtv_home(sender_id):
    elements = [
        # Template.GenericElement("Đóng góp hình ảnh",
        #                         subtitle="svtv",
        #                         # image_url="http://210.211.109.211/weqbfyretnccbsaf/ttb_tintuc.jpg",
        #                         buttons=[
        #                             Template.ButtonPostBack(
        #                                 "Upload", "svtv_menu_upload")
        #                         ]),
        Template.GenericElement("Tin tức",
                                subtitle="svtv",
                                # image_url="http://210.211.109.211/weqbfyretnccbsaf/ttb_xemtintuc.jpg",
                                buttons=[
                                    Template.ButtonPostBack(
                                        "Xem tin tức", "svtv_get_news"),
                                    Template.ButtonPostBack(
                                        "Theo dõi tin tức", "svtv_menu_subscribe")
                                ])
    ]
    svtv.send(sender_id, Template.Generic(elements))