AWS Contact Center

Easily create and visualize post chat surveys with Amazon Connect and Amazon Lex

Contact centers face a challenge of having to constantly improve on the contact center experience based on customer feedback. In order to so, it is important that contact centers collect reliable and measurable data. Contact centers can implement post chat customer satisfaction surveys that allow for actionable feedback on user experience and agent performance. Customer satisfaction (CSAT) surveys are a useful tool to not only assess the performance of customer-facing agents, but also help in customer retention, by allowing businesses to address the concerns of unhappy customers. With Amazon Connect, customers are able to build omni-channel post contact surveys that cater to both call and chat.

In this blog, we will examine to create post chat surveys, and analyze customer satisfaction scores.

1. Create a post chat survey

Integrate Amazon Lex with Amazon Connect to send customers post chat surveys.

2. Analyze and visualize survey data

Integrate Amazon Kinesis Firehose, Amazon S3, AWS Glue, Amazon Athena and Amazon QuickSight to analyze and visualize survey data. This post will focus on generating insights from customer feedback, helping contact centers build customizable omni-channel post chat surveys and analyzing the results to take meaningful action based on how satisfied your customers are with your contact center service.

Overview of solution

The following diagram illustrates the solution.

The post chat Amazon Lex bot is configured to recognize the intents of user responses to survey questions and saves the intents as custom customer attributes in Amazon Connect. These attributes are stored in the contact trace records (CTRs), which are then streamed to Amazon Kinesis Data Firehose and stored in its raw JSON format in an Amazon S3 bucket. The CTRs contain events associated with the contact in your contact center, for example, the customer satisfaction scores stored as custom contact attributes. For a list of all data that’s captured in the CTR, see Contact trace records (CTR) data model. AWS Glue crawlers can be used to run scheduled or on-demand jobs to automatically determine the schema of the CTRs. The crawlers store the records in a data catalog which will be queried by Amazon Athena and visualized using Amazon QuickSight.


In this section, we will guide you through the steps required to deploy an Amazon Connect post chat survey solution in your AWS account, and perform some testing on your website page.

The high-level steps we will follow are as follows:

  1. Set up Amazon Lex bot
  2. Add Amazon Lex bot to Amazon Connect instance
  3. Set up Amazon Connect contact flows
  4. Configure Amazon Connect chat widget
  5. Enable data streaming to Amazon S3
  6. Run AWS Glue Crawler and Run Sample Reporting Queries in Amazon Athena
  7. Visualize in Amazon QuickSight


To implement a post call survey in your Amazon Connect contact center, you need the following pre-requisites in place:

Implementation steps

Step 1: Set up Amazon Lex Bot

1. In the Amazon Lex console, navigate to the Bots page.
2. On the Bots page, choose Actions, upload PostChatSurvey, and choose Import.

3. Build your bot.
4. Test it at the right side of the console. Type ‘3’ and see verify the response received is accurate by checking the Intent at the Inspect response section at the bottom.

5. Clear chat history and test the bot again with a different utterance, such as “Excellent”.
6. Choose Save, and then Publish. Note: For alias name, add latest.

Step 2: Add Amazon Lex bot to Amazon Connect instance

1. Navigate to the Amazon Connect Service on the AWS console.
2. Select the Instance Alias of the instance to which to add the bot.
3. Choose Contact flows.
4. Under Amazon Lex, use the drop-down to select the US East: N. Virginia region which you had created your Bot in earlier.
5. Select the PostChatSurvey Bot and choose + Add Lex Bot. If your bot is not in the list, reload the page and try again.

Step 3: Set up Amazon Connect Contact flows

1. Create the post chat survey contact flow:

  1. In the Amazon Connect console, choose Routing by clicking on the three arrowheads icon on the left bar and then click on Contact flows.
  2. Click on Create contact flow button.
  3. Name this contact flow as ‘Post Chat Survey’. Download and import our Post Chat Survey sample into your contact flow by selecting Import flow from the dropdown menu next to the Save button.

2. In this contact flow, we are using Contact Blocks to create the post chat survey.
3. The contact flow starts with a Get Customer Input block. Click on the header of the Get Customer Input block. Notice that the instructions will be played out as – “Please rate your chat experience from 1 to 5, where 1 – Bad, 2 – Poor, 3 – Average, 4 – Good, and 5 – Excellent”.
4. In the same Get Customer Input block, under the Amazon Lex tab, configure the Select a Lex bot option to use the PostChatSurvey Amazon Lex bot you had created earlier. This allows Amazon Connect to capture the customer response from the Amazon Lex bot, based on Amazon Lex intents.

5. Click on Save.
6. After the Get Customer Input block, we use the Set Contact Attributes block to store the customer response to the statement based on the Amazon Lex intents.
7. The attribute used to store the customer response is ‘SurveyResult’. It maps the Amazon Lex intents to a number that can be used for aggregation in reporting analytics.

8. Save and publish this contact flow.
9. As a next step, we will proceed to create another contact flow that will drive the customer experience during the initial inbound call. To do that:

  1. In the Amazon Connect console, choose Routing by clicking on the three arrowheads icon on the left bar and then click on Contact flows.
  2. Click on Create contact flow button.
  3. Name this contact flow as ‘Basic Chat Flow’.
  4. Import our Basic Chat Flow sample into your contact flow by selecting Import Flow from the dropdown menu next to the Save button.

10. In this contact flow, we are configuring the basic chat to trigger the chat with an agent. Before transferring to the queue, we use a Set Working Queue block to set the working queue to a particular queue. We can use the Basic Queue in this block.
11. We make use of Set Disconnect Flow block and map the ‘Post Chat Survey’ contact flow set up in previous steps as the ‘Disconnect Flow’.
12. Save and publish this contact flow.
13. Optional: If you require the survey solution to work for calls as well, ensure that your phone number is configured to use the Basic Chat Flow.

Step 4: Configure Amazon Connect chat widget

1. On the Amazon Connect dashboard, choose Test chat.

2. Choose Test Settings. Under System Settings, choose under the Contact Flow dropdown, select Basic Chat Flow that was imported in an earlier step.

3. On the Contact Control Panel on the right, ensure agent status is set to Available.
4. Click the Test widget icon on the left.
5. Wait for an incoming chat request to come in on the right agent panel, and click Accept chat.

6. After the agent has connected to the chat, using the agent panel on the right, choose End chat to trigger the disconnect flow. The user should see the Amazon Lex bot triggered after the agent disconnects from the chat.

Step 5: Enable data streaming to Amazon S3

1. Deploy this AWS CloudFormation template to set up Amazon Kinesis, Amazon S3, AWS Glue, and AWS Lambda. This template is based on the solution in this blog post.

  • If you wish to reuse an existing Kinesis Stream, you can specify your stream ARN in the KinesisStreamArn parameter and leave KinesisStreamName parameter empty
  • If you want to create a new Kinesis Stream, leave the KinesisStreamArn parameter blank and fill in the KinesisStreamName parameter

2. Open the Amazon Connect console. Select the Instance Alias of the instance to enable data streaming.
3. Choose Kinesis Stream and under the dropdown, select ctr-processor that was deployed in the CloudFormation template.

Step 6: Run AWS Glue Crawler and Run Sample Reporting Queries in Amazon Athena

1. Navigate to the AWS Glue console. Under ETL, click on Jobs.
2. The AWS CloudFormation template would have deployed an ETL job that automatically runs AWS Glue crawler jobs to extract CTRs from your Amazon S3 bucket that stores the CTRs.
3. We can select the job that begins with ‘glueJob-’. Run the job by choosing Run job under the Action button.
4. Wait for the AWS Glue job to run and to finish successfully. You can track the status of the job by checking the History tab.

5. When the job finishes running, check on Tables under the Database section. There should be a new table created called ctr.

6. After the ctr table has been created successfully, navigate to the Amazon Athena console.
7. Run the following sample reporting queries, written in SQL for Athena:
8. This query creates a View with relevant fields from the CTR table, while converting numerical values into the Integer type for aggregation queries. Replace ‘demo-connect-analytics-db’ with your own database name.

-- Create a Sample View
CREATE OR REPLACE VIEW surveyresult_table AS
SELECT CAST("attributes.surveyresult" AS INT) as surveyresult, "agent.username" as agentname, contactid, CAST(From_iso8601_timestamp(initiationtimestamp) AS timestamp) as "real_date"
FROM "demo-connect-analytics_db"."ctr"
WHERE "attributes.surveyresult" IS NOT NULL and "agent.username" IS NOT NULL;

9. This sample query uses the view created from before and aggregates survey results for a certain time range. You can modify the query date range for weekly or monthly reporting purposes as needed.

-- Aggregate Survey Results for Reporting After Certain Time Period
SELECT agentname, avg(surveyresult) as AverageScore FROM surveyresult_table
WHERE real_date > DATE('2021-07-07')
GROUP BY agentname;

10. The results can be exported as CSV by clicking on the file icon on the right of the results table for reporting purposes.

Step 7: Visualize in Amazon QuickSight

1. Ensure that Amazon QuickSight has permissions to access Amazon Athena and the Amazon S3 buckets. Follow the steps in the documentation.
2. For more information on doing this, see Managing Amazon QuickSight Permissions to AWS Resources in the Amazon QuickSight User Guide.
3. Choose Datasets, and New dataset. Select Athena as the data source.

4. Select your database and the ctr table.

5. Select Visualize.

6. In the Visualize tabs, you should see the following screen.

7. You can now create visualizations to analyze survey responses. The following are some sample visualization configurations.

  • Average Survey Result by Date:
    1. Under the Fields list, select the agentname, surveyresult, and real_date fields.
    2. Click into the graph and in the Field wells section, move surveyresult into the Values block. In the dropdown for surveyresult, select surveyresult (Average).
    3. This will give you a visual of average survey results by date, so you can easily see which agents have large variances in their average scores across the date range.

  • Average Survey Result by Agent Name:
  1. Under the Fields list, select the agentname and surveyresult fields.
  2. Click into the graph and in the Field wells section, in the Values block, select the dropdown for surveyresult and select surveyresult (Average).
  3. This will give you a visual of average survey result by agent, so you can easily see which agents have the highest average survey result.

8. You can create more visualizations, and proceed to rename and rearrange them in a similar reporting dashboard format as follows.

Cleaning up

To avoid incurring future charges, follow the steps below to clean up the deployed resources:

  • Delete the Amazon Connect instance:
    • In the Amazon Connect console, select the check box for the instance and choose Remove.
    • When prompted, type the name of the instance and choose Remove.
  • Delete the Amazon Lex Bot
    • In the Amazon Lex console, choose the bot that was created.
    • Choose Delete and then choose Continue.
  • Delete the Amazon QuickSight instance:
    • Unsubscribe from the service by logging in to the Amazon QuickSight console.
    • Choose your username on the application bar and Manage QuickSight.
    • Choose Account settings and Delete account.
  • Delete the AWS CloudFormation Stack:
  •  On the Stacks page, select the stack that was created before. In the stack details pane, choose Delete.
  • Select Delete stack when prompted.
  • This deletes the Amazon Kinesis stream, Amazon S3 bucket, AWS Glue job and crawlers, AWS IAM roles and AWS Lambda function.


In this post, you learned how to implement an omni-channel post chat survey solution using Amazon Lex that works for both voice and chat. Following that, we walked through the steps of streaming contact trace records to Amazon S3 and analyzing the survey responses using AWS Lambda, AWS Glue, Amazon Athena and Amazon QuickSight. This end-to-end survey solution enables contact centers to achieve operational excellence by continually improving and delivering business value to their customers.

For other Amazon Connect best practices, check out our blog channel