def lambda_handler()

in src/smaLambda/callForwardingSMA.py [0:0]


def lambda_handler(event, context):

    # Extract all the elements from the event that we will need for processing
    event_type = event['InvocationEventType']
    participants = event['CallDetails']['Participants']
    call_id = participants[0]['CallId']
    to_number = participants[0]['To']
    from_number = participants[0]['From']

    # For consistent and detail logging, set a prefix format that can be used by all functions
    global log_prefix
    log_prefix = 'Call-ID:{} {} From:[{}] To:[{}]: '.format(call_id, event_type, from_number, to_number)

    if event_type == 'NEW_INBOUND_CALL':
        logger.info('RECV {} {}'.format(log_prefix, 'New inbound call initiated'))
        return new_call_handler(call_id, to_number)

    elif event_type == 'HANGUP':
        logger.info('RECV {} {}'.format(log_prefix, 'Hangup event received'))
        return hangup_handler(participants)

    elif event_type == 'RINGING':
        logger.info('RECV {} {}'.format(log_prefix, 'Ringing event received'))
        return ()

    elif event_type == 'ACTION_SUCCESSFUL':
        return action_success_handler(event)

    elif event_type == 'ACTION_FAILED':
        logger.error('RECV {} {} {} {}'.format(log_prefix, event['ActionData']['ErrorType'], event['ActionData']['ErrorMessage'], json.dumps(event)))
        return unable_to_connect(call_id)

    elif event_type == 'INVALID_LAMBDA_RESPONSE':
        logger.error('RECV {} : {} : {} : {}'.format(log_prefix, event['ErrorType'], event['ErrorMessage'], json.dumps(event)))
        return unable_to_connect(call_id)

    else:
        logger.error('RECV {} [Unhandled event] {}'.format(log_prefix, json.dumps(event)))
        return unable_to_connect(call_id)