Skip to content

Commit

Permalink
Merge pull request #56 from amazon-connect/v5.19.1
Browse files Browse the repository at this point in the history
v5.19.1
  • Loading branch information
Ilapides authored Oct 17, 2023
2 parents 34cb6a0 + 6c2f563 commit adfff25
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
Binary file modified sam-app/lambda_functions/lambda_layers.zip
Binary file not shown.
36 changes: 36 additions & 0 deletions sam-app/lambda_functions/sfInvokeAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {}

Expand Down
16 changes: 10 additions & 6 deletions sam-app/lambda_functions/sfProcessContactLens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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}
Expand Down
10 changes: 7 additions & 3 deletions sam-app/lambda_functions/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -232,7 +236,7 @@ Conditions:
Globals:
Function:
Timeout: 6
Runtime: python3.7
Runtime: python3.10
CodeUri: ./sam-app-deployment-artifact.zip

Resources:
Expand All @@ -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
Expand Down Expand Up @@ -1375,7 +1379,7 @@ Resources:
FunctionName:
Fn::GetAtt: sfCTRTrigger.Arn
StartingPosition: "LATEST"
BatchSize: 100
BatchSize: !Ref CTREventSourceMappingBatchSize
MaximumRetryAttempts: !Ref CTREventSourceMappingMaximumRetryAttempts

sfProcessTranscriptionResult:
Expand Down

0 comments on commit adfff25

Please sign in to comment.