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

        CUSTOMER.update_one(
            {'id_user': sender_id},
            {'$set': {
                'SCRIPT.subscribe_news': quick_reply_payload
            }})

        # 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", "saostar_home")]
        saostar.send(sender_id, Template.Buttons(text, buttons))

        CUSTOMER.update_one(
            {'id_user': sender_id},
            {'$set': {
                'SCRIPT.subscribe_news': quick_reply_payload
            }})
Пример #2
0
def saostar_get_news_thoi_trang(sender_id):
    elements = []
    news_list = []
    for news in NEWS.find({'chatbot': 'saostar', 'category': 'thoi trang'}):
        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('HOME', 'saostar_home')
            ])
        elements.append(element)

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

    question = 'Xem thêm'
    quick_replies = [
        QuickReply(title="Xem thêm", payload="xem_them"),
        QuickReply(title="Giải trí", payload="giai_tri"),
        QuickReply(title="Âm nhạc", payload="am_nhac"),
        QuickReply(title="Phim ảnh", payload="phim_anh"),
        QuickReply(title="Đời sống", payload="doi_song")
        # QuickReply(title="Âm nhạc", payload="thoi_trang")
    ]
    saostar.send(sender_id,
                 question,
                 quick_replies=quick_replies,
                 metadata="DEVELOPER_DEFINED_METADATA")
Пример #3
0
def saostar_greeting(sender_id):
    user_profile = saostar.get_user_profile(sender_id)
    first = user_profile["first_name"]
    last = user_profile["last_name"]

    check_customer_by_id('saostar', 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 Saostar có nhé'
    buttons = [Template.ButtonPostBack("HOME", "saostar_home")]
    saostar.send(sender_id, Template.Buttons(text, buttons))
Пример #4
0
def saostar_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")
    ]
    saostar.send(sender_id,
                 question,
                 quick_replies=quick_replies,
                 metadata="DEVELOPER_DEFINED_METADATA")
Пример #5
0
def saostar_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 Saostar nhé!'
            buttons = [Template.ButtonPostBack("HOME", "saostar_home")]
            saostar.send(sender_id, Template.Buttons(text, buttons))
Пример #6
0
def saostar_chuyen_muc(sender_id):
    question = "Chọn chuyên mục bạn muốn xem"
    quick_replies = [
        QuickReply(title="Âm nhạc", payload="am_nhac"),
        QuickReply(title="Giải trí", payload="giai_tri"),
        QuickReply(title="Phim ảnh", payload="phim_anh"),
        QuickReply(title="Thời trang", payload="thoi_trang"),
        QuickReply(title="Đời sống", payload="doi_song")
    ]
    saostar.send(sender_id,
                 question,
                 quick_replies=quick_replies,
                 metadata="DEVELOPER_DEFINED_METADATA")
Пример #7
0
def saostar_implement_upload(sender_id):
    # text = 'hãy chọn hình ảnh để upload cho'
    text = 'chọn hình và gửi'

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

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

    saostar.send(sender_id, text)
Пример #8
0
def saostar_home(sender_id):
    elements = [
        # Template.GenericElement("Đóng góp hình ảnh",
        #                         subtitle="Saostar",
        #                         # image_url="http://210.211.109.211/weqbfyretnccbsaf/saostar_tintuc.jpg",
        #                         buttons=[
        #                             Template.ButtonPostBack(
        #                                 "Upload", "saostar_menu_upload")

        #                         ]),
        Template.GenericElement(
            "Tin tức",
            subtitle="Saostar",
            # image_url="http://210.211.109.211/weqbfyretnccbsaf/saostar_xemtintuc.jpg",
            buttons=[
                Template.ButtonPostBack("Xem tin tức",
                                        "saostar_get_news_general"),
                Template.ButtonPostBack("Theo dõi tin tức",
                                        "saostar_menu_subscribe")
            ])
    ]
    saostar.send(sender_id, Template.Generic(elements))
Пример #9
0
def saostar_menu_upload(sender_id):
    text = 'nhấn chọn nút ở dưới để bắt đầu quy trình upload'
    buttons = [Template.ButtonPostBack("Upload", "saostar_implement_upload")]
    saostar.send(sender_id, Template.Buttons(text, buttons))
Пример #10
0
def saostar_ads(sender_id):
    text = 'Liên hệ hợp tác quảng cáo & xuất bản nội dung: [email protected] ❤'
    buttons = [Template.ButtonPostBack("HOME", "saostar_home")]
    saostar.send(sender_id, Template.Buttons(text, buttons))