|
| 1 | +# Lambda forAmazon Connect Chat Interactive Messaging [Lex V2] |
| 2 | + |
| 3 | +An AWS [Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) (AWS SAM) template to deploy a boilerplate **AWS Lambda** and **Amazon Lex** V2 bot, enabling interactive message in Amazon Connect chat. |
| 4 | + |
| 5 | +Interactive messages are pre-configured responses that your users can select from, making it easy for your customers to quickly resolve their issues through chat. Interactive messages can be designed using the new Amazon Connect Chat templates, which include several different customer display options (shared below), and are sent by Amazon Connect Chat using **Amazon Lex** chatbots. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## Specifications |
| 10 | + |
| 11 | +- Amazon Lex V2 |
| 12 | +- AWS Lambda Runtime: `nodejs18.x` |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +- An [AWS Account](https://aws.amazon.com/console/) with access to Lambda, Amazon Connect, and Amazon Lex |
| 17 | +- An **Amazon Connect** instance set up in your account [[Guide: Create an Amazon Connect instance](https://docs.aws.amazon.com/connect/latest/adminguide/amazon-connect-instances.html)] |
| 18 | + |
| 19 | +## Setup Instructions |
| 20 | + |
| 21 | +> #### Security Notice |
| 22 | +> ⚠️ This is example code not intended for production use. Dependencies may contain known vulnerabilities. Please update all dependencies before using in any production environment. |
| 23 | +
|
| 24 | +### 1. Deploy Sample Lambda Function |
| 25 | + |
| 26 | +1. Log in to the [AWS Console](https://console.aws.amazon.com/console/home). |
| 27 | +2. Deploy the sample Lambda function by visiting [this link](https://serverlessrepo.aws.amazon.com/applications/us-west-2/533267401313/amazon-connect-interactive-messages-example-lex-v2) and following the deployment instructions. |
| 28 | + |
| 29 | +### 2. Create Amazon Lex Bot |
| 30 | + |
| 31 | +1. Download the [`InteractiveMsg_LexBotV2_Export.zip`](./InteractiveMsg_LexBotV2_Export.zip) file. |
| 32 | +2. Navigate to the Amazon Lex page in the AWS Console. |
| 33 | +3. Click "Action" > "Import" and choose the downloaded ZIP file, named "MyNewLexV2Bot" |
| 34 | + |
| 35 | +<!-- TODO: add screenshot (like the LexV1 blog: https://aws.amazon.com/blogs/contact-center/easily-set-up-interactive-messages-for-your-amazon-connect-chatbot/ )--> |
| 36 | + |
| 37 | +### 3. Associate Lex Bot with Lambda Function |
| 38 | + |
| 39 | +1. In the AWS Console, open the new bot "MyNewLexV2Bot". |
| 40 | +2. Go to Aliases > TestBotAlias > Alias language support: English (US). |
| 41 | +3. Set the source to `serverless-xxxx` and click "Save". |
| 42 | +4. Ensure the InteractiveMessageIntent is linked to the Lambda: |
| 43 | + - Go to Versions > DRAFT > All languages > English (US) > Intents |
| 44 | + - Check "Use a Lambda function for initialization and validation" |
| 45 | +5. Build the bot: Versions > DRAFT > English (US) > Build |
| 46 | + |
| 47 | +<!-- TODO: add screenshot (like the LexV1 blog: https://aws.amazon.com/blogs/contact-center/easily-set-up-interactive-messages-for-your-amazon-connect-chatbot/ )--> |
| 48 | + |
| 49 | +### 4. Link Lex Bot to Amazon Connect Instance |
| 50 | + |
| 51 | +1. Go to the Amazon Connect page in the AWS Console. |
| 52 | +2. Click on your instance alias to open instance settings. |
| 53 | +3. Navigate to the "Flows" tab. |
| 54 | +4. Scroll to "Amazon Lex" and select your bot from the dropdown. |
| 55 | + |
| 56 | +<!-- TODO: add screenshot (like the LexV1 blog: https://aws.amazon.com/blogs/contact-center/easily-set-up-interactive-messages-for-your-amazon-connect-chatbot/ )--> |
| 57 | + |
| 58 | +### 5. Create Contact Flow |
| 59 | + |
| 60 | +1. Download the [`InteractiveMsg_ContactFlowLexV2_Export.zip`](./InteractiveMsg_ContactFlowLexV2_Export.json) file. |
| 61 | +2. Log in to your Amazon Connect instance. |
| 62 | +3. Go to `https://<YOUR-INSTANCE>.my.connect.aws/contact-flows`. |
| 63 | +4. Click "Create" > "Save" dropdown > "Import", named "InteractiveMessaging" |
| 64 | +5. Import the downloaded ZIP file. |
| 65 | +6. Edit the "Get customer input" contact flow block: |
| 66 | + - Select your Lex bot |
| 67 | + - Click "Save contact flow block" |
| 68 | +7. Click "Publish" to save your entire contact flow. |
| 69 | + |
| 70 | +<!-- TODO: add screenshot (like the LexV1 blog: https://aws.amazon.com/blogs/contact-center/easily-set-up-interactive-messages-for-your-amazon-connect-chatbot/ )--> |
| 71 | + |
| 72 | +### 6. Test the Setup |
| 73 | + |
| 74 | +1. Visit `https://<YOUR-INSTANCE>.my.connect.aws/test-chat`. |
| 75 | +2. Open settings and set it to use your new contact flow: "InteractiveMessaging". |
| 76 | +3. Launch the chat widget and type `help` to test the interaction. |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +## Diagrams |
| 81 | + |
| 82 | +Interactive Message System Diagram |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +Interactive Message Flow Chart |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +Interactive Message Chat Experience |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +## Supported Regions |
| 95 | + |
| 96 | +- us-east-1 (N. Virginia) |
| 97 | +- us-west-2 (Oregon) |
| 98 | +- ap-southeast-2 (Sydney) |
| 99 | +- ap-northeast-1 (Tokyo) |
| 100 | +- eu-central-1 (Frankfurt) |
| 101 | +- eu-west-2 (London) |
| 102 | +- ap-southeast-1 (Singapore) |
| 103 | +- ca-central-1 (Canada) |
| 104 | +- ap-northeast-2 (South Korea) |
| 105 | +- af-south-1 (Cape Town) |
| 106 | + |
| 107 | +## [Maintainers Only] Publish New Serverless Application Repository Version |
| 108 | + |
| 109 | +### Prerequisites |
| 110 | + |
| 111 | +- Install SAM CLI (`brew install aws-sam-cli`) |
| 112 | +- Access to account: `533267401313` (ask @spenlep-amzn) |
| 113 | + |
| 114 | +### Installation |
| 115 | + |
| 116 | +```sh |
| 117 | +git clone https://github.com/amazon-connect/amazon-connect-chat-ui-examples.git |
| 118 | +cd amazon-connect-chat-ui-examples |
| 119 | +cd samTemplates/amazon-connect-interactive-messages-example-lex-v2 |
| 120 | +export AWS_ACCESS_KEY_ID="your-access-key-id" |
| 121 | +export AWS_SECRET_ACCESS_KEY="your-secret-access-key" |
| 122 | +export AWS_SESSION_TOKEN="your-session-token" |
| 123 | +``` |
| 124 | + |
| 125 | +### Steps |
| 126 | + |
| 127 | +1. Make changes to source code locally |
| 128 | + |
| 129 | +2. Bump the version number in `template.yaml`, `package.yml`, and `package.json` |
| 130 | + ```diff |
| 131 | + - SemanticVersion: 2.0.1 |
| 132 | + + SemanticVersion: 2.0.2 |
| 133 | + ``` |
| 134 | + |
| 135 | +3. Validate the samTemplate |
| 136 | + |
| 137 | + ```bash |
| 138 | + sam validate --region us-west-2 --lint |
| 139 | + sam build |
| 140 | + ``` |
| 141 | + |
| 142 | +4. Update the `package.yml` by running: |
| 143 | + ```bash |
| 144 | + sam package --output-template-file packaged.yaml --s3-bucket amazon-connect-interactive-message-blog-assets-lex-v2 --region us-west-2 |
| 145 | + ``` |
| 146 | + |
| 147 | +5. Commit the updated files: |
| 148 | + ```bash |
| 149 | + git add package.yml template.yml path-to-my-updated-code |
| 150 | + ``` |
| 151 | + |
| 152 | +6. Create a pull request |
| 153 | + |
| 154 | +7. Publish the **Serverless Application Repository**: |
| 155 | + ```bash |
| 156 | + sam publish --template packaged.yaml --region us-west-2 |
| 157 | + ``` |
| 158 | + |
| 159 | +## License |
| 160 | + |
| 161 | +This sample code is made available under the MIT-0 license. See the [LICENSE](LICENSE) file for details. |
| 162 | + |
| 163 | +## Additional Resources |
| 164 | + |
| 165 | +- [Interactive Messages Documentation](https://docs.aws.amazon.com/connect/latest/adminguide/interactive-messages.html) |
| 166 | +- [AWS Lambda Documentation](https://docs.aws.amazon.com/lambda/) |
| 167 | +- [Amazon Connect Documentation](https://docs.aws.amazon.com/connect/) |
| 168 | +- [Amazon Lex Documentation](https://docs.aws.amazon.com/lex/) |
| 169 | + |
| 170 | +For any questions or support, please open an issue in this repository. |
0 commit comments