Beispiel #1
0
def old_process_bot_input_command(room_id, command, headers, bot_name):
    """ 
        Provides a few different command options based in different lists. (commands should be lower case)
        Combines all lists together and checks if any keyword commands are detected...basically a manually created case/switch statement
        For each possible command, do something
        Is there an easier way to do this?
    """
    ss_client = ss_get_client(os.environ['SMARTSHEET_TOKEN'])
    state_filter = []
    arch_filter = []
    mobile_filter = False
    url_filter = False
    data = []

    command_list = [("events", ['event', 'events', '-e']),
                    ("mobile", ['mobile', 'phone', '-m']),
                    ("filter", ['filter', '-f']), ("url_test", ['url', '-u'])
                    #("command alias",["list of possible command entries"])
                    ]
    result = command_parse(command_list, command)
    ##looks like: {"event":"TX FL AL","filter":"sec dc","mobile":""}
    if result:
        if "events" in result:
            print(f"made it to events:  {result['events']}")
            state_filter = process_state_codes(
                result['events'].upper().split(" "), reverse=False)
        if "filter" in result:
            print(f"made it to filter:  {result['filter']}")
            arch_filter = process_arch_filter(result['filter'])
        if "mobile" in result:
            print(f"made it to mobile:  {result['mobile']}")
            mobile_filter = True
        if "url_test" in result:
            print(f"made it to url_test:  {result['url_test']}")
            url_filter = True

        data = get_all_data_and_filter(ss_client, EVENT_SMARTSHEET_ID,
                                       state_filter, arch_filter, url_filter,
                                       NO_COLUMN_FILTER)
        communicate_to_user(ss_client,
                            room_id,
                            headers,
                            bot_name,
                            data,
                            state_filter,
                            arch_filter,
                            mobile_filter,
                            url_filter,
                            help=False)
    else:
        communicate_to_user(ss_client,
                            room_id,
                            headers,
                            bot_name,
                            data,
                            state_filter,
                            arch_filter,
                            mobile_filter,
                            url_filter,
                            help=True)
Beispiel #2
0
def hello(body):
    """
        Test bot for new features.
    """
    email = TEST_EMAIL
    headers = TEST_HEADERS
    name = TEST_NAME
    #print(f"GOT {type(body)}: {repr(body)}")
    resource = body["resource"]
    bot_event = body["event"]
    print(f'Resource = {resource}    Event = {bot_event}')
    if resource == "attachmentActions":
        card_id = body["data"]["messageId"]
        app_id = body["appId"]
        actor_id = body["actorId"]
        data_id = body["data"]["id"]
        person_id = body["data"]["personId"]
        room_id = body["data"]["roomId"]
        identity = get_person_from_id(person_id, headers)
        card_inputs = get_card_msg(data_id, headers)
        process_card_inputs(room_id, card_inputs, card_id, headers, name)
        print(f"{card_inputs}")
        #create_card(room_id,headers)

    elif resource == "messages":
        room_id = body["data"]["roomId"]
        identity = body["data"]["personEmail"]
        text = body["data"]["id"]
        print("hugtest sees POST from {}".format(identity))
        if identity != email:
            print("{}-----{}".format(identity, email))
            #command = get_msg_sent_to_bot(text).lower()
            command = get_msg_sent_to_bot(text, headers)
            command = (command.replace(name, '')).strip()
            command = (command.replace('@', '')).strip()
            command = command.lower(
            )  #added this, don't forget to move to events-bot as well
            print("stripped command: {}".format(command))
            process_bot_input_command(room_id, command, headers, name)
            #send_log_to_ss(name,str(datetime.now()),identity,command,room_id)
    elif resource == "memberships":
        room_id = body["data"]["roomId"]
        identity = body["data"]["personEmail"]
        print(f'made it to memberships identity={identity}')
        if bot_event == "created" and identity == email:
            print("made it to if")
            create_card(ss_get_client(os.environ['SMARTSHEET_TOKEN']), room_id,
                        headers)
    print("Done processing webhook")
Beispiel #3
0
def process_card_inputs(room_id, result, card_id, headers, bot_name):
    msg_ids_list = []
    msg_ids_list.append(card_id)

    msg_ids_list = msg_ids_list + result["old_msg_ids"].split(",")
    state_filter = []
    arch_filter = []
    mobile_filter = False
    url_filter = False
    data = []
    remove_old_msgs(room_id, msg_ids_list, headers)
    ss_client = ss_get_client(os.environ['SMARTSHEET_TOKEN'])
    if "create" in result["button_choice"]:
        create_card(ss_client, room_id, headers)
    else:
        string = result['state_code']
        #use sanitize string function for this
        string = string.replace('\xa0', '')  #an artifact from WebEx sometimes
        string = string.replace(',', ' ')  #replace commas with spaces
        string = ' '.join([w for w in string.split() if len(w) > 1
                           ])  #remove all characters of length of 1
        #print(string)
        state_filter = process_state_codes(string.upper().split(" "),
                                           reverse=False)
        #print(state_filter)
        if result['filter_flag']:
            arch_filter.append(result['filter_flag'])

        data = get_all_data_and_filter(ss_client, EVENT_SMARTSHEET_ID,
                                       state_filter, arch_filter, url_filter,
                                       NO_COLUMN_FILTER)
        #print(data)
        msg_ids_list = []
        msg_ids_list = communicate_to_user(ss_client,
                                           room_id,
                                           headers,
                                           bot_name,
                                           data,
                                           state_filter,
                                           help=False)
        create_rerun_card(room_id, result, headers, msg_ids_list)
Beispiel #4
0
def process_bot_input_command(room_id, command, headers, bot_name):
    """ 
        Provides a few different command options based in different lists. (commands should be lower case)
        Combines all lists together and checks if any keyword commands are detected...basically a manually created case/switch statement
        For each possible command, do something
        Is there an easier way to do this?
    """
    ss_client = ss_get_client(os.environ['SMARTSHEET_TOKEN'])
    state_filter = []
    arch_filter = []
    mobile_filter = False
    url_filter = False
    data = []

    #create a function to display who uses the bot the most (grab logs, count usage and return)
    command_list = [("events", ['event', 'events', '-e']),
                    ("mobile", ['mobile', 'phone', '-m']),
                    ("filter", ['filter', '-f']), ("url_test", ['url', '-u']),
                    ("test", ['test', '-t']), ("stats", ['stats', '-s'])
                    #("command alias",["list of possible command entries"])
                    ]
    result = command_parse(command_list, command)
    ##looks like: {"event":"TX FL AL","filter":"sec dc","mobile":""}
    if result:
        if "events" in result:
            print(f"made it to events:  {result['events']}")
            state_filter = process_state_codes(
                result['events'].upper().split(" "), reverse=False)
        if "filter" in result:
            print(f"made it to filter:  {result['filter']}")
            arch_filter = process_arch_filter(result['filter'])
        if "mobile" in result:
            print(f"made it to mobile:  {result['mobile']}")
            mobile_filter = True
        if "url_test" in result:
            print(f"made it to url_test:  {result['url_test']}")
            url_filter = True
        if "stats" in result:
            print(f"made it to stats:  {result['stats']}")
            msg = get_logs_from_ss(ss_client)
            i = 6000
            while len(msg) > i:
                bot_post_to_room(room_id, msg[:i], headers)
                msg = msg[i:]
            bot_post_to_room(room_id, msg, headers)
            return
        if "test" in result:
            print(f"made it to test:  {result['test']}")
            create_card(ss_client, room_id, headers)
            return
        data = get_all_data_and_filter(ss_client, EVENT_SMARTSHEET_ID,
                                       state_filter, arch_filter, url_filter,
                                       NO_COLUMN_FILTER)
        communicate_to_user(ss_client,
                            room_id,
                            headers,
                            bot_name,
                            data,
                            state_filter,
                            help=False)
        bot_post_to_room(
            room_id,
            f"If on Desktop: Try the new Events Form.  \nType '@{bot_name} help' to get started",
            headers)
    else:
        communicate_to_user(ss_client,
                            room_id,
                            headers,
                            bot_name,
                            data,
                            state_filter,
                            help=True)
        #create_card(room_id,headers)
        return
Beispiel #5
0
def events(body):
    """
        Production for EVENTS-TBD bot
        Takes the webhook data <body> and parses out the sender and the message
        Must filter out all messages sent by bot as those come back as part of webhook
        Strips the command of the botname, and then sends the command to take action
        Finally, we log the interaction in smartsheets

        Future: regex search identity for domain verification
    """
    email = EVENTS_EMAIL
    headers = EVENTS_HEADERS
    name = EVENTS_NAME
    print(f"GOT {type(body)}: {repr(body)}")
    resource = body["resource"]
    bot_event = body["event"]
    print(f'Resource = {resource}    Event = {bot_event}')
    if resource == "attachmentActions":
        card_id = body["data"]["messageId"]
        app_id = body["appId"]
        actor_id = body["actorId"]
        data_id = body["data"]["id"]
        person_id = body["data"]["personId"]
        room_id = body["data"]["roomId"]
        identity = get_person_from_id(person_id, headers)
        card_inputs = get_card_msg(data_id, headers)
        process_card_inputs(room_id, card_inputs, card_id, headers, name)
        print(f"{card_inputs}")
        send_log_to_ss(name, str(datetime.now()), identity,
                       f"card processed: {card_inputs['state_code']}", room_id)
        #create_card(room_id,headers)

    elif resource == "messages":
        room_id = body["data"]["roomId"]
        identity = body["data"]["personEmail"]
        text = body["data"]["id"]
        print("Events-tbd sees POST from {}".format(identity))
        if identity != email:
            print("{}-----{}".format(identity, email))
            #command = get_msg_sent_to_bot(text).lower()
            command = get_msg_sent_to_bot(text, headers)
            command = (command.replace(name, '')).strip()
            command = (command.replace('@', '')).strip()
            command = command.lower(
            )  #added this, don't forget to move to events-bot as well
            print("stripped command: {}".format(command))
            process_bot_input_command(room_id, command, headers, name)
            send_log_to_ss(name, str(datetime.now()), identity, command,
                           room_id)
    elif resource == "memberships":
        room_id = body["data"]["roomId"]
        identity = body["data"]["personEmail"]
        print(f'made it to memberships identity={identity}')
        if bot_event == "created" and identity == email:
            print("made it to if")
            create_card(ss_get_client(os.environ['SMARTSHEET_TOKEN']), room_id,
                        headers)
            send_log_to_ss(name, str(datetime.now()), identity,
                           "new room: card created", room_id)
    print("Done processing webhook")
    '''