Updating Contact Attributes with Contact Lens rules

<body>
<div id="docs-ai-summary">
<p id="docs-ai-summary-toggle">Verified AI summary <span id="up-triangle">◀</span><span id="down-triangle">▼</span></p>
<p id="docs-ai-summary-content">
Enhance agent support by using Contact Lens rules to update contact attributes during calls and chats. Create a Contact Lens rule, a Lambda function, and an EventBridge rule to automate responses to customer issues. Customize attributes like labels and panels to provide real-time updates, improving the context agents have when assisting customers. This setup empowers agents to address customer concerns more effectively.
</p>
</div>
<div class="body">
<p class="p"><span class="ph addon_contact-center">Add-on | Zendesk for Contact Center</span></p>
<p class="p" dir="ltr">You can provide automated assistance to agents during calls and chats by using
Connect Contact Lens to process voice and chat transcripts in real-time and respond to
predefined scenarios. For example, if a customer expresses dissatisfaction about a
delivery delay, the system can swiftly detect this issue and provide agents with
instructions to reassure the customer that the matter is being addressed. </p>
<p class="p" dir="ltr">Contact Center supports standard contact attributes, as well as label, panel,
and button attributes. </p>
<p class="p" dir="ltr">To react to events published by Connect Contact Lens rules to automatically
assist and notify agents, you need to create a Contact Lens rule, create a Lambda
function, and then create an EventBridge rule.</p>
<p class="p" dir="ltr"><img class="image" id="updating_contact_attributes_with_rules__image_k1h_mq3_zgc" src="https://zen-marketing-documentation.s3.amazonaws.com/docs/en/cont_cent_bab3.png" width="500"></p>
<div class="bodydiv">
<div class="p">This article contains the following topics:<ul class="ul" id="updating_contact_attributes_with_rules__ul_jcr_xr3_zgc">
<li class="li"><a class="xref" href="#topic_s1g_s43_zgc">About standard contact attributes</a></li>
<li class="li"><a class="xref" href="#topic_vzh_r43_zgc">Creating a Connect Contact Lens rule</a></li>
<li class="li"><a class="xref" href="#topic_cll_s43_zgc">Create the Lambda function</a></li>
<li class="li"><a class="xref" href="#topic_mqq_s43_zgc">Create EventBridge rule</a></li>
</ul>
</div>
</div>
</div>
<div aria-labelledby="ariaid-title2" class="topic nested1" id="topic_s1g_s43_zgc">
<h2 class="title topictitle2" id="ariaid-title2">About standard contact attributes</h2>
<div class="body">
<p class="p" dir="ltr">Standard attributes can provide agents with context about the contact they
are managing. The standard contact attributes include the Label and Panel
attributes.</p>
<p class="p" dir="ltr">You can customize these attributes to use a variety of colour themes and
icons. Label attributes are used for concise information, such as status updates.
Panel attributes are used for longer information, with multiple lines and extra
formatting requirements.</p>
<p class="p" dir="ltr"><img class="image" id="topic_s1g_s43_zgc__image_mzl_lp3_zgc" src="https://zen-marketing-documentation.s3.amazonaws.com/docs/en/cont_cent_bab1.png" width="650"></p>
<p class="p" dir="ltr">You can also create buttons that link to external URLs. Keep in mind the
following:</p>
<ul class="ul" id="topic_s1g_s43_zgc__ul_rv3_1q3_zgc">
<li class="li" dir="ltr">
<p class="p" dir="ltr">You can create as many buttons as needed.</p>
</li>
<li class="li" dir="ltr">
<p class="p" dir="ltr">These buttons appear in Active contacts and Historical.</p>
</li>
<li class="li" dir="ltr">
<p class="p" dir="ltr">URLs are not validated by Contact Center.</p>
</li>
<li class="li" dir="ltr">
<p class="p" dir="ltr">Links open in a new tab.</p>
</li>
</ul>
<p class="p" dir="ltr"><img class="image" id="topic_s1g_s43_zgc__image_sv3_1q3_zgc" src="https://zen-marketing-documentation.s3.amazonaws.com/docs/en/cont_cent_bab2.png" width="650"></p>
</div>
</div>
<div aria-labelledby="ariaid-title3" class="topic nested1" id="topic_vzh_r43_zgc">
<h2 class="title topictitle2" id="ariaid-title3">Creating a Connect Contact Lens rule </h2>
<div class="body">
<p class="p">The first step is to create a Connect Contact Lens rule with an action type of
publishing an EventBridge event. This rule is designed for real-time call and chat
conditions, ensuring that contact attributes are promptly updated in near real-time
after the rule is triggered by Connect Contact Lens.</p>
<p class="p"><strong class="ph b">To create a Connect Contact Lends rule</strong></p>
<ol class="ol" id="topic_vzh_r43_zgc__ol_k1v_cp3_zgc">
<li class="li" dir="ltr">In Contact Lens, under the Analytics and Optimization Menu, navigate
to the Rules sections.</li>
<li class="li" dir="ltr">Click <strong class="ph b">Create a rule</strong>.</li>
<li class="li" dir="ltr">Select <strong class="ph b">Conversational analytics</strong>.</li>
<li class="li" dir="ltr">For When, select <strong class="ph b">A contact lens real-time call (or chat) analysis
is available</strong>
</li>
<li class="li" dir="ltr">Click <strong class="ph b">Add Condition</strong>, then select the condition you want to
apply to contacts.<p class="p">You can select whether these phrases can be from the
customer, agent, or both.</p>
</li>
<li class="li" dir="ltr">Click <strong class="ph b">Add Action</strong>, then select Generate an EventBridge Event.
<p class="p">Provide a name for this action. This name is visible in the EventBridge
event received in Lambda later.</p>
</li>
<li class="li" dir="ltr">Review the rule and publish it.</li>
</ol>
<p class="p" dir="ltr">For more information on setting up Contact Lens Rules in Connect, see <a class="xref" href="https://docs.aws.amazon.com/connect/latest/adminguide/build-rules-for-contact-lens.html" target="_blank">Create Contact Lens rules using the Amazon
Connect admin website</a> in the AWS documentation.</p>
</div>
</div>
<div aria-labelledby="ariaid-title4" class="topic nested1" id="topic_cll_s43_zgc">
<h2 class="title topictitle2" id="ariaid-title4">Create the Lambda function</h2>
<div class="body">
<p class="p">After you create your Connect Contact Lens rule, you need to create a Lambda function
to handle the actions, specifically updating the contact's standard, label, and
panel attributes. This ensures that agents see updates in real-time in Contact
Center.</p>
<p class="p"><img class="image" id="topic_cll_s43_zgc__image_x4m_gp3_zgc" src="https://zen-marketing-documentation.s3.amazonaws.com/docs/en/cont_cent_bab4.png" width="650"></p>
<p class="p"> In this instance, we name the function "_ConnectHandleRulesActions" and use Python
3.12. Incorporate the provided sample code into the Lambda function. You can modify
the code as needed, such as adding new conditions or adjusting the text for custom
attributes. Be sure to replace all the placeholders with your Amazon Connect and
account information.</p>
<p class="p" dir="ltr"><strong class="ph b">To create a lambda function to manage the events, use the following
code</strong></p>
<div class="p">
<pre class="pre">import json
import boto3
import os
def lambda_handler(event, context):
# Check for Contact ID
if 'contactArn' in event['detail']:
contact_arn = event['detail']['contactArn']
contact_id = contact_arn.split('/')[-1]
else:
print("INFO: Contact ID was not found. Skip.")
return
# Get Connect instance Id from Lambda env. variables
ConnectInstanceId = os.environ['ConnectInstanceId']
# Create a client for the Amazon Connect
connect_client = boto3.client('connect')
# Get values for rule and action
ruleName = event['detail']['ruleName']
actionName = event['detail']['actionName']
# Handle rules and actions
try:
if ruleName == 'DelayInDelivery':
if actionName == 'ConnectDelayInDeliveryAction':
# Update the contact with the new contact attribute
response = connect_client.update_contact_attributes(
InitialContactId=contact_id,
InstanceId=ConnectInstanceId,
Attributes={
'label_DelayInDelivery': '{"text":"Delay in
Delivery","theme":"warning","icon":"delivery"}',
'panel_DelayInDelivery': '{"text":"## Instructions for Delay in
Delivery: \\n\\n1. **Listen &amp; Apologize:** Acknowledge customer frustration
and apologize for the inconvenience.\\n1. **Gather Details:** Obtain order
number or relevant info to check order status.\\n1. **Explain Delay:**
Clearly communicate reason for delay (e.g., shipping issues,
inventory).\\n1. **Offer Solutions &amp; Follow-up:** Provide options
(expediting, refund) and promise to update on progress.","theme":"info"}'
}
)
# ...
# Extend the rules and actions to cover different scenarios.
# ...
except Exception as e:
print(f"An error occurred: {str(e)}")
return</pre>
</div>
<p class="p" dir="ltr">Ensure that the Lambda function has the necessary
"connect:UpdateContactAttributes" permission. Refer to the sample policy below for
guidance.</p>
<div class="p">
<pre class="pre">Unset
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "connect:UpdateContactAttributes",
"Resource": "arn:aws:connect:{AWS region}:{AWS account
number}:instance/{Connect instance ID}/contact/*"
}
]
}</pre>
</div>
</div>
</div>
<div aria-labelledby="ariaid-title5" class="topic nested1" id="topic_mqq_s43_zgc">
<h2 class="title topictitle2" id="ariaid-title5">Create EventBridge rule</h2>
<div class="body">
<p class="p">After you create the Lambda function, you need to create an EventBridge rule with a
target of the Lambda function.</p>
<div class="p">
<strong class="ph b">To create the EventBridge rule</strong><ol class="ol" id="topic_mqq_s43_zgc__ol_g5x_d53_zgc">
<li class="li">In the Amazon EventBridge service, click <strong class="ph b">Rules</strong>.</li>
<li class="li">Click <strong class="ph b">Create rule</strong>.</li>
<li class="li">Select <strong class="ph b">Rule with an event pattern</strong>, then proceed.</li>
<li class="li">Select <strong class="ph b">Use pattern form</strong>, then configure the AWS service to Amazon
Connect with the Event type set to <strong class="ph b">Realtime Rules Matched</strong>.</li>
<li class="li">Enter the name of the action set in the Connect Contact Lens rule or select
<strong class="ph b">Any action type</strong>.</li>
<li class="li">For the <strong class="ph b">Target</strong>, select the Lambda function you created.</li>
<li class="li">Review the details, then click <strong class="ph b">Create rule</strong>.</li>
</ol>
</div>
</div>
</div>
<script id="docs-schema-markup" type="application/ld+json">{
"@context": "https://schema.org",
"@type": "TechArticle",
"@id": "https://support.zendesk.com/hc/en-us/articles/9790997024282-Updating-Contact-Attributes-with-Contact-Lens-rules",
"url": "https://support.zendesk.com/hc/en-us/articles/9790997024282-Updating-Contact-Attributes-with-Contact-Lens-rules",
"headline": "Updating Contact Attributes with Contact Lens rules",
"description": "You can update contact attributes in real-time during calls and chats by creating Contact Lens rules, a Lambda function, and an EventBridge rule to automate agent support based on customer interactions.",
"articleSection": "Using Contact Center",
"datePublished": "2025-10-04T19:53:19+00:00",
"dateModified": "2025-10-17T22:28:18+00:00",
"inLanguage": "en-US",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://support.zendesk.com/hc/en-us/articles/9790997024282-Updating-Contact-Attributes-with-Contact-Lens-rules"
},
"author": {
"@type": "Organization",
"name": "Zendesk",
"@id": "https://www.zendesk.com"
},
"publisher": {
"@type": "Organization",
"name": "Zendesk",
"@id": "https://www.zendesk.com"
},
"isPartOf": {
"@type": "WebSite",
"name": "Zendesk Help",
"@id": "https://support.zendesk.com/hc/"
},
"about": {
"@type": "SoftwareApplication",
"name": "Zendesk",
"@id": "https://www.zendesk.com",
"softwareAddOn": {
"@type": "SoftwareApplication",
"name": "Contact Center",
"@id": "https://support.zendesk.com/hc/en-us/sections/9248688983706"
}
}
}</script><script id="fast-path-script">
//<![CDATA[
const fast_path_style = document.createElement('style');
fast_path_style.innerHTML = `#article-body .fastpath{font-size:.9em;background-color:#f3f3f3;border:1px solid #d3d3d3;padding:10px 10px 8px;margin-bottom:16px}#article-body .fastpath::before{content:none!important}`;
document.head.appendChild(fast_path_style);
//]]>
</script><script id="ai-summary-script">
//<![CDATA[
const ai_summary_style = document.createElement('style');
ai_summary_style.innerHTML = `#styled-article-body{padding:0 0 0}#article-body #docs-ai-summary{background-color:#f3f3f3;border:1px solid #d3d3d3;padding:10px 10px 6px;margin-bottom:16px}#article-body #docs-ai-summary #docs-ai-summary-toggle{font-size:.9em;font-weight:700;margin-bottom:4px;cursor:pointer;display:flex;justify-content:space-between;align-items:center}#article-body #docs-ai-summary #docs-ai-summary-toggle #up-triangle{margin-left:auto;padding-right:10px;display:none}#article-body #docs-ai-summary #docs-ai-summary-toggle #down-triangle{margin-left:auto;padding-right:10px}#article-body #docs-ai-summary #docs-ai-summary-content{font-size:.9em;padding-left:25px;padding-right:25px;margin-bottom:12px}`;
document.head.appendChild(ai_summary_style);

const toggleAISummary = () => {
const summary = document.getElementById("docs-ai-summary-content");
const upTriangle = document.getElementById("up-triangle");
const downTriangle = document.getElementById("down-triangle");
if (summary.style.display === "none") {
summary.style.display = "block";
upTriangle.style.display = "none";
downTriangle.style.display = "inline";
} else {
summary.style.display = "none";
upTriangle.style.display = "inline";
downTriangle.style.display = "none";
}
};

document.getElementById("docs-ai-summary-toggle").addEventListener("click", toggleAISummary);
//]]>
</script>

</body>