Newer Version Available

This content describes an older version of this product. View Latest

Retry CTR Sync for VoiceCall Records

Typically, Call Trace Record (CTR) data is automatically stored in VoiceCall records. However, there are occasions where this sync doesn’t occur, and it isn’t always possible to access CTR data in Amazon Connect after the call. This example shows you how to back up CTR data to a separate S3 bucket, then check for VoiceCall records that don’t have CTR data, and then resync the CTR data to your org using the backup data.
Ease of Implementation Advanced
Estimated Time to Implement 2–3 hours

Contact Trace Records are generated on Amazon for each call. This data contains the details about the call including caller and agent information, call statistics, and queue information. The CTRDataSyncFunction Lambda automatically runs for each call in order to store this data in a VoiceCall record. CTRs aren’t retained by Amazon and if the CTR sync process fails for any reason, you could 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

To run this example:
  1. Have your AWS root user or AWS administrator credentials ready.
  2. Be familiar with Amazon S3 buckets. To learn more, see Amazon’s documentation: Creating and configuring an S3 bucket.
  3. Be familiar with modifying Amazon Connect Lambda functions. To learn more, see Amazon’s documentation: AWS Lambda Developer Guide.

Step 1: Create an S3 Bucket

Create an S3 bucket within the region and set the access policies to be accessible within the region where your Amazon instance is configured. Also, ensure you set the right access control policies for the bucket so it's not accessible outside of your instance. To learn more, see Amazon’s documentation: Creating and configuring an S3 bucket.

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. To learn more, see Amazon’s documentation: Expiring Objects and Managing your storage lifecycle.

Step 3: Save Contract Trace Records in S3

The CTRDataSyncFunction Lambda 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.

Changes to handler.js:

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.

Step 4: Re-Sync VoiceCalls That Aren’t Synced

Now, modify the InvokeSalesforceRestApiFunction Lambda to perform three key actions:

  1. Query for VoiceCalls that aren’t synced. Query for all VoiceCall records (over a given time period) that weren’t updated by CTRDataSyncFunction. To identify VoiceCalls 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.
  2. 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 VoiceCall records. Look up this data with the VendorCallKey.
  3. Update VoiceCall records in the org. Update VoiceCall records based on the information returned from the previous step.

This code calls the InvokeTelephonyIntegrationApiFunction Lambda. You can make this call in one of the following two ways:

a) Declare an environment variable for that Lambda and reference it from your code.

b) Hard-code the ARN of the InvokeTelephonyIntegrationApiFunction Lambda into your code.

This sample code assumes that there’s an environment variable named INVOKE_TELEPHONY_INTEGRATION_API_ARN (option a), but you can hard-code the ARN if you prefer.

Important

The following code updates to InvokeSalesforceRestApiFunction perform all of the above actions.

Updates to sfRestApi.js.

Updates to QueryEngine.js.

Updates to Handler.js.

Updates to utils.js.

The following two functions (transformCTR and getCallAttributes) are copied over from CTRDataSyncFunction Lambda utils.js. (Alternatively, directly modify CTRDataSyncFunction Lambda to support taking a single CTR and updating the VoiceCall record from there.)

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 as documented in Amazon’s documentation: Schedule AWS Lambda Functions Using CloudWatch Events.

Test This Example

To test this example:

  1. Dial your phone number in order to create a VoiceCall record. After the call is answered, hang up.
  2. In your org, find the newly created VoiceCall record and remove some CTR fields, including CustomerHoldDuration.
  3. 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 such as this:
  4. Check that the VoiceCall record now has the CTR fields filled in.