diff --git a/sam-app/lambda_functions/lambda_layers.zip b/sam-app/lambda_functions/lambda_layers.zip index bf01fa3..c93f495 100644 Binary files a/sam-app/lambda_functions/lambda_layers.zip and b/sam-app/lambda_functions/lambda_layers.zip differ diff --git a/sam-app/lambda_functions/sfInvokeAPI.py b/sam-app/lambda_functions/sfInvokeAPI.py index 8209493..848b27c 100644 --- a/sam-app/lambda_functions/sfInvokeAPI.py +++ b/sam-app/lambda_functions/sfInvokeAPI.py @@ -75,6 +75,10 @@ def lambda_handler(event, context): resp = search(sf=sf, **event['Details']['Parameters']) elif (sf_operation == "searchOne"): resp = searchOne(sf=sf, **event['Details']['Parameters']) + elif (sf_operation == "searchSOSL"): + resp = searchSOSL(sf=sf, **event['Details']['Parameters']) + elif (sf_operation == "searchOneSOSL"): + resp = searchOneSOSL(sf=sf, **event['Details']['Parameters']) else: msg = "sf_operation unknown" logger.error(msg) @@ -268,6 +272,38 @@ def searchOne(sf, q, sf_fields, sf_object, where="", **kwargs): result['sf_count'] = count return result +def searchSOSL(sf, query, **kwargs): + for key, value in kwargs.items(): + logger.info("Replacing [%s] with [%s] in [%s]" % (key, value, query)) + query = query.replace(key, value) + + records = sf.search(query=query) + count = len(records) + result = {} + + if count > 0: + recordArray = {} + for record in records: + recordArray[str(records.index(record))] = flatten_json(record) + + result['sf_records'] = recordArray + else: + result['sf_records'] = {} + + result['sf_count'] = count + return flatten_json(result, '_') + +def searchOneSOSL(sf, query, **kwargs): + for key, value in kwargs.items(): + logger.info("Replacing [%s] with [%s] in [%s]" % (key, value, query)) + query = query.replace(key, value) + + records = sf.query(query=query) + count = len(records) + result = flatten_json(records[0]) if count == 1 else {} + result['sf_count'] = count + return result + def flatten_json(nested_json, separator = '.'): out = {} diff --git a/sam-app/lambda_functions/sfProcessContactLens.py b/sam-app/lambda_functions/sfProcessContactLens.py index 0199773..851991b 100644 --- a/sam-app/lambda_functions/sfProcessContactLens.py +++ b/sam-app/lambda_functions/sfProcessContactLens.py @@ -66,11 +66,14 @@ def lambda_handler(event, context): return {"Done": False} logger.info('Getting lock file metadata: %s ' % contactId) - oMetadata = getS3FileMetadata(os.environ['TRANSCRIPTS_DESTINATION'], contactId) - mACContactChannelAnalyticsId = None - if 'ACContactChannelAnalyticsId'.lower() in oMetadata: - mACContactChannelAnalyticsId = oMetadata['ACContactChannelAnalyticsId'.lower()] + oMetadata = None + transcribeBucketExists = os.environ['TRANSCRIPTS_DESTINATION'] != '' + if transcribeBucketExists: + oMetadata = getS3FileMetadata(os.environ['TRANSCRIPTS_DESTINATION'], contactId) + + if 'ACContactChannelAnalyticsId'.lower() in oMetadata: + mACContactChannelAnalyticsId = oMetadata['ACContactChannelAnalyticsId'.lower()] logger.info('Processing ContactLens transcript') participants = contactLensObj['Participants'] @@ -85,8 +88,9 @@ def lambda_handler(event, context): createSalesforceObject(contactId, contactLensTranscripts, contactLensConversationCharacteristics, mACContactChannelAnalyticsId) - logger.info('Updating s3 metadata') - updateLock(os.environ['TRANSCRIPTS_DESTINATION'], contactId, oMetadata) + if transcribeBucketExists: + logger.info('Updating s3 metadata') + updateLock(os.environ['TRANSCRIPTS_DESTINATION'], contactId, oMetadata) logger.info('Done') return {"Done": True} diff --git a/sam-app/lambda_functions/template.yaml b/sam-app/lambda_functions/template.yaml index 2e5167b..a31c56f 100644 --- a/sam-app/lambda_functions/template.yaml +++ b/sam-app/lambda_functions/template.yaml @@ -87,6 +87,10 @@ Parameters: Type: Number Default: 100 Description: Maximum retry attempts on failure for lambdas triggered by Kinesis Events + CTREventSourceMappingBatchSize: + Type: Number + Default: 30 + Description: Batch size for lambdas triggered by Kinesis Events SalesforceAdapterNamespace: Default: 'amazonconnect' Description: This is the namespace for CTI Adapter managed package. The default value is [amazonconnect]. If a non-managed package is used, leave this field blank. @@ -232,7 +236,7 @@ Conditions: Globals: Function: Timeout: 6 - Runtime: python3.7 + Runtime: python3.10 CodeUri: ./sam-app-deployment-artifact.zip Resources: @@ -243,7 +247,7 @@ Resources: Description: Salesforce Lambda function external dependencies ContentUri: ./lambda_layers.zip CompatibleRuntimes: - - python3.7 + - python3.10 invokeSfExecuteAWSServicePolicy: Type: AWS::IAM::ManagedPolicy @@ -1375,7 +1379,7 @@ Resources: FunctionName: Fn::GetAtt: sfCTRTrigger.Arn StartingPosition: "LATEST" - BatchSize: 100 + BatchSize: !Ref CTREventSourceMappingBatchSize MaximumRetryAttempts: !Ref CTREventSourceMappingMaximumRetryAttempts sfProcessTranscriptionResult: