Newer Version Available
Retry Contact Record Sync for Voice Call Records
| Ease of Implementation | Advanced |
| Estimated Time to Implement | 2–3 hours |
Contact Trace Records are generated on Amazon for each call. This data contains details about the call, including caller and rep information, call statistics, and queue information. The CTRDataSyncFunction Lambda function automatically runs for each call to store this data in a Voice Call record. CTRs aren’t retained by Amazon, and if the CTR sync process fails for any reason, you can lose important information about the call.
This solution provides a way to reattempt a sync of the CTR data by first backing up CTR data in a separate Amazon S3 bucket, then checking for any sync failures, and then re-uploading CTR data whenever necessary.
Prerequisites
- Have your AWS root user or AWS administrator credentials ready.
- Be familiar with Amazon S3 buckets. See Amazon’s documentation: Creating and configuring an S3 bucket.
- Be familiar with modifying Amazon Connect Lambda functions. See Amazon’s documentation: AWS Lambda Developer Guide.
- Configure the OAuth support for the InvokeSalesforceRestApiFunction Lambda function. This step is required to support the getAccessToken function.
Step 1: Create an Amazon S3 Bucket
- Under General Configuration > Bucket Type, select General Purpose.
- Under Object Ownership, select ACLs disabled (recommended).
- Under Block Public Access settings for this bucket, select Block all public access.
- Under Bucket Versioning, select Enable.
- Under Default Encryption > Encryption Type, select Server-side encryption with Amazon S3 managed keys (SSE-S3).
- Under Default Encryption > Bucket Key, select Enable.
See Amazon’s documentation: Creating and configuring an S3 bucket.
When using the code provided by your S3 bucket service in AWS, replace the resource account ID and ARN with your account ID and S3 bucket ARN, respectively. Delete all code comments before you save your changes.
Step 2: Set Data Expiration
After you store the CTR data in the S3 bucket, it’s a good idea to purge them periodically. To remove old data, specify the object expiration for the S3 bucket and define how long to wait before the files are deleted. See Amazon’s documentation: Expiring Objects and Managing your storage lifecycle.
Step 3: Save Contract Trace Records in S3
The CTRDataSyncFunction is configured to receive events from the Kinesis stream. These events are generated whenever a CTR is generated. Modify this Lambda function to read those events and write them to the S3 bucket as they’re generated. Update the handler.js file so that it contains a new function, writeCTRToS3, that writes data to the new bucket. Then, update the existing code to call this new function.
When modifying existing code, it's crucial to add code in the correct context. Inserting code snippets out of context or in the wrong order breaks the code.
In this example, the text in bold is where the new writeCTRToS3 function must be added to the handler.js file. Delete all code comments before you save your changes.
There’s one object in S3 for every CTR generated. The object is named with the ContactId of the CTR, so it’s easy to look up.
In the CTRDataSyncFunction associated with your contact center, create a new inline policy for the IAM role and delete any comments in the code before saving:
Step 4: Re-Sync Voice Calls That Aren’t Synced
Modify the InvokeSalesforceRestApiFunction Lambda to perform three key actions:
- Query for Voice Calls that aren’t synced. Query for all Voice Call records
(over a given time period) that weren’t updated by the CTRDataSyncFunction.
To identify Voice Calls that aren’t updated, you can filter by fields that
are only updated during a CTR sync. In this example, we specify a condition
based on CustomerHoldDuration.
- Fetch CTRs from S3. If there are results returned from the previous step, then read from the S3 bucket to fetch CTRs for the given Voice Call records. Look up this data with the VendorCallKey.
- Update Voice Call records in the org. Update Voice Call records based on the information returned from the previous step.
This code updates to InvokeSalesforceRestApiFunction perform all these actions.
Updates to sfRestApi.js. In-context changes are in bold. Remove any comments in the code before saving.
Updates to QueryEngine.js. In-context changes are in bold. Remove any comments in the code before saving.
Updates to Handler.js. In-context changes are in bold:
Updates to utils.js. In-context changes are in bold. Remove any comments in the code before saving.
The transformCTR and getCallAttributes functions are copied over from the CTRDataSyncFunction utils.js file. (Alternatively, directly modify CTRDataSyncFunction to support taking a single CTR and updating the Voice Call record from there.) These functions must be inserted under the declaration of the getRealtimeAlertEventFieldValuesFromConnectLambdaParams function.
In InvokeSalesforceRestApiFunction, add the AmazonS3FullAccess policy to the role:
Next, publish a new version of the Lambda functions. Make sure that you update this code in your Lambda functions to ensure compatibility after the contact center update.
Step 6: Call the New Method on the InvokeSalesforceRestApiFunction Lambda
Call this new method in InvokeSalesforceRestApiFunction by specifying a methodName of retryCTRSync and a soql attribute of SELECT Id, VendorCallKey FROM VoiceCall WHERE CustomerHoldDuration = null. You can schedule this call to run periodically. See Schedule AWS Lambda Functions Using CloudWatch Events in the Amazon documentation.
Test This Example
To test this example:
- Dial your phone number in order to create a Voice Call record. After the call is answered, hang up.
- In your org, find the newly created Voice Call record and remove some CTR fields, including CustomerHoldDuration.
- Call InvokeSalesforceRestApiFunction with the information specified
in the
final
step (step 6) of this example. However, instead of
scheduling the function to run, you can programmatically call the Lambda
from the console as shown in Amazon’s documentation (Create a Lambda function with the
console). Use a payload similar to
this:
- Check that the Voice Call record now has the CTR fields filled in.