Newer Version Available

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

Retry Contact Record Sync for Voice Call Records

Amazon Connect contact record (previously called contact trace record or CTR) data is stored automatically in Voice Call records through data synchronization. Sometimes this sync doesn’t occur, and it isn’t always possible to access contact record data in Amazon Connect after the call. Back up contact record data to a separate Amazon S3 bucket, then check for Voice Call records that don’t have contact record data, and then resync the contact record 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 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

To run this example:
  1. Have your AWS root user or AWS administrator credentials ready.
  2. Be familiar with Amazon S3 buckets. See Amazon’s documentation: Creating and configuring an S3 bucket.
  3. Be familiar with modifying Amazon Connect Lambda functions. See Amazon’s documentation: AWS Lambda Developer Guide.
  4. 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

Create an Amazon S3 bucket on the same instance as your contact center. This bucket must be accessible within the region where your Amazon instance is configured. When creating your S3 bucket, make sure that you set the right access control policies for the bucket so it's not accessible outside of your instance.
  1. Under General Configuration > Bucket Type, select General Purpose.
  2. Under Object Ownership, select ACLs disabled (recommended).
  3. Under Block Public Access settings for this bucket, select Block all public access.
  4. Under Bucket Versioning, select Enable.
  5. Under Default Encryption > Encryption Type, select Server-side encryption with Amazon S3 managed keys (SSE-S3).
  6. 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:

Creating a new inline policy for the IAM role is required for the CTRDataSyncFunction to run, but it is not the only required policy. The other required policies come incorporated out of the box, but it’s a good idea to confirm that they’re present. These policies are:

Depending on how your org is configured, out of the box policies can come with additional attributes.

Important

Step 4: Re-Sync Voice Calls That Aren’t Synced

Modify the InvokeSalesforceRestApiFunction Lambda to perform three key actions:

  1. 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.
  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 Voice Call records. Look up this data with the VendorCallKey.
  3. Update Voice Call records in the org. Update Voice Call records based on the information returned from the previous step.

This code calls the InvokeTelephonyIntegrationApiFunction Lambda function. You can call it in one of two ways:

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

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:

Adding the AmazonS3FullAccess policy to the role is required for the CTRDataSyncFunction to run, but it’s not the only required policy. The other required policies come incorporated out of the box, but it’s a good idea to confirm that they’re present. These policies are:

Depending on how your org is configured, out of the box policies can come with additional attributes.

Important

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:

  1. Dial your phone number in order to create a Voice Call record. After the call is answered, hang up.
  2. In your org, find the newly created Voice Call 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 similar to this:
  4. Check that the Voice Call record now has the CTR fields filled in.