Redacting sensitive data in the chat message streaming API for Amazon Connect
Organizations today strive to provide increasingly personalized customer journeys. For example, up-selling new products based on history of interest in related products. Data collection drives the ability for businesses to personalize – data is valuable and the more collected, the more impact a personalized experience can have.
Businesses must be able however to balance the collection of data with commitments to data privacy and managing PII (Personally Identifiable Information). Sensitive PII data can be redacted in real time from Amazon Connect chat messages, preventing sensitive data from being passed between customers and agents. Such data can often be innocently shared, such as over informal social media channels, but becomes difficult or impossible to identify and purge once uttered and recorded in chat transcripts. Redacting sensitive data encourages frank and open interactions, rich in customer insight and data, while reducing the risk of inadvertently capturing sensitive data.
The benefits of the described solution apply to customers, agents, and compliance stakeholders alike:
- Protects customers from accidentally revealing PII
- Protects agents from having to handle PII that is unintentionally shared
- Protects businesses from having to identify and purge PII from data stores such as chat histories
- Minimizes risk of PII compliance breaches e.g., financial account details being shared
Solution overview and architecture
The example project detailed here is available from this GitHub repository. This project includes end to end infrastructure to support the Facebook Messenger channel.
Figure 1: Solution architecture
- Customer sends a message from the digital messaging channel to the webhook hosted on Amazon API Gateway.
- API Gateway sends the message to AWS Lambda.
- AWS Lambda writes the chat contact context to Amazon DynamoDB.
- AWS Lambda invokes the Amazon Comprehend API to redact sensitive data.
- If this is the first message for the contact, Lambda calls the API operations in the following order: StartChatContact, StartContactStreaming, and CreateParticipantConnection. If there is an existing chat, Lambda will send the message to Amazon Connect.
- Amazon Connect streams Agent/System messages to Amazon SNS. Amazon Simple Notification Service (Amazon SNS) is a fully managed pub/sub messaging, SMS, email, and mobile push notifications.
- Amazon SNS invokes AWS Lambda
- Lambda queries DynamoDB for chat contact context.
- Lambda delivers the reply message to the customer through APIs from the source channel.
For this walkthrough, it is assumed that you understand and have access to the following resources:
- An AWS account with administrator access
- An Amazon Connect Instance
- An Amazon Connect Contact Flow setup for Amazon Connect (include Disconnect flow)
- AWS CLI setup in your local environment
- A Facebook developer account. For more details, visit the Facebook Developer console.
- Node.js installation on the developer machine with NPM. Click here for more details.
Facebook Developer console
- Navigate to the Facebook Developer console.
- Choose My Apps.
- Select Create App (or use an existing App).
- Choose an app type for your business. For this walk through choose Business, which supports messenger.
- Choose Next.
- Provide a display name, contact email, app purpose.
- Choose whether to attach business manager account.
- Choose Create app.
- Navigate to Settings, Basic.
- Next to App Secret select Show. Store this value for later use.
- Navigate to Settings, Advanced, Security. Add relevant details.
- Turn on Require App Secret.
- Choose Save Changes.
- Navigate to Dashboard, Messenger.
- Choose Setup.
- Under Access Tokens, add a page or create a new page
- This may prompt you for a login review. Follow the steps there before proceeding.
- After the page has been added, choose Generate Token. Save this value on the side
Set up AWS Secrets Manager
- Open the AWS Management Console and login with an AWS Account with admin access where Amazon Connect instance is set up.
- Navigate to AWS Secrets Manager console, Store a new secret.
- Choose Other type of secrets.
- Under Secret key/value add APP_SECRET, PAGE_TOKEN and VERIFY_TOKEN
- APP_SECRET – App Secret generated previously.
PAGE_TOKEN – Access Token generated previously
VERIFY_TOKEN – For the verify token, use any random string. This will be added in Facebook later when the webhook Callback URL is created.
- APP_SECRET – App Secret generated previously.
- Select the default encryption key.
- Choose Next.
- Note: feel free to add a new key, however, make sure to modify the CDK project to provide permissions to that encryption key.
- Provide Secret name and Description.
- Choose Next.
- Note: If you add any additional resource permissions or other settings, CDK stack resources must be given permissions to this secret.
- Choose Next, and Store the secret.
- Note: you can configure automatic rotation setting based on your requirements, however, for our walkthrough we will keep the default values.
- In the AWS Secrets Manager console, search for the secret you just created and note down the Secret ARN.
Amazon Connect instance details
- Navigate to the Amazon Connect console.
- Choose the Amazon Connect instance and note down the Instance ARN.
- Log in to that instance’s Amazon Connect admin console.
- Choose contact flows.
- Choose the contact flow for Facebook messenger channel to start the chat contact. Note the Contact Flow ID.
Install AWS CDK and Bootstrap CDK environment (skip if you have CDK installed)
npm -g install typescript npm -g install aws-cdk cdk bootstrap aws://ACCOUNT_ID/AWS_REGION
Deploy the project
Before deploying, ensure you have the following variables from the previous steps before continuing:
- Amazon Connect Instance ARN
- Amazon Connect Contact flow ID
- AWS Secrets Manager secret ARNs where values for PAGE_TOKEN, APP_SECRET and VERIFY_TOKEN are stored
- Using Git, clone the repository from GitHub.
git clone email@example.com:amazon-connect/amazon-connect-message-streaming-examples.git
- In your terminal move into the root of the directory
- Install the dependencies for the CDK project and AWS Lambda functions.
npm install cd src/lambda/inboundMessageHandler npm install cd ../../.. cd src/lambda/outboundMessageHandler npm install cd ../../.. cd src/lambda/digitalChannelHealthCheck npm install cd ../../..
- Deploy the CDK project using your AWS CLI profile. Pass in the context environment variables amazonConnectArn, contactFlowId and fbSecretArn, which are required for the CDK stack. Provide a list of Amazon Comprehend PII entity types in the piiRedactionTypes parameter, for example as “PIN, CREDIT_DEBIT_NUMBER”.
- For a full list of PII Redaction entity types, visit Detecting PII entities. Having piiRedactionTypes set enables the filtering of PII information entered by the customer.
- SMS and Facebook channels are part of the same CDK project. If you would like to deploy the SMS channel, you need to supply the pinpointAppId and smsNumber (the phone number). For more details, refer to the SMS blog.
cdk deploy \ --context fbSecretArn=<YOUR SECRET ARN> \ --context amazonConnectArn=<YOUR AMAZON CONNECT INSTANCE ARN> \ --context contactFlowId=<YOUR CONTACT FLOW ID> \ --context piiRedactionTypes="<CSV LIST OF AMAZON COMPREHEND PII ENTITY TYPES, EX: PIN, CREDIT_DEBIT_NUMBER>"
- Once the CDK deployment has finished, note down the FacebookApiGatewayWebhook from the CDK output.
Note: This is a sample project designed to be easily deployable for experimentation. The IAM policy permissions use least privilege, however, the Amazon API Gateway deployed will be publicly accessible. Take the appropriate measures to secure your API Gateway by following the public documentation.
- In the CDK output in the terminal, find the API Gateway invoke URL.
- Navigate back to Facebook Developer console.
- In the App you created in the first step, go to Messenger, Settings.
- Under Webhook, add Callback URL
- Callback URL is your API Gateway invoke URL which was generated by CDK in step 5 of deploy the project section above.
- Verify token is the random string you created in the previous Secrets Manager section.
- Verify and save.
- Choose Add subscription
- Select messages
- Choose Save
Congrats! You’ve successfully added Facebook Messenger as a digital channel to your Amazon Connect instance with PII redaction. To test this solution, send a message to your Facebook business page and you’ll be connected to your Amazon Connect instance!
PII Redaction User Experience
These two screenshots show a sample conversation between a customer and agent, where the customer is sharing their credit card number and PIN code with an agent. Both values are redacted by the solution and are replaced with placeholders.
- Delete Facebook business page.
- Delete Facebook developer account.
- Navigate to the AWS Secrets Manager Console and delete the secret.
- Destroy the CDK stack
cdk destroy \ --context fbSecretArn=<YOUR SECRET ARN> \ --context amazonConnectArn=<YOUR AMAZON CONNECT INSTANCE ARN> \ --context contactFlowId=<YOUR CONTACT FLOW ID> \ --context piiRedactionTypes="<CSV LIST OF AMAZON COMPREHEND PII ENTITY TYPES, EX: PIN, CREDIT_DEBIT_NUMBER>"
In this blog post, we demonstrated an example of how to redact sensitive data to improve customer experience by protecting privacy of the customers, protecting agents from having to handle sensitive data, minimizing the risk of PII compliance breaches using Amazon Connect chat message streaming API. To get started, visit our GitHub repository and deploy the project!
|Abhishek Pandey is a Senior Solutions Architect with Amazon Web Services. With over 16 years of enterprise IT experience, Abhishek is passionate about diving deep with customers to architect creative solutions that support business innovation across different industries. Abhishek inspires builders to unlock the value of the AWS Cloud, using his secret blend of passion, enthusiasm, customer advocacy, curiosity, and creativity.|
|Attila is an Amazon Connect Consultant with Amazon Web Services Professional Services group. Besides contact center experience, he has also had software development and enterprise networking background. Attila is always looking at innovative ways of enhancing product capabilities to deliver customer benefits.|
|Jag Jhutty is a Senior Amazon Connect Consultant with Amazon Web Services Professional Services group. He has over 15 years of experience with various contact center technologies and infrastructure more generally, delivering solutions across different industries.|
|Ernest Ozdoba is an Amazon Connect Consultant at Amazon Web Services Professional Services. He has been working with multiplicity of organizations of various size and industries, for over 16 years, creating customer and agent experiences. Ernest is dedicated to details when building solutions, making sure to meet all customer expectations and follow best practices.|
|Michiel Buurman is an Amazon Connect Consultant with Amazon Web Services Professional Services. With more than 14 years of contact center experience, Michiel has helped many organizations deliver exceptional customer service to their clients.|