Пример #1
0
def received_postback(event):
    sender_id = event.sender_id
    recipient_id = event.recipient_id
    time_of_postback = event.timestamp
    payload = event.payload

    page.typing_on(sender_id)
    page.send(
        sender_id,
        "Welcome! Search yelp for something like this:\nDISH, LOCATION\n\nChange default location with location=LOCATION"
    )
    db.insert_user(sender_id)
    page.typing_off(sender_id)
Пример #2
0
def received_postback(event):
    sender_id = event.sender_id
    recipient_id = event.recipient_id
    time_of_postback = event.timestamp
    payload = event.payload

    page.typing_on(sender_id)

    if (payload == "Subscribe"):
        if not db.user_exists(sender_id):
            handle_unsub(sender_id)
        else:
            page.send(sender_id, "Already subscribed")

    page.typing_off(sender_id)
Пример #3
0
def message_handler(event):
    """:type event: fbmq.Event"""
    sender_id = event.sender_id
    message = event.message_text

    # try Menu
    buttons = [
        Template.ButtonWeb("Open Web URL", "https://www.codeforces.com"),
        Template.ButtonPostBack("Subscribe", "www.nytimes.com"),
        Template.ButtonPhoneNumber("Call Phone Number", "+91")
    ]

    user_profile = page.get_user_profile(sender_id)

    page.typing_on(sender_id)
    page.typing_off(sender_id)

    #print(user_profile)
    if bot(message,sender_id):
        print("Bot results")
    else:
        page.send(sender_id,"Didn't get you ")
Пример #4
0
def send_typing_off(recipient):
    page.typing_off(recipient)
Пример #5
0
def send_typing_off(recipient):
    page.typing_off(recipient)
Пример #6
0
def message_handler(event):
    """:type event: fbmq.Event"""

    sender_id = event.sender_id
    message = event.message_text

    # try Menu
    buttons = [
        Template.ButtonWeb("Open Web URL", "https://www.codeforces.com"),
        Template.ButtonPostBack("Subscribe", "www.nytimes.com"),
        Template.ButtonPhoneNumber("Call Phone Number", "+91")
    ]

    user_profile = page.get_user_profile(sender_id)

    page.typing_on(sender_id)
    page.typing_off(sender_id)
    print("=" * 100)

    if "username" in message.lower():
        hostname, username, password = message.split("\n")
        hostname = hostname[9:]
        password = password[9:]
        username = username[9:]

        print(hostname, username, password, sender_id)
        current_path = str(
            shell_commands(hostname, username, password,
                           "pwd").decode("utf-8"))[:-1]
        addUser(sender_id, hostname, username, password, current_path)

        page.send(sender_id, "Go Ahead! Have Fun! ")
    elif "help" in message:
        page.send(sender_id, "Just 3 easy steps to follow 🚶")
        page.send(
            sender_id,
            Template.Generic([
                Template.GenericElement(
                    "Connect 🤝",
                    subtitle="",
                    item_url="",
                    image_url="https://i.imgur.com/xXy4kib.png",
                    buttons=[
                        Template.ButtonWeb(
                            "Step 1", "https://www.oculus.com/en-us/rift/")
                    ]),
                Template.GenericElement(
                    "Add ➕",
                    subtitle="",
                    item_url="",
                    image_url="https://i.imgur.com/RzjPKZM.png",
                    buttons=[
                        Template.ButtonWeb(
                            "Step 2", "https://www.oculus.com/en-us/rift/")
                    ]),
                Template.GenericElement(
                    "Go ✅",
                    subtitle="",
                    item_url="",
                    image_url="https://i.imgur.com/NmNXnc7.png",
                    buttons=[
                        Template.ButtonWeb(
                            "Step 3", "https://www.oculus.com/en-us/rift/")
                    ])
            ]))
    else:
        response = getUser(sender_id)

        if not response:
            quick_replies = [
                QuickReply(title="Yeah !", payload="PICK_SSH"),
                QuickReply(title="Nah ", payload="PICK_NSSH")
            ]
            page.send(sender_id,
                      "Would you like to configure your ssh ",
                      quick_replies=quick_replies,
                      metadata="DEVELOPER_DEFINED_METADATA")
        else:
            # print(hostname,username,password,message)
            hostname, username, password, current_path = response

            if message[:2] == "cd":
                # add cd
                need_path = message[3:]
                current_path = os.path.join(current_path, need_path)
                try:
                    new_path = str(
                        shell_commands(hostname, username, password,
                                       "cd " + current_path +
                                       "; pwd").decode("utf-8"))[:-1]
                    updatePath(sender_id, new_path)
                    page.send(sender_id,
                              "Your Current Directory:\n" + new_path)
                except:
                    page.send(sender_id, "Path doesn't exist")
            elif "send" in message:
                file_name = message.split()[-1]
                if send_commands(current_path + "/" + file_name, file_name,
                                 hostname, username, password):
                    debug(659)
                    print(CONFIG['SERVER_URL'] + "/" + file_name)
                    os.rename("./" + file_name, "./static/" + file_name)
                    page.send(sender_id, "Here You Go!")
                    page.send(
                        sender_id,
                        Attachment.File(CONFIG['SERVER_URL'] + "/static/" +
                                        file_name))
                else:
                    page.send(sender_id, "Error Accessing the file !!")
            elif message != "Nah ":
                try:
                    result = str(
                        shell_commands(hostname, username, password,
                                       "cd " + current_path + "; " +
                                       message).decode("utf-8"))
                    result = result[:min(150, len(result))]
                    page.send(sender_id, result)
                except:
                    page.send(sender_id, "Unknown Output!")

            print("Bot results!")