def lambda_handler(event, context): if 'recordingPath' not in event or not event['recordingPath'] or event['recordingPath'] == 'null': logger.info("No recordingPath in event; returning.") return None # retrieve secrets logger.info("Retrieving cloudfront credentials") session = boto3.session.Session() client = session.client(service_name='secretsmanager') sf_credentials_secrets_manager_arn = get_arg(os.environ, 'SF_CREDENTIALS_SECRETS_MANAGER_ARN') secrets = json.loads(client.get_secret_value(SecretId=sf_credentials_secrets_manager_arn)['SecretString']) private_key = secrets['CloudFrontPrivateKey'] access_key_id = secrets['CloudFrontAccessKeyID'] logger.info("Cloudfront credentials retrieved") # construct url to audio recording recordingPath = event['recordingPath'] # need to remove bucket name, connect dir from path if("/connect/" in recordingPath): recordingPath = "connect/" + recordingPath.split("/connect/", 1)[1] elif("/Analysis/" in recordingPath): recordingPath = "Analysis/" + recordingPath.split("/Analysis/", 1)[1] cloudfront_domain = get_arg(os.environ, 'CLOUDFRONT_DISTRIBUTION_DOMAIN_NAME') url = 'https://' + cloudfront_domain + '/' + recordingPath logger.info('Unsigned audio recording url: %s' % url) # sign url expire_date = datetime.datetime.utcnow() + datetime.timedelta(minutes=60) cloudfront_signer = CloudFrontSigner(access_key_id, rsa_signer(private_key)) signed_url = cloudfront_signer.generate_presigned_url( url, date_less_than=expire_date) logger.info('Signed audio recording url: %s' % signed_url) return signed_url
def __init__(self): session = boto3.session.Session() self.secrets = {} self.secrets_manager_client = session.client( service_name="secretsmanager") self.sf_credentials_secrets_manager_arn = get_arg( os.environ, "SF_CREDENTIALS_SECRETS_MANAGER_ARN") self.__load_credentials() self.version = get_arg(os.environ, "SF_VERSION") self.host = get_arg(os.environ, "SF_HOST") self.username = get_arg(os.environ, "SF_USERNAME") self.login_host = self.host self.request = Request() self.auth_data = { 'grant_type': 'password', 'client_id': self.consumer_key, 'client_secret': self.consumer_secret, 'username': self.username, 'password': self.password } if get_arg(os.environ, "SF_PRODUCTION").lower() == "true": self.set_production()
def createACContactChannelAnalyticsSalesforceObject(contactId, recordingPath): pnamespace = os.environ['SF_ADAPTER_NAMESPACE'] if not pnamespace or pnamespace == '-': logger.info("SF_ADAPTER_NAMESPACE is empty") pnamespace = '' else: pnamespace = pnamespace + "__" sfRequest = {'Details': {'Parameters': {}}} sfRequest['Details']['Parameters']['sf_operation'] = 'create' sfRequest['Details']['Parameters'][ 'sf_object'] = pnamespace + 'AC_ContactChannelAnalytics__c' sfRequest['Details']['Parameters'][pnamespace + 'ContactId__c'] = contactId ACContactChannelAnalyticsId = invokeSfAPI(sfRequest)['Id'] logger.info('SF Object Created, with ID: %s' % ACContactChannelAnalyticsId) #add ACContactChannelAnalyticsId to lock file metadata oMetadata = {} oMetadata['ACContactChannelAnalyticsId'] = ACContactChannelAnalyticsId updateLockMetadata(contactId, oMetadata) if get_arg(os.environ, "INVOKE_MUTE_CALL_RECORDING_LAMBDA_ENABLED") == 'true': arn = get_arg(os.environ, "INVOKE_MUTE_CALL_RECORDING_LAMBDA_ARN") input_params = {'contact_id': contactId} logger.info('calling: %s, contactId=%s' % (arn, contactId)) try: client = boto3.client('lambda') response = client.invoke(FunctionName=arn, InvocationType='RequestResponse', Payload=json.dumps(input_params)) logger.info('response: success') except Exception as e: logger.error('exception: %s' % e) return #attch the call recording file logger.info('Retrieving and attaching call recodring file: %s' % recordingPath) attachFileSaleforceObject('CallRecording.wav', 'audio/wav', 'Call Recording', ACContactChannelAnalyticsId, getBase64fileFromS3(recordingPath)) logger.info('SF Recording Attached') return
def __init__(self): self.__load_credentials() self.version = get_arg(os.environ, "SF_VERSION") self.host = get_arg(os.environ, "SF_HOST") self.username = get_arg(os.environ, "SF_USERNAME") self.login_host = self.host self.request = Request() self.access_token = None self.auth_data = { 'grant_type': 'password', 'client_id': self.consumer_key, 'client_secret': self.consumer_secret, 'username': self.username, 'password': self.password } if get_arg(os.environ, "SF_PRODUCTION").lower() == "true": self.set_production()
def __load_credentials(self): logger.info("Loading credentials") session = boto3.session.Session() client = session.client(service_name="secretsmanager") sf_credentials_secrets_manager_arn = get_arg( os.environ, "SF_CREDENTIALS_SECRETS_MANAGER_ARN") secrets = json.loads( client.get_secret_value( SecretId=sf_credentials_secrets_manager_arn)["SecretString"]) self.password = secrets["Password"] + secrets["AccessToken"] self.consumer_key = secrets["ConsumerKey"] self.consumer_secret = secrets["ConsumerSecret"] logger.info("Credentials Loaded")
def __init__(self): self.version=get_arg(os.environ, "SF_VERSION") self.host=get_arg(os.environ, "SF_HOST") self.consumer_key=get_arg(os.environ, "SF_CONSUMER_KEY") self.consumer_secret=get_arg(os.environ, "SF_CONSUMER_SECRET") self.username=get_arg(os.environ, "SF_USERNAME") self.password=get_arg(os.environ, "SF_PASSWORD") + get_arg(os.environ, "SF_ACCESS_TOKEN") self.login_host = self.host self.request = Request() self.access_token = None self.auth_data = { 'grant_type': 'password', 'client_id': self.consumer_key, 'client_secret': self.consumer_secret, 'username': self.username, 'password': self.password } if get_arg(os.environ, "SF_PRODUCTION").lower() == "true": self.set_production()