AWS Contact Center

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.

Overview

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.

Prerequisites

For this walkthrough, you should have the following prerequisites:

  • 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.

Walkthrough

Facebook developer console

  1. Navigate to the Facebook Developer console.
  2. Click My Apps
  3. Click Create App (or use an existing App)
  4. Select an app type for your business, for this walk through please choose Business which supports messenger. Click Next.
  5. Provide a display name, contact email, app purpose and choose whether or not to attach business manager account, then click Create App.
  6. Navigate to Settings, Basic, Next to App Secret click Show. Store this value somewhere
  7. Fill out the rest of the settings such as Privacy Policy URL, Terms of Service URL and Contact email.
  8. Navigate to Settings, Advanced, Security, add relevant details and turn on Require App Secret and click Save Changes.
  9. Navigate to Dashboard, Messenger, click Setup
  10. Under Access Tokens, add a page, or Create a new page
    1. This may prompt you to for a login review. Please follow the steps there.
  11. After the page has been added, click Generate Token, save this value on the side

Setup AWS Secret Manager

  1. Navigate to Secret Manager console, Store a new secret, Other type of secret
  2. Under Secret key/value add PAGE_TOKEN, APP_SECRET and VERIFY_TOKEN
    1. 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).
  3. Select the default encryption key. Click Next.
    1. Note: feel free to add a new key, however, make sure to modify the CDK project to provide permissions to that encryption Key.
  4. 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.
  5. Click Next, and Store the secret.
    1. Note: you can configure automatic rotation setting based on your requirements, however, for our walkthrough we will keep the default values.
  6. Next and then click Store,
  7. In the Secret manager console, search for the secret you just created and note down the Secret ARN.

Get Amazon Connect instance details

  1. Navigate to AWS Amazon Connect console
  2. Choose the Amazon Connect instance and note down the Instance ARN
  3. 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
  1. Using Git, clone the repository from Github
    git clone git@github.com:amazon-connect/amazon-connect-message-streaming-examples.git 
  2. In your terminal move into the root of the directory
    cd amazon-connect-message-streaming-examples
  3. 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 ../../..
  4. 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>
    
  5. Once the CDK deployment has finished, note down the FacebookApiGatewayWebhook from the CDK output.

Facebook console

  1. In the CDK output in the terminal, find the API Gateway invoke URL
  2. Navigate back to Facebook Developer console.
  3. In the App you created in the first step, go to Messenger, settings
  4. Under webhook, Add Callback URL.
    1. Callback URL as your API gateway invoke URL
    2. Verify token as the random string you created in the secret manager in step 2.
    3. Verify and save
  5. Click Add subscription
  6. Select messages
  7. 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!

Clean up

  1. Delete Facebook business page
  2. Delete Facebook developer account
  3. Navigate to the AWS Secret Manager Console and delete the secret
  4. Destroy the CDK stack
    cdk destroy \
    --context fbSecretArn=<YOUR SECRET ARN> \
    --context amazonConnectArn=<YOUR AMAZON CONNECT INSTANCE ARN> \
    --context contactFlowId=<YOUR CONTACT FLOW ID>

Conclusion

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!