Exemplo n.º 1
0
def start_help_handler(message):
    dynamodb = boto3.resource('dynamodb', region_name="us-east-1")
    table = dynamodb.Table(get_current_event())

    response = table.query(
        KeyConditionExpression=Key('number').eq(message['From']))

    name = ""

    # On the off chance we have someone who isn't registered at the event but still needs help.
    if response['Count'] == 0:
        table.put_item(
            Item={
                'number': message['From'],
                'name': name,
                'arrived': get_arrival_time(),
                'help_flag': True,
                'help_flag_raised': get_arrival_time()
            })
    else:
        name = response['Items'][0]['name']
        table.put_item(
            Item={
                'number': response['Items'][0]['number'],
                'name': response['Items'][0]['name'],
                'arrived': response['Items'][0]['arrived'],
                'help_flag': True,
                'help_flag_raised': get_arrival_time()
            })

    SMSHandler.sendsms(message['From'], immediate_help_message())
    notify_parties(name, message['From'])
    SMSHandler.sendsms(message['From'], whats_next_message())
Exemplo n.º 2
0
def notify_parties(name, number, message="nomessage"):
    if message == "nomessage":
        # SMSHandler.send_sms_exec(alert_message(name, number))
        # SMSHandler.send_sms_soberbros(alert_message(name, number))
        SMSHandler.sendsms("+17085578202", alert_message(name, number))
    else:
        # SMSHandler.send_sms_exec("Message from " + name + " (" + number + "): " + process_message(message))
        # SMSHandler.send_sms_soberbros("Message from " + name + " (" + number + "): " + process_message(message))
        SMSHandler.sendsms("+17085578202", alert_message(name, number))
Exemplo n.º 3
0
def handler(data):
    data['body'] = data['body'].encode()

    # We have to decode the message as its sent in base 64.
    message_parsed = (base64.b64decode(data['body']))
    message_parsed = message_parsed.decode().split('&')

    message = dictify_message(message_parsed)
    current_event = get_current_event()

    # No event going on rn.
    if current_event == "none":
        SMSHandler.sendsms(message['From'], no_event_message())
        return "200 OK"
    else:
        # Trigger for help flag raising.
        if message['Body'].lower().find('help') != -1:
            start_help_handler(message)
            return "200 OK"

        dynamodb = boto3.resource('dynamodb', region_name="us-east-1")
        table = dynamodb.Table(current_event)

        response = table.query(
            KeyConditionExpression=Key('number').eq(message['From']))

        # If the number exists in our db and their flag is raised, let's forward their messages
        if response['Count'] != 0 and response['Items'][0]['help_flag']:
            notify_parties(response['Items'][0]['name'], message['Body'])
            SMSHandler.sendsms(response['Items'][0]['number'],
                               "Successfully forwarded.")
            return "200 OK"

        # If the sender didn't have the keyword correct.
        if get_keyword() != "none":
            if not validate_keyword(message['Body']):
                SMSHandler.sendsms(message['From'],
                                   incorrect_keyword_message())
                return "200 OK"

        # Ensuring the number doesn't exist in the DB yet.
        if response['Count'] == 0:
            SMSHandler.sendsms(message['From'],
                               welcome_number_message(message['Body']))

            table.put_item(
                Item={
                    'number': message['From'],
                    'name': get_name(message['Body']),
                    'arrived': get_arrival_time(),
                    'help_flag': False,
                    'help_flag_raised': "n/a"
                })

            current_guests = increment_guests(current_event)

            # Number of people attending the event.
            if current_guests % 50 == 0:
                wooglin.sendmessage("The current event: " + current_event +
                                    " has " + str(current_guests) +
                                    " guests registered.")

        else:
            SMSHandler.sendsms(message['From'], number_exists_message())
            return "200 OK"