Skip to content

create samTemplate Lex V2 interactive msg lambda hook #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/samTemplate-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Validate SAM Template

on:
pull_request:
branches:
- master
paths:
- 'samTemplates/amazon-connect-interactive-messages-example-lex-v2/**'

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install SAM CLI
run: |
pip install aws-sam-cli
- name: Validate SAM template
run: |
cd samTemplates/amazon-connect-interactive-messages-example-lex-v2
sam validate --region us-west-2 --lint
- name: Build SAM template
run: |
cd samTemplates/amazon-connect-interactive-messages-example-lex-v2
sam build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.DS_Store
.vscode
.idea
.aws-sam
node_modules
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.4] - 2025-04-08

### Added
- [samTemplates/amazon-connect-interactive-messages-example-lex-v2](./samTemplates/amazon-connect-interactive-messages-example-lex-v2) - new **AWS Serverless Application Model (AWS SAM) template** to deploy an **Amazon Lex V2** bot for interactive messages in Chat.

## [1.4.3] - 2023-11-07
### Added
- [iOSChatExample](mobileChatExamples/iOSChatExample/README.md) - iOS example of the AWS Connect chat widget is designed for easy integration with a focus on customization.
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,22 @@ At the moment, these are the solutions in this repo:
3. **[samTemplates/amazon-connect-interactive-messages-example](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/samTemplates/amazon-connect-interactive-messages-example)**
Interactive messages in Amazon Connect Chat allow contact centers to provide personalized prompts and response options that customers can easily select from. This serverless application is a sample lambda function which implements Amazon Connect interactive message templates (lists, lists with images, and a time picker) as described in the AWS Contact Center blog post [How to enable interactive messages in Amazon Connect chat](https://aws.amazon.com/blogs/contact-center/easily-set-up-interactive-messages-for-your-amazon-connect-chatbot/).

4. **[customChatWidget](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/customChatWidget)**
4. **[samTemplates/amazon-connect-interactive-messages-example-lex-v2](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/samTemplates/amazon-connect-interactive-messages-example-lex-v2)**
Interactive messages in Amazon Connect Chat allow contact centers to provide personalized prompts and response options that customers can easily select from. This serverless application is a sample lambda function which implements Amazon Connect interactive message templates (lists, lists with images, and a time picker).

5. **[customChatWidget](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/customChatWidget)**
Custom Chat Widget for Amazon Connect, with a Chat Form that can be easily plugged into a webpage. This solution helps customers to have Amazon Connect Custom Chat Widget in their website, by applying simple configuration parameters. It also makes customizing the `amazon-connect-interface.js` file easier, and can be used as an easy way to host custom widget on a webpage.

5. **[connectReactNativeChat](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/mobileChatExamples/connectReactNativeChat)**
6. **[connectReactNativeChat](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/mobileChatExamples/connectReactNativeChat)**
React Native demo Chat application for Amazon Connect. This cross-platform solution implements basic Chat JS functionality and is fully customizable. Follow the provided documentation to build with [`amazon-connect-chatjs@^1.5.0`](https://github.com/amazon-connect/amazon-connect-chatjs).
6. **[startChatContactAPILocalProxy](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/startChatContactAPILocalProxy)**

7. **[startChatContactAPILocalProxy](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/startChatContactAPILocalProxy)**
Solution to run local proxy server for the Amazon Connect [StartChatContact](https://docs.aws.amazon.com/connect/latest/APIReference/API_StartChatContact.html) Public API. Can be used during local development when building a custom chat interface, prior to deploying a production CloudFormation chat backend.

6. **[hostedWidgetCustomization](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/hostedWidgetCustomization)**
8. **[hostedWidgetCustomization](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/hostedWidgetCustomization)**
Additional ways to configure the Amazon Connect Hosted Widget on your website and further personalize the branding. This sample code covers several common use cases for customizing the widget snippet code. [Learn more](https://docs.aws.amazon.com/connect/latest/adminguide/add-chat-to-website.html)

7. **[mobileChatExamples](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/mobileChatExamples)**
9. **[mobileChatExamples](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/mobileChatExamples)**
These native mobile examples of the AWS Connect chat widget are designed for easy integration with a focus on customization. Out-of-the-box ready yet fully adaptable, they offer developers the perfect starting point for incorporating a chat feature that can be fine-tuned to any customer’s requirements.


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Version":"2019-10-30","StartAction":"8b2f025e-cd00-4ffe-821a-76a3f9dda572","Metadata":{"entryPointPosition":{"x":14.4,"y":20},"ActionMetadata":{"b0dd1051-e4f0-4bae-9f09-2c1ba82ca30d":{"position":{"x":1493.6,"y":13.6}},"36eb2181-5b9d-4e15-97cb-25b338280e30":{"position":{"x":1765.6,"y":242.4}},"cb0a54b8-6407-44b2-b507-f8401de864c0":{"position":{"x":1208,"y":12},"parameters":{"QueueId":{"displayName":"BasicQueue"}},"queue":{"text":"BasicQueue"}},"057134d9-a78e-4910-80f6-406a24ed68ca":{"position":{"x":680,"y":345.6}},"8b2f025e-cd00-4ffe-821a-76a3f9dda572":{"position":{"x":162.4,"y":13.6}},"3b2f3727-4eb7-4422-95c2-50798429f382":{"position":{"x":685.6,"y":12},"conditions":[],"conditionMetadata":[{"id":"841b4357-b5b8-4132-aee4-e1bcfae4073a","operator":{"name":"Equals","value":"Equals","shortDisplay":"="},"value":"Continue to agent"},{"id":"7230f710-6910-48eb-bfc6-5ad9db8825dc","operator":{"name":"Equals","value":"Equals","shortDisplay":"="},"value":"End chat"}]},"b701c222-ed08-4fb2-84ff-b91f0fae04b9":{"position":{"x":420.8,"y":12.8},"useLexBotDropdown":true,"conditionMetadata":[]}},"Annotations":[],"name":"InteractiveMessaging","description":"","type":"contactFlow","status":"published","hash":{}},"Actions":[{"Parameters":{},"Identifier":"b0dd1051-e4f0-4bae-9f09-2c1ba82ca30d","Type":"TransferContactToQueue","Transitions":{"NextAction":"36eb2181-5b9d-4e15-97cb-25b338280e30","Errors":[{"NextAction":"36eb2181-5b9d-4e15-97cb-25b338280e30","ErrorType":"QueueAtCapacity"},{"NextAction":"36eb2181-5b9d-4e15-97cb-25b338280e30","ErrorType":"NoMatchingError"}]}},{"Parameters":{},"Identifier":"36eb2181-5b9d-4e15-97cb-25b338280e30","Type":"DisconnectParticipant","Transitions":{}},{"Parameters":{"QueueId":"arn:aws:connect:us-west-2:990999614922:instance/7f18d5d6-8e42-4613-9014-84503d17e7da/queue/48e235a6-546b-43a8-aa4c-9a8d04e45ad1"},"Identifier":"cb0a54b8-6407-44b2-b507-f8401de864c0","Type":"UpdateContactTargetQueue","Transitions":{"NextAction":"b0dd1051-e4f0-4bae-9f09-2c1ba82ca30d","Errors":[{"NextAction":"36eb2181-5b9d-4e15-97cb-25b338280e30","ErrorType":"NoMatchingError"}]}},{"Parameters":{"Text":"Sorry I did not understand that. Please try again later."},"Identifier":"057134d9-a78e-4910-80f6-406a24ed68ca","Type":"MessageParticipant","Transitions":{"NextAction":"36eb2181-5b9d-4e15-97cb-25b338280e30"}},{"Parameters":{"FlowLoggingBehavior":"Enabled"},"Identifier":"8b2f025e-cd00-4ffe-821a-76a3f9dda572","Type":"UpdateFlowLoggingBehavior","Transitions":{"NextAction":"b701c222-ed08-4fb2-84ff-b91f0fae04b9"}},{"Parameters":{"ComparisonValue":"$.Lex.Slots.action"},"Identifier":"3b2f3727-4eb7-4422-95c2-50798429f382","Type":"Compare","Transitions":{"NextAction":"cb0a54b8-6407-44b2-b507-f8401de864c0","Conditions":[{"NextAction":"cb0a54b8-6407-44b2-b507-f8401de864c0","Condition":{"Operator":"Equals","Operands":["Continue to agent"]}},{"NextAction":"36eb2181-5b9d-4e15-97cb-25b338280e30","Condition":{"Operator":"Equals","Operands":["End chat"]}}],"Errors":[{"NextAction":"cb0a54b8-6407-44b2-b507-f8401de864c0","ErrorType":"NoMatchingCondition"}]}},{"Parameters":{"Text":"Edit this message in the \"Get customer input\" block in Flows\n\nType help to get help!","LexBot":{"Name":"InteractiveMessageBot","Region":"us-west-2","Alias":"latest"}},"Identifier":"b701c222-ed08-4fb2-84ff-b91f0fae04b9","Type":"ConnectParticipantWithLexBot","Transitions":{"NextAction":"057134d9-a78e-4910-80f6-406a24ed68ca","Errors":[{"NextAction":"3b2f3727-4eb7-4422-95c2-50798429f382","ErrorType":"NoMatchingCondition"},{"NextAction":"057134d9-a78e-4910-80f6-406a24ed68ca","ErrorType":"NoMatchingError"}]}}]}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# Lambda forAmazon Connect Chat Interactive Messaging [Lex V2]

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.

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.

![Interactive Messages Thumbnail](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/samTemplates/amazon-connect-interactive-messages-example-lex-v2/docs/AmazonConnectLexLambdaArchitecture.png)

## Specifications

- Amazon Lex V2
- AWS Lambda Runtime: `nodejs18.x`

## Prerequisites

- An [AWS Account](https://aws.amazon.com/console/) with access to Lambda, Amazon Connect, and Amazon Lex
- 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)]

## Setup Instructions

> #### Security Notice
> ⚠️ This is example code not intended for production use. Dependencies may contain known vulnerabilities. Please update all dependencies before using in any production environment.

### 1. Deploy Sample Lambda Function

1. Log in to the [AWS Console](https://console.aws.amazon.com/console/home).
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.

### 2. Create Amazon Lex Bot

1. Download the [`InteractiveMsg_LexBotV2_Export.zip`](./InteractiveMsg_LexBotV2_Export.zip) file.
2. Navigate to the Amazon Lex page in the AWS Console.
3. Click "Action" > "Import" and choose the downloaded ZIP file, named "MyNewLexV2Bot"

<!-- TODO: add screenshot (like the LexV1 blog: https://aws.amazon.com/blogs/contact-center/easily-set-up-interactive-messages-for-your-amazon-connect-chatbot/ )-->

### 3. Associate Lex Bot with Lambda Function

1. In the AWS Console, open the new bot "MyNewLexV2Bot".
2. Go to Aliases > TestBotAlias > Alias language support: English (US).
3. Set the source to `serverless-xxxx` and click "Save".
4. Ensure the InteractiveMessageIntent is linked to the Lambda:
- Go to Versions > DRAFT > All languages > English (US) > Intents
- Check "Use a Lambda function for initialization and validation"
5. Build the bot: Versions > DRAFT > English (US) > Build

<!-- TODO: add screenshot (like the LexV1 blog: https://aws.amazon.com/blogs/contact-center/easily-set-up-interactive-messages-for-your-amazon-connect-chatbot/ )-->

### 4. Link Lex Bot to Amazon Connect Instance

1. Go to the Amazon Connect page in the AWS Console.
2. Click on your instance alias to open instance settings.
3. Navigate to the "Flows" tab.
4. Scroll to "Amazon Lex" and select your bot from the dropdown.

<!-- TODO: add screenshot (like the LexV1 blog: https://aws.amazon.com/blogs/contact-center/easily-set-up-interactive-messages-for-your-amazon-connect-chatbot/ )-->

### 5. Create Contact Flow

1. Download the [`InteractiveMsg_ContactFlowLexV2_Export.zip`](./InteractiveMsg_ContactFlowLexV2_Export.json) file.
2. Log in to your Amazon Connect instance.
3. Go to `https://<YOUR-INSTANCE>.my.connect.aws/contact-flows`.
4. Click "Create" > "Save" dropdown > "Import", named "InteractiveMessaging"
5. Import the downloaded ZIP file.
6. Edit the "Get customer input" contact flow block:
- Select your Lex bot
- Click "Save contact flow block"
7. Click "Publish" to save your entire contact flow.

<!-- TODO: add screenshot (like the LexV1 blog: https://aws.amazon.com/blogs/contact-center/easily-set-up-interactive-messages-for-your-amazon-connect-chatbot/ )-->

### 6. Test the Setup

1. Visit `https://<YOUR-INSTANCE>.my.connect.aws/test-chat`.
2. Open settings and set it to use your new contact flow: "InteractiveMessaging".
3. Launch the chat widget and type `help` to test the interaction.

![Lex Bot Message on Test Chat Page](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/samTemplates/amazon-connect-interactive-messages-example-lex-v2/docs/TestChatPageExample.png)

## Diagrams

Interactive Message System Diagram

![Interactive Message System Diagram](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/samTemplates/amazon-connect-interactive-messages-example-lex-v2/docs/interactive-message-diagram.png)

Interactive Message Flow Chart

![Interactive Message Flow Chart](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/samTemplates/amazon-connect-interactive-messages-example-lex-v2/docs/InteractiveMessageUIExample_FlowChart.png)

Interactive Message Chat Experience

![Interactive Message Chat Experience](https://github.com/amazon-connect/amazon-connect-chat-ui-examples/tree/master/samTemplates/amazon-connect-interactive-messages-example-lex-v2/docs/InteractiveMessageChatFlow.png)

## Supported Regions

- us-east-1 (N. Virginia)
- us-west-2 (Oregon)
- ap-southeast-2 (Sydney)
- ap-northeast-1 (Tokyo)
- eu-central-1 (Frankfurt)
- eu-west-2 (London)
- ap-southeast-1 (Singapore)
- ca-central-1 (Canada)
- ap-northeast-2 (South Korea)
- af-south-1 (Cape Town)

## [Maintainers Only] Publish New Serverless Application Repository Version

### Prerequisites

- Install SAM CLI (`brew install aws-sam-cli`)
- Access to account: `533267401313` (ask @spenlep-amzn)

### Installation

```sh
git clone https://github.com/amazon-connect/amazon-connect-chat-ui-examples.git
cd amazon-connect-chat-ui-examples
cd samTemplates/amazon-connect-interactive-messages-example-lex-v2
export AWS_ACCESS_KEY_ID="your-access-key-id"
export AWS_SECRET_ACCESS_KEY="your-secret-access-key"
export AWS_SESSION_TOKEN="your-session-token"
```

### Steps

1. Make changes to source code locally

2. Bump the version number in `template.yaml`, `package.yml`, and `package.json`
```diff
- SemanticVersion: 2.0.1
+ SemanticVersion: 2.0.2
```

3. Validate the samTemplate

```bash
sam validate --region us-west-2 --lint
sam build
```

4. Update the `package.yml` by running:
```bash
sam package --output-template-file packaged.yaml --s3-bucket amazon-connect-interactive-message-blog-assets-lex-v2 --region us-west-2
```

5. Commit the updated files:
```bash
git add package.yml template.yml path-to-my-updated-code
```

6. Create a pull request

7. Publish the **Serverless Application Repository**:
```bash
sam publish --template packaged.yaml --region us-west-2
```

## License

This sample code is made available under the MIT-0 license. See the [LICENSE](LICENSE) file for details.

## Additional Resources

- [Interactive Messages Documentation](https://docs.aws.amazon.com/connect/latest/adminguide/interactive-messages.html)
- [AWS Lambda Documentation](https://docs.aws.amazon.com/lambda/)
- [Amazon Connect Documentation](https://docs.aws.amazon.com/connect/)
- [Amazon Lex Documentation](https://docs.aws.amazon.com/lex/)

For any questions or support, please open an issue in this repository.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"requestAttributes": {
"x-amz-lex:accept-content-types": "PlainText"
},
"sessionId": "5d11c7ca-6eb1-48d1-b5f2-58510e9ae6c3",
"inputTranscript": "help",
"interpretations": [
{
"intent": {
"slots": {
"action": null,
"appointment": null,
"department": null,
"interactiveOption": null
},
"confirmationState": "None",
"name": "InteractiveMessageIntent",
"state": "InProgress"
},
"nluConfidence": 1
},
{
"intent": {
"slots": {},
"confirmationState": "None",
"name": "FallbackIntent",
"state": "InProgress"
}
}
],
"responseContentType": "text/plain; charset=utf-8",
"sessionState": {
"sessionAttributes": {},
"activeContexts": [],
"intent": {
"slots": {
"action": null,
"appointment": null,
"department": null,
"interactiveOption": null
},
"confirmationState": "None",
"name": "InteractiveMessageIntent",
"state": "InProgress"
},
"originatingRequestId": "abc2cbc8-4e60-4649-83c7-c317d4d21824"
},
"invocationSource": "DialogCodeHook",
"messageVersion": "1.0",
"bot": {
"aliasName": "TestBotAlias",
"aliasId": "TSTALIASID",
"name": "interactive-messaging-lexv2",
"version": "DRAFT",
"localeId": "en_US",
"id": "VGKIKY0S9G"
},
"inputMode": "Text"
}
Loading