Adding digital messaging channels to your Amazon Connect contact center
Today, consumers can pick from a range of rich digital messaging apps to communicate with friends and family. Some example include: Facebook Messenger, iMessage, WhatsApp, WeChat, Viber, Line, Telegram and more. These digital channels are pervasive and widely used: eMarketer estimates that over 3 billion people will use at least one of them in 2021. Increasingly, consumers are interested in using these digital channels to reach out to companies because of their convenience and flexibility. It’s critical that all companies—regardless of size—meet their customers’ evolving communication preferences.
Now, using Amazon Connect’s new message streaming APIs, you can easily integrate these digital channels into your Amazon Connect contact center, enabling you to provide personalized, real-time support to your customers on the digital channels they prefer. In this blog post, we will walk you through how to integrate Facebook Messenger with your Amazon Connect contact center. The steps and architecture outlined below can also be applied to integrating with other digital channels. Once you set up Facebook Messenger (or any other digital channel) following the steps in this post, your agents can start receiving and replying to customer messages on that channel from the same agent desktop they already use for Amazon Connect voice, chat, and tasks.
In this blog post, we will deploy an example project from our Github repository. This project includes end to end infrastructure to support the Facebook Messenger channel. The infrastructure deployed could be extended to support additional channels such as Twitter DM, WhatsApp, Slack, etc…
To learn how to use these APIs to integrate Amazon Connect Chat with SMS, check out our other blog.
For this walkthrough, you should have the following prerequisites:
- 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 please go to the Facebook Developer console.
- 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
- Lambda writes the chat contact context to Amazon DynamoDB
- If this is the first message for the contact, Lambda calls the APIs 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 SNS invokes Lambda
- Lambda queries DynamoDB for chat contact context.
- Lambda delivers the reply message to the customer through APIs from the source channel.
Facebook developer console
- Navigate to the Facebook Developer console.
- Click My Apps
- Click Create App (or use an existing App)
- Select an app type for your business, for this walk through please choose Business which supports messenger. Click Next.
- Provide a display name, contact email, app purpose and choose whether or not to attach business manager account, then click Create App.
- Navigate to Settings, Basic, Next to App Secret click Show. Store this value somewhere
- Navigate to Settings, Advanced, Security, add relevant details and turn on Require App Secret and click Save Changes.
- Navigate to Dashboard, Messenger, click Setup
- Under Access Tokens, add a page, or Create a new page
- This may prompt you to for a login review. Please follow the steps there.
- After the page has been added, click Generate Token, save this value on the side
Setup AWS Secret Manager
- Navigate to Secret Manager console, Store a new secret, Other type of secret
- Under Secret key/value add PAGE_TOKEN, APP_SECRET and VERIFY_TOKEN
- For PAGE_TOKEN and APP_SECRET, use the values you got from the previous steps. For the verify token, you can use any random string (generate one yourself).
- Select the default encryption key. Click 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, description and Click Next.Note: If you add any additional resource permission and other settings please make sure the CDK stack resources are given permissions to this secret.
- Click 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.
- Next and then click Store,
- In the Secret manager console, search for the secret you just created and note down the Secret ARN.
Get Amazon Connect instance details
- Navigate to AWS Amazon Connect console
- Choose the Amazon Connect instance and note down the Instance ARN
- Login to your Amazon Connect Admin console, contact flows, and choose the contact flow you would like the Facebook messenger channel to start the chat contact in and note down 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
Make sure you have the following variables from the previous steps before continuing
- Amazon Connect Instance ARN
- Amazon Connect Contact flow ID
- AWS Secret Manager ARN which stores the values for PAGE_TOKEN, APP_SECRET and VERIFY_TOKEN
- 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.Note: SMS and Facebook channels are part of the same CDK project. If you are would like to deploy the SMS channel, you need to supply the pinpointAppId and smsNumber (the phone number) for more details, please refer the SMS blog.
cdk deploy \ --context fbSecretArn=<YOUR SECRET ARN> \ --context amazonConnectArn=<YOUR AMAZON CONNECT INSTANCE ARN> \ --context contactFlowId=<YOUR CONTACT FLOW ID>
- Once the CDK deployment has finished, note down the FacebookApiGatewayWebhook from the CDK output.
- 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 as your API gateway invoke URL
- Verify token as the random string you created in the secret manager in step 2.
- Verify and save
- Click Add subscription
- Select messages
- Click Save
Congrats! You’ve successfully added Facebook Messenger as a digital channel to your Amazon Connect instance. Send a message to your Facebook business page and you’ll be connected to your Amazon Connect instance!
- Delete Facebook business page
- Delete Facebook developer account
- Navigate to the AWS Secret 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>
In this post we showed you how to build a digital channel for Amazon Connect using the Amazon Connect Chat message streaming APIs and Facebook messenger as the example. To get started, visit our Github repository and deploy the project!