def createSalesforceObject()

in sam-app/lambda_functions/sfProcessTranscriptionResult.py [0:0]


def createSalesforceObject(contactId, customerTranscripts, agentTranscripts, comprehendResults, mACContactChannelAnalyticsId):
    
    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':{}}}
    if mACContactChannelAnalyticsId is not None:
        logger.info('SF Object Already Created, with ID: %s' % mACContactChannelAnalyticsId)
        sfRequest['Details']['Parameters']['sf_operation'] = 'update'
        sfRequest['Details']['Parameters']['sf_id'] = mACContactChannelAnalyticsId
    else:
        sfRequest['Details']['Parameters']['sf_operation'] = 'create'

    sfRequest['Details']['Parameters']['sf_object'] = pnamespace + 'AC_ContactChannelAnalytics__c'
    sfRequest['Details']['Parameters'][pnamespace + 'ContactId__c'] = contactId
    sfRequest['Details']['Parameters'][pnamespace + 'Sentiment__c'] = comprehendResults['FormattedSentiment'] if 'FormattedSentiment' in comprehendResults else ''
    sfRequest['Details']['Parameters'][pnamespace + 'Keywords__c'] = comprehendResults['FormattedKeywords'] if 'FormattedKeywords' in comprehendResults else ''
    sfRequest['Details']['Parameters'][pnamespace + 'DominantLanguage__c'] = comprehendResults['FormattedDominantLanguage'] if 'FormattedDominantLanguage' in comprehendResults else ''
    sfRequest['Details']['Parameters'][pnamespace + 'NamedEntities__c'] = comprehendResults['FormattedNamedEntities'] if 'FormattedNamedEntities' in comprehendResults else ''

    ACContactChannelAnalyticsId = mACContactChannelAnalyticsId
    if mACContactChannelAnalyticsId is not None:
        logger.info("Updating the SF Object: %s" % sfRequest)
        invokeSfAPI(sfRequest)
    else:
        logger.info('SF Object does not exist, creating a new one: %s' % sfRequest)
        ACContactChannelAnalyticsId = invokeSfAPI(sfRequest)['Id']
        logger.info('SF Object Created, with ID: %s' % ACContactChannelAnalyticsId)

    if len(customerTranscripts) > 0:
        logger.info('Attaching SF Transcript - Customer Side')
        attachFileSaleforceObject('CustomerTranscripts.json', 'application/json', 'Call Recording Transcription - Customer Side', ACContactChannelAnalyticsId, getBase64String(customerTranscripts))
        logger.info('SF Transcript Attached - Customer Side')

    if len(agentTranscripts) > 0:
        logger.info('Attaching SF Transcript - Agent Side')
        attachFileSaleforceObject('AgentTranscripts.json', 'application/json', 'Call Recording Transcription - Agent Side', ACContactChannelAnalyticsId, getBase64String(agentTranscripts))
        logger.info('SF Transcript Attached - Agent Side')

    if 'FormattedSyntax' in comprehendResults:
        logger.info('Attaching Comprehend Syntax')
        attachFileSaleforceObject('ComprehendSyntax.json', 'application/json', 'Comprehend Syntax', ACContactChannelAnalyticsId, getBase64String(comprehendResults['FormattedSyntax']))
        logger.info('SF Comprehend Syntax Attached')