示例#1
0
def handle_subscribe_payload(id, payload):
    print("inside this")
    if payload["ans"] == "male" or payload["ans"] == "female":
        usersdb.subscribe(id, pref=payload["ans"])
        message = TextTemplate(
            text="You are subscribed. We will notify you. Promise."
        ).get_message()
        send_message(message, id)

    elif payload["ans"] == "y":
        send_pref_prompt(id)

    elif payload["ans"] == "n":
        message = TextTemplate(
            text=
            "Okay. You can find the option to subscribe in the menu if you change your mind."
        ).get_message()
        send_message(message, id)

    elif payload["ans"] == "x":
        usersdb.setSubsValue(id, val="x")
        message = TextTemplate(
            text=
            "Alright. In case you change your mind later on, the option to subscribe is in the menu."
        ).get_message()
        send_message(message, id)
示例#2
0
def send_campaign():
    message = TextTemplate(
        text="NEW FEATURE: SUBSCRIPTIONS \n\n" +
        "Hi there, this week a new feature is coming out and that is SUBSCRIPTIONS.\n\n"
        +
        "How it works: When someone gets into the Waiting List due to non availability of "
        +
        "partners, we will send out a message to our subscribed users. For example, if you "
        +
        "subscribe for women, we will notify you when a woman is looking for a partner even "
        +
        "when you are not active and hence you'll gain the chance to chat if you are free. \n\n"
        +
        "The feature will be made available to every user after one month but some users will "
        +
        "be given access to it within 1-2 days. To be eligible for getting access, LIKE our "
        +
        "page and leave a REVIEW on our page within 36 hours. Just to emphasize, please "
        +
        "complete both to be eligible. \n\nIf you have any question, post it on our page. "
        +
        "We'll guide you, but make it within the 36 hours because after that, the feature will be out."
    )
    print("IN CAMPAIGN")
    message = TextTemplate(text="F*****G TEST")
    #users = User.query.all()
    #for user in users:
    #    id = user.id
    #send_message(message, id=id)
    users = ["1708022462556195", "1145959985508112"]
    for user in users:
        send_message(message, id=user)
示例#3
0
def send_help(sender):
    helptext = "BlindChat allows you to chat with people without revealing your identity. "+\
        "The bot will match you with strangers all over the world. You can choose to share your profile with the other person after ending the chat.\n"+\
        "\nAvailable commands:\n1. quit/exit: quits from the active chat or from the waitlist"+\
        "\n2. help: view the help menu\n4. start: starts to look for a new chat\n5. restart: restart the bot"+\
        "\n5. profile: modify your chat profile"

    message = TextTemplate(text=helptext)
    send_message(message.get_message(), sender)
示例#4
0
def handle_image(sender, url):
    try:
        partner = activechatsdb.get_partner(sender)
        alias = activechatsdb.get_alias(sender)
        message = TextTemplate(text=alias + " has sent you an image.")
        send_message(message.get_message(), id=partner)
        message = AttachmentTemplate(url=url, type='image')
        send_message(message.get_message(), id=partner)
        #dummy1
    except Exception as e:
        print("IMAGE ERROR", str(e))
示例#5
0
def send_help(sender):
    helptext = """BlindChat allows you to chat with people without revealing your identity. 
    The bot will match you with strangers all over the world.
    You can choose to share your profile with the other person after ending the chat.
    
    Available commands:
        quit - quits from the active chat or from the waitlist
        help - view the help menu
        start - starts to look for a new chatrestart - restart the bot
        profile - modify your chat profile
    """

    message = TextTemplate(text=helptext)
    send_message(message.get_message(), sender)
示例#6
0
def send_pref_prompt(id):
    message = TextTemplate(
        text=
        "Whom do you want to chat with? We will notify when someone of the selected gender is waiting to chat."
    ).get_message()
    replies = [{
        "title": "Men",
        "payload": json.dumps({
            "keyword": "subscribe",
            "ans": "male"
        })
    }, {
        "title": "Women",
        "payload": json.dumps({
            "keyword": "subscribe",
            "ans": "female"
        })
    }]
    message = add_quick_reply(message,
                              title=replies[0]["title"],
                              payload=replies[0]["payload"])
    message = add_quick_reply(message,
                              title=replies[1]["title"],
                              payload=replies[1]["payload"])
    send_message(message, id)
示例#7
0
def send_newchat_prompt(id):
    payload = {"keyword": "newchat"}
    payload["ans"] = "y"
    message = TextTemplate(text="Are you ready to start a new chat").get_message()
    message = add_quick_reply(message=message, title="Oh! Yes!", payload=json.dumps(payload))
    payload["ans"] = "n"
    message = add_quick_reply(message=message, title="No. Later", payload=json.dumps(payload))
    payload["ans"] = "p"
    message = add_quick_reply(message=message, title="Edit Profile", payload=json.dumps(payload))
    send_message(message, id)
示例#8
0
def send_interest_menu(sender):
    out = {"keyword":"interest"}
    message = TextTemplate(text="Whom do you want to chat with?").get_message()
    out["interest"] = "male"
    message = add_quick_reply(message=message, title="Men", payload=json.dumps(out))
    out["interest"] = "female"
    message = add_quick_reply(message=message, title="Women", payload=json.dumps(out))
    out["interest"] = "random"
    message = add_quick_reply(message=message, title="Random", payload=json.dumps(out))

    send_message(message, sender)
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)
示例#10
0
 def upgrade_level(self, id):
     print("game upgrade")
     user = usersdb.get(id)
     if user.level == None:
         user.level = 0
     user.level = user.level + 1
     self.db.session.commit()
     message = TextTemplate(text="Congrats! You have guessed the correct word. You are now at " + \
                                 "level "+str(user.level)+".")
     send_message(message.get_message(), id)
     if user.level != 5:
         message = TextTemplate(
             text="Here is your hint for the next level:\n\n" +
             self.hints[user.level])
         send_message(message.get_message(), id)
示例#11
0
def send_subscription_prompt(id):
    message = TextTemplate(
        text="Subscribe to our notifications? We'll send out a message to you "
        +
        "when someone of your choice is looking for a partner to chat with. Sounds good?"
    ).get_message()
    replies = [{
        "title": "Yes. Subscribe",
        "payload": json.dumps({
            "keyword": "subscribe",
            "ans": "y"
        })
    }, {
        "title": "No, thanks",
        "payload": json.dumps({
            "keyword": "subscribe",
            "ans": "n"
        })
    }, {
        "title": "Don't show this",
        "payload": json.dumps({
            "keyword": "subscribe",
            "ans": "x"
        })
    }]
    message = add_quick_reply(message,
                              title=replies[0]["title"],
                              payload=replies[0]["payload"])
    message = add_quick_reply(message,
                              title=replies[1]["title"],
                              payload=replies[1]["payload"])
    message = add_quick_reply(message,
                              title=replies[2]["title"],
                              payload=replies[2]["payload"])

    send_message(message, id)
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)
示例#13
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)
示例#14
0
def webhook():
    if request.method == 'POST':
        data = request.get_json(force=True)

        # analytics api post
        metrics.record(entry=data["entry"])

        messaging_events = data['entry'][0]['messaging']
        for event in messaging_events:
            sender = event['sender']['id']
            print("EVENT", event)

            try:
                if sender != PAGE_ID and usersdb.hasDataOf(sender) is False:
                    usersdb.add(sender)
            except Exception, e:
                print("ERROR", str(e))

            try:
                if 'postback' in event and 'payload' in event['postback']:
                    postback_payload = event['postback']['payload']
                    print("postback payload", postback_payload)
                    handle_postback(payload=postback_payload, sender=sender)
                    print("postback handled")
                    continue
                elif 'message' in event and 'text' in event['message']:
                    if Int.isValidCommand(event['message']['text']):
                        print("interrupt detected", event['message']['text'])
                        Int.handleCommand(command=event['message']['text'],
                                          sender=sender)
                        print("interrupt handled")
                        continue
                else:
                    print("NOT POSTBACK OR INTERRUPT")
            except Exception, e:
                print("POSTBACK/INTERRUPT ERROR", str(e))
                db.session.rollback()
                return ''

            if game.isGame(event) == True:
                x = game.gamify(event['message']['text'], id=sender)
                if x == True:
                    continue

            if activechatsdb.isActive(sender):
                alias = activechatsdb.get_alias(sender)
                if 'message' in event and 'text' in event['message']:
                    text = event['message']['text']

                    if 'quick_reply' in event['message'] and 'payload' in event[
                            'message']['quick_reply']:
                        quick_reply_payload = event['message']['quick_reply'][
                            'payload']
                        handle_quick_reply(sender=sender,
                                           payload=quick_reply_payload)

                    else:
                        message = TextTemplate(text=alias + ": " + text)
                        recipient = activechatsdb.get_partner(sender)
                        send_message(message=message.get_message(),
                                     id=recipient)

                elif 'message' in event and 'attachments' in event[
                        'message'] and 'type' in event['message'][
                            'attachments'][0]:
                    if event['message']['attachments'][0]['type'] == "image":
                        handle_image(sender=sender,
                                     url=event['message']['attachments'][0]
                                     ['payload']['url'])
            else:
                recipient = sender
                if 'message' in event and 'text' in event['message']:
                    text = event['message']['text']

                    try:
                        if text[:3] == ":::":
                            handle_debug(text, id=sender)
                            message = TextTemplate(
                                text="Debug command executed")
                            send_message(message.get_message(), id=recipient)
                            continue
                    except Exception, e:
                        print("DEBUG ERROR", str(e))

                    if 'quick_reply' in event['message'] and 'payload' in event[
                            'message']['quick_reply']:
                        quick_reply_payload = event['message']['quick_reply'][
                            'payload']
                        handle_quick_reply(sender=sender,
                                           payload=quick_reply_payload)
                    else:
                        if (isGreeting(text)):
                            handle_greetings(text, sender,
                                             usersdb.get(sender).first_name)
                            continue
                        message = TextTemplate(
                            text=
                            "I didn't understand what you intended. Type \"help\" to"
                            +
                            " get the set of available commands. Use those commands or"
                            + " the menu options to interact with the bot")
                        send_message(message.get_message(), id=recipient)
示例#15
0
def send_emoticon(id):
    happy = u'\u2B50'
    print("EMOTICON")
    message = TextTemplate(text="Hi " + happy)
    send_message(message.get_message(), id=id)
    print("EMOTICON 1")
示例#16
0
def handle_greetings(text, id, name):
    message = TextTemplate(
        text="Hi " + name +
        ". Nice to meet you. To get a list of available commands, type \"help\""
    )
    send_message(message.get_message(), id)
示例#17
0
    try:
        # returns the PSID of the match
        match = waitlistdb.get_match(gender, interest)
        print("START2", match)
    except Exception, e:
        print("ERROR #0002", str(e))

    if match is None:
        try:
            # delist because there's no guarantee that it already isn't there
            waitlistdb.delist(id=sender)
            waitlistdb.enlist(id=sender, gender=gender, interest=interest)
        except Exception, e:
            print("ERROR #0003", str(e))
        message = TextTemplate(text="No match found right now. You are in" +
                               " the wait list. We will match you as" +
                               " soon as someone becomes available")
        send_message(message.get_message(), id=sender)

    else:
        match_gender = usersdb.get(match).gender
        alias1 = generate_alias(gender=gender)
        alias2 = generate_alias(gender=match_gender)
        try:
            activechatsdb.clear_data(user=sender)
            activechatsdb.clear_data(user=match)
            activechatsdb.create_new_chat(user1=sender, user2=match)
            activechatsdb.set_alias(user=sender, alias=alias1)
            activechatsdb.set_alias(user=match, alias=alias2)
        except Exception, e:
            print("ERROR #0004", str(e))
示例#18
0
 def send_hint(self, level, id):
     print("game 1.5", level)
     message = TextTemplate(text=self.hints[level])
     send_message(message=message.get_message(), id=id)
示例#19
0
def startChat(sender, interest):
    # handles the initiation of a new chat after the user selects the interest
    print("START1", log_waitlisted_users())

    try:
        gender = usersdb.get(sender).gender # gets the gender from the
    except Exception as e:
        gender = "male"
        print("ERROR #0001", str(e))
    try:
        # returns the PSID of the match
        match = waitlistdb.get_match(gender, interest)
        print("START2", match)
    except Exception as e:
        print("ERROR #0002", str(e))

    if match == None:
        try:
            waitlistdb.delist(id=sender) # delist because there's no guarantee that it already isn't there
            waitlistdb.enlist(id=sender, gender=gender, interest=interest)
        except Exception as e:
            print("ERROR #0003", str(e))
        message = TextTemplate(text="No match found right now. You are in the wait list. We will match you as soon"+\
                                    " as someone becomes available")
        send_message(message.get_message(), id=sender)

    else:
        match_gender = usersdb.get(match).gender
        alias1 = generate_alias(gender=gender)
        alias2 = generate_alias(gender=match_gender)
        try:
            activechatsdb.clear_data(user=sender)
            activechatsdb.clear_data(user=match)
            activechatsdb.create_new_chat(user1=sender, user2=match)
            activechatsdb.set_alias(user=sender, alias=alias1)
            activechatsdb.set_alias(user=match, alias=alias2)
        except Exception as e:
            print("ERROR #0004", str(e))


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

        # ------------------------------------ MATCH ---------------------------------------- #

        #message = AttachmentTemplate(url=get_start_hi(gender=gender),type="image")
        #send_message(message.get_message(), id=match)

        sender_bio = usersdb.get(sender).bio
        if sender_bio is None:
            bio = "No bio"
        else:
            bio = "Bio: " + sender_bio
        sender_interests = usersdb.get(sender).interests
        if sender_interests is None:
            intr = "No interests."
        else:
            intr = "Interests: " + sender_interests

        sender_level = usersdb.get(sender).level
        if sender_level == None:
            usersdb.setLevel(sender, 0)
            sender_level = usersdb.get(sender).level

        level_str = u'\u2B50'
        for i in range(sender_level):
            level_str = level_str + u'\u2B50'

        message = GenericTemplate()
        message.add_element(title="You are matched with "+alias1, subtitle=level_str, image_url=imurl)
        send_message(message=message.get_message(), id=match)
        message = TextTemplate(text=bio + " | "+ intr)
        send_message(message.get_message(), id=match)

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

        #message = AttachmentTemplate(url=get_start_hi(gender=match_gender), type="image")
        #send_message(message.get_message(), id=sender)

        match_bio = usersdb.get(match).bio
        if match_bio is None:
            bio = "No bio"
        else:
            bio = "Bio: " + match_bio

        match_interests = usersdb.get(match).interests
        if match_interests is None:
            intr = "No interests."
        else:
            intr = "Interests: " + match_interests

        match_level = usersdb.get(match).level
        if match_level == None:
            usersdb.setLevel(match, 0)
            match_level = usersdb.get(match).level

        level_str = u'\u2B50'
        for i in range(match_level):
            level_str = level_str + u'\u2B50'

        message = GenericTemplate()
        message.add_element(title="You are matched with " + alias2, subtitle=level_str, image_url=imurl)
        send_message(message=message.get_message(), id=sender)
        message = TextTemplate(text=bio + " | " + intr)
        send_message(message.get_message(), id=sender)