def createSalesforceObject()

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


def createSalesforceObject(contactId, contactLensTranscripts, contactLensConversationCharacteristics, 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
    
    if contactLensConversationCharacteristics['contactLensCustomerOverallSentiment']:
        sfRequest['Details']['Parameters'][pnamespace + 'ContactLensCustomerSentiment__c'] = contactLensConversationCharacteristics['contactLensCustomerOverallSentiment']
    if contactLensConversationCharacteristics['contactLensAgentOverallSentiment']:
        sfRequest['Details']['Parameters'][pnamespace + 'ContactLensAgentSentiment__c'] = contactLensConversationCharacteristics['contactLensAgentOverallSentiment']

    sfRequest['Details']['Parameters'][pnamespace + 'ContactLensInterruptions__c'] = contactLensConversationCharacteristics['contactLensInterruptions']
    if contactLensConversationCharacteristics['contactLensAgentInterruptions']:
        sfRequest['Details']['Parameters'][pnamespace + 'ContactLensAgentInterruptions__c'] = contactLensConversationCharacteristics['contactLensAgentInterruptions']
    if contactLensConversationCharacteristics['contactLensCustomerInterruptions']:
        sfRequest['Details']['Parameters'][pnamespace + 'ContactLensCustomerInterruptions__c'] = contactLensConversationCharacteristics['contactLensCustomerInterruptions']

    sfRequest['Details']['Parameters'][pnamespace + 'ContactLensNonTalkTime__c'] = contactLensConversationCharacteristics['contactLensNonTalkTime']
    sfRequest['Details']['Parameters'][pnamespace + 'ContactLensTalkSpeedCustomer__c'] = contactLensConversationCharacteristics['contactLensTalkSpeedCustomer']
    sfRequest['Details']['Parameters'][pnamespace + 'ContactLensTalkSpeedAgent__c'] = contactLensConversationCharacteristics['contactLensTalkSpeedAgent']
    sfRequest['Details']['Parameters'][pnamespace + 'ContactLensTalkTimeTotal__c'] = contactLensConversationCharacteristics['contactLensTalkTimeTotal']
    sfRequest['Details']['Parameters'][pnamespace + 'ContactLensTalkTimeCustomer__c'] = contactLensConversationCharacteristics['contactLensTalkTimeCustomer']
    sfRequest['Details']['Parameters'][pnamespace + 'ContactLensTalkTimeAgent__c'] = contactLensConversationCharacteristics['contactLensTalkTimeAgent']
    if contactLensConversationCharacteristics['recordingPath'] is not None:
        sfRequest['Details']['Parameters'][pnamespace + 'RecordingPath__c'] = contactLensConversationCharacteristics['recordingPath']
    if contactLensConversationCharacteristics['contactLensMatchedCategories']:
        sfRequest['Details']['Parameters'][pnamespace + 'ContactLensMatchedCategories__c'] = contactLensConversationCharacteristics['contactLensMatchedCategories']
    
    sfRequest['Details']['Parameters'][pnamespace + 'ContactLensMatchedDetails__c'] = contactLensConversationCharacteristics['contactLensMatchedDetails']
    if contactLensConversationCharacteristics['contactLensCustomerSentimentCurve']:
        sfRequest['Details']['Parameters'][pnamespace + 'ContactLensCustomerSentimentCurve__c'] = contactLensConversationCharacteristics['contactLensCustomerSentimentCurve']

    sfRequest['Details']['Parameters'][pnamespace + 'DataSource__c'] = getDataSource()
    sfRequest['Details']['Parameters'][pnamespace + 'ContactLensTranscriptsFullText__c'] = contactLensConversationCharacteristics['contactLensTranscriptsFullText']
    # if len(customerTranscripts) > 0:
    #     sfRequest['Details']['Parameters'][pnamespace + 'ContactLensCustomerTranscripts__c'] = customerTranscripts
    # if len(agentTranscripts) > 0:
    #     sfRequest['Details']['Parameters'][pnamespace + 'ContactLensAgentTranscripts__c'] = agentTranscripts
    

    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(contactLensTranscripts) > 0:
        logger.info('Attaching SF Transcript - Contact Lens')
        attachFileSaleforceObject('ContactLensTranscripts.json', 'application/json', 'Contact Lens Transcripts', ACContactChannelAnalyticsId, getBase64String(contactLensTranscripts))
        logger.info('SF Transcript Attached - Contact Lens')