Exemplo n.º 1
0
def share_profile(sender, payload):
    if isinstance(payload, str) or isinstance(payload, unicode):
        payload = json.loads(str(payload))
    print("SHAREPROFILE PAYLOAD", payload)

    alias = payload["alias"]
    partner = payload["partner"]

    if payload["ans"] == "y":
        r = requests.get('https://graph.facebook.com/v2.6/' + str(sender), params={
            'fields': 'first_name,last_name,profile_pic',
            'access_token': os.environ.get('ACCESS_TOKEN', config.ACCESS_TOKEN)
        })
        userData = r.json()

        message = TextTemplate(text=alias + " has shared his/her profile with you")
        send_message(message=message.get_message(), id=partner, pause_check=True)
        message = GenericTemplate()
        message.add_element(title=userData["first_name"] + " " + userData["last_name"],image_url=userData["profile_pic"],
                            subtitle="Search on Facebook by the name and recognise by the profile picture")
        send_message(message=message.get_message(), id=partner, pause_check=True)

    else:
        message = TextTemplate(text=alias + " has chosen not to share his/her profile with you")
        send_message(message=message.get_message(), id=partner, pause_check=True)

    show_typing(id=sender, duration=1)
    if sender != ADMIN_ID:
        send_newchat_prompt(id=sender)
    elif usersdb.getSubsValue(id=sender) != "x":
        send_subscription_prompt(id=sender)
Exemplo n.º 2
0
 def handleCommand(self, command, sender):
     text = command.lower().replace(" ", "")
     print("INTERRUPT", text)
     if text == "help":
         send_help(sender)
     elif text == "restart":
         restart_bot(sender)
     elif text == "quit" or text == "exit":
         execute_exit(id=sender)
     elif text == "start" or text == "startchat":
         send_newchat_prompt(id=sender)
     elif text == "profile":
         send_profile_prompt(id=sender)
Exemplo n.º 3
0
def execute_exit(id):
    show_typing(id=id, duration=1)
    print("EXECUTING EXIT")

    if activechatsdb.isActive(id):
        endChat(id)

    elif waitlistdb.isWaiting(id):
        waitlistdb.delist(id)
        message = TextTemplate(text="You have been removed from the waitlist")
        send_message(message=message.get_message(), id=id)

        show_typing(id=id, duration=1)
        send_newchat_prompt(id=id)

    else:
        message = TextTemplate(
            text=
            "You are not in an active chat or in the waitlist. Type \"start\" to start a new chat"
        )
        send_message(message=message.get_message(), id=id)
Exemplo n.º 4
0
def restart_bot(id):
    show_typing(id=id, duration=1)
    print("here")
    if activechatsdb.isActive(id):
        print("ACTIVE", id)
        partner = activechatsdb.get_partner(id)
        activechatsdb.delete_chat_entries(id)
        message = TextTemplate(text="Your active chat has been ended.")
        send_message(message=message.get_message(), id=id)
        message = TextTemplate(
            text="Your active chat has been ended from the other side.")
        send_message(message=message.get_message(), id=partner)

        show_typing(id=partner, duration=1)
        send_newchat_prompt(id=partner)

    if waitlistdb.isWaiting(id):
        waitlistdb.delist(id)
        message = TextTemplate(text="You have been removed from the waitlist")
        send_message(message=message.get_message(), id=id)

    show_typing(id=id, duration=1)
    send_newchat_prompt(id=id)
Exemplo n.º 5
0
def handle_postback(payload, sender):

    if payload not in valid_payloads and json.loads(
            payload)["keyword"] not in valid_payloads:
        message = TextTemplate(text="Not sure if this is a valid command")
        send_message(message.get_message(), id=sender)

    elif payload == "restart":
        interrupts.handleCommand(command="restart", sender=sender)
    elif payload == "help":
        send_help(sender=sender)
    elif payload == "quit":
        interrupts.handleCommand(command="quit", sender=sender)
    elif payload == "getstarted":
        print("GET STARTED DETECTED")
        message = TextTemplate(
            "Hello there, a big welcome to BlindChat. Chat with people all over the "
            +
            "world anonymously. Share your profile only when you want to.\n\n"
            + "We are adding cool new features every single day, so keep " +
            "on exploring. Cheers!\n\nAnd by the way, when in need, type" +
            " \"help\" to see the list of available commands")
        send_message(message.get_message(), id=sender)
        send_newchat_prompt(id=sender)
Exemplo n.º 6
0
def endChat(sender):

    try:
        partner = activechatsdb.get_partner(sender)
        alias1 = activechatsdb.get_alias(sender)
        alias2 = activechatsdb.get_alias(partner)
    except:
        message = TextTemplate(
            text="No open chat was found which can be closed")
        send_message(message.get_message(), id=sender)
        show_typing(id=sender, duration=2)
        send_newchat_prompt(id=sender)
        return

    imurl = APP_URL + "static/endchat1.jpg/"

    # -------------------------- SENDER --------------------------- #

    replies_sender = [{
        "title":
        "Share profile",
        "payload":
        json.dumps({
            "keyword": "profile_share",
            "ans": "y",
            "alias": alias1,
            "partner": partner
        })
    }, {
        "title":
        "Don't share",
        "payload":
        json.dumps({
            "keyword": "profile_share",
            "ans": "n",
            "alias": alias1,
            "partner": partner
        })
    }]

    message = GenericTemplate()
    title = "You have ended the chat with " + alias2
    subtitle = "Hope you had a nice experience."
    message.add_element(title=title, subtitle=subtitle, image_url=imurl)
    send_message(message=message.get_message(), id=sender)

    message = TextTemplate(text="Would you like to share your profile with " +
                           alias2 + "?").get_message()
    message = add_quick_reply(message,
                              title=replies_sender[0]["title"],
                              payload=replies_sender[0]["payload"])
    message = add_quick_reply(message,
                              title=replies_sender[1]["title"],
                              payload=replies_sender[1]["payload"])
    send_message(message=message, id=sender)

    # ----------------------------------------------------------------------- #

    # ------------------------------- PARTNER ------------------------------- #

    replies_partner = [{
        "title":
        "Share profile",
        "payload":
        json.dumps({
            "keyword": "profile_share",
            "ans": "y",
            "alias": alias2,
            "partner": sender
        })
    }, {
        "title":
        "Don't share",
        "payload":
        json.dumps({
            "keyword": "profile_share",
            "ans": "n",
            "alias": alias2,
            "partner": sender
        })
    }]

    message = GenericTemplate()
    title = alias1 + " has quit the chat"
    subtitle = "Hope you had a nice experience while it lasted."
    message.add_element(title=title, subtitle=subtitle, image_url=imurl)
    send_message(message=message.get_message(), id=partner, pause_check=True)

    message = TextTemplate(text="Would you like to share your profile with " +
                           alias1 + "?").get_message()
    message = add_quick_reply(message,
                              title=replies_partner[0]["title"],
                              payload=replies_partner[0]["payload"])
    message = add_quick_reply(message,
                              title=replies_partner[1]["title"],
                              payload=replies_partner[1]["payload"])
    send_message(message=message, id=partner, pause_check=True)

    # --------------------------------------------------------------- #

    try:
        activechatsdb.delete_chat_entries(user=sender)
    except Exception, e:
        print("ENDCHAT ERROR", str(e))