Skip to content

Commit

Permalink
Update to version v5.2.1
Browse files Browse the repository at this point in the history
Update to version v5.2.1
  • Loading branch information
tabdunabi committed Sep 15, 2022
2 parents 771b4b4 + e0c91e8 commit 2de5fed
Show file tree
Hide file tree
Showing 44 changed files with 1,460 additions and 3,201 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ config.json
.idea/




# ignore VS Code specific configs and environments
.devcontainer/
.vscode/
utilities/migration.md

Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
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).

## [5.2.1] - 2022-09-15

### Updated

- Security patches for npm packages.
- `safe-eval` npm package was replaced by `vm2` package, and `node-sass` was replaced by `sass` package.
- `multer` npm package removed.
- Node.js Lambda runtime to Nodejs.16

### Fixed

- Error when the image URL is not provided in the Response card.

## [5.2.0] - 2022-07-14

### Added
Expand Down
2 changes: 0 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ mini-css-extract-plugin under the Massachusetts Institute of Technology (MIT) li
minimist under the Massachusetts Institute of Technology (MIT) license
moment under the Massachusetts Institute of Technology (MIT) license
morgan under the Massachusetts Institute of Technology (MIT) license
multer under the Massachusetts Institute of Technology (MIT) license
node-sass under the Massachusetts Institute of Technology (MIT) license
ora under the Massachusetts Institute of Technology (MIT) license
progress-bar-webpack-plugin under the Massachusetts Institute of Technology (MIT) license
pug under the Massachusetts Institute of Technology (MIT) license
Expand Down
110 changes: 35 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,96 +1,60 @@
# A Question and Answer Bot Using Amazon Lex and Amazon Alexa

> Build a chat bot to answer questions.
# QnABot on AWS

## Overview

This repository contains code for the QnABot, described in the AWS AI blog post [“Creating a Question and Answer Bot with Amazon Lex and Amazon Alexa”](https://aws.amazon.com/blogs/ai/creating-a-question-and-answer-bot-with-amazon-lex-and-amazon-alexa/).

Refer to [Getting Started](#getting-started) to launch your own QnABot, or [Automated Deployment](https://docs.aws.amazon.com/solutions/latest/qnabot-on-aws/automated-deployment.html) for detailed implementation instructions.

The 5.1.0 release of QnABot provides support for a new mechanism where a Question can set a Lex session attribute.

In prior versions, the use of handlebars in an answer could set a session attribute. For example, the following

"{{setSessionAttr ‘attributeName' ‘attributeValue’}}""
QnABot on AWS is a multi-channel, multi-language conversational interface (chatbot) that responds to your customer’s questions, answers, and feedback. It allows you to deploy a fully functional chatbot across multiple channels including chat, voice, SMS, and Amazon Alexa. The solution’s content management environment, and contact center integration wizard allow you to set up and customize an environment that provides the following benefits:

will set the an attribute called “attributeName” to the value “attributeValue”. The drawback in this approach is that the attribute value could not itself contain nested handle bars.
- Enhance your customer’s experience by providing personalized tutorials and question and answer support with intelligent multi-part interaction

In 5.1.0, a Question can now define a set of name/value pairs to set as session attributes when the answer is returned. You’ll see a new field to set a name/value pair plus an “Add” button to define additional name/value pairs and a button to delete a name/value pair. The Value field can contain handlebar statements as well.
- Reduce call center wait times by automating customer support workflows

The attribute name can be a simple name like “myAttribute” or a complex name like “myAttribute.subAttribute”. Using the dot notation an attribute several levels deep can be set. Note that one can overwrite reserved session attribute names. Avoid using “appContext” or “qnabotcontext” as attribute names. Setting these may have adverse effects on the system.

Note, the handlebar syntax still works just as it did before. The question configuration just has a new option.
- Implement the latest machine learning technology to create engaging, human-like interactions for chatbots

## Architecture Overview

Deploying this solution with the default parameters builds the following environment in the AWS Cloud.

![Architecture](docs/architecture.png)

Figure 1: QnABot on AWS architecture on AWS

The AWS CloudFormation template deploys the following workflows and services:

1. The admin deploys the solution into their AWS account, opens the Content Designer UI, and uses Amazon Cognito to authenticate.
1. The admin deploys the solution into their AWS account, opens the Content Designer UI, and uses [Amazon Cognito](http://aws.amazon.com/cognito/) to authenticate.

2. After authentication, [Amazon CloudFront](http://aws.amazon.com/cloudfront/) and [Amazon S3](http://aws.amazon.com/s3/) deliver the contents of the Content Designer UI.

2. After authentication, Amazon CloudFront
and Amazon S3 deliver the contents of the Content Designer UI.
3. The admin configures questions and answers in the Content Designer and the UI sends requests to [Amazon API Gateway](http://aws.amazon.com/api-gateway/) to save the questions and answers.

3. The admin configures questions and answers in the Content Designer and the UI sends requests to Amazon API Gateway to save the questions and answers.
4. The `Content Designer` [AWS Lambda](http://aws.amazon.com/lambda/) function saves the input in [Amazon OpenSearch Service](http://aws.amazon.com/opensearch-service/) (successor to Amazon ElasticSearch Service) in a questions bank index.

4. The Content Designer AWS Lambda
function saves the input in Amazon OpenSearch Service (successor to Amazon ElasticSearch Service) in a questions bank index.
5. Users of the chatbot interact with [Amazon Lex](http://aws.amazon.com/lex/) via the web client UI or Amazon Connect.

5. Users of the chatbot interact with Amazon Lex via the web client UI or Amazon Connect.
6. Amazon Lex forwards requests to the `Bot Fulfillment` AWS Lambda function. (Users can also send requests to this Lambda function via [Amazon Alexa](https://developer.amazon.com/en-US/alexa) devices).

6. Amazon Lex forwards requests to the AWS Lambda (Bot Fulfillment) function. (Users can also send requests to this Lambda function via Amazon Alexa devices).
7. The `Bot Fulfillment` AWS Lambda function takes the users input and uses [Amazon Comprehend](http://aws.amazon.com/comprehend/) and [Amazon Translate](http://aws.amazon.com/translate/) (if necessary) to translate non-English requests to English and then looks up the answer in in Amazon OpenSearch Service. If Amazon Kendra index is configured and provided at the time of deployment, the Bot Fulfillment function also sends a request to the [Amazon Kendra](http://aws.amazon.com/kendra/) index.

7. The Bot Fulfillment function takes the users input and uses Amazon Comprehend
and Amazon Translate (if necessary) to translate non-English requests to English and then looks up the answer in in Amazon OpenSearch Service. If Amazon Kendra index is configured and provided at the time of deployment, the Bot Fulfillment function also sends a request to the Amazon Kendra index.
8. User interactions with the `Bot Fulfillment` function generate logs and metrics data, which is sent to [Amazon Kinesis Data Firehose](http://aws.amazon.com/kinesis/data-firehose/) then to Amazon S3 for later data analysis.

8. User interactions with Bot Fulfillment functions generate logs and metrics data, which is sent to Amazon Kinesis Data Firehose then to Amazon S3 for later data analysis.
Refer to the [implementation guide](https://docs.aws.amazon.com/solutions/latest/qnabot-on-aws) for detailed instructions on deploying QnABot in your AWS account.

## Upgrade Notes
Alternatively, if you want to custom deploy QnABot on AWS, refer to the details below.

During an upgrade, we recommend that existing QnABot content first be exported and downloaded from the Content Designer prior to
the upgrade. In this release we expect upgrade to be smooth but just in case you should always have your QnABot content preserved.
## Custom deployment of QnABot on AWS

## Prerequisites
### Environment Prerequisites

- Run Linux. (tested on Amazon Linux)
- Install npm >7.10.0 and node >12.15.1. ([instructions](https://nodejs.org/en/download/))
- Install npm >7.10.0 and node >16.X.X ([instructions](https://nodejs.org/en/download/))
- Clone this repo.
- Set up an AWS account. ([instructions](https://AWS.amazon.com/free/?sc_channel=PS&sc_campaign=acquisition_US&sc_publisher=google&sc_medium=cloud_computing_b&sc_content=AWS_account_bmm_control_q32016&sc_detail=%2BAWS%20%2Baccount&sc_category=cloud_computing&sc_segment=102882724242&sc_matchtype=b&sc_country=US&s_kwcid=AL!4422!3!102882724242!b!!g!!%2BAWS%20%2Baccount&ef_id=WS3s1AAAAJur-Oj2:20170825145941:s))
- Set up an AWS account. ([instructions](https://AWS.amazon.com/free/))
- Configure AWS CLI and a local credentials file. ([instructions](https://docs.AWS.amazon.com/cli/latest/userguide/cli-chap-welcome.html))

## Getting Started
### Build a version

Two approaches can be used to get started. Deploy from pre-created repositories or clone the repo and build a version yourself.
Navigate to the root directory of QnABot (directory will be created once you have cloned this repo).

### Pre-created deployment

Sign in to the AWS Management Console and select the button to launch
the `qnabot-onaws-main.template` AWS CloudFormation template.
Alternatively, you can download the template as a starting point for your
own implementation. The template launches in the US East (N. Virginia) Region by default. To launch the solution in a
different AWS Region, use the Region selector in the console navigation bar.

<a target="_blank" href="https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=QnABot&templateURL=https://solutions-reference.s3.amazonaws.com/qnabot-on-aws/latest/qnabot-on-aws-main.template"><span><img height="24px" src="https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png"/></span></a>

The solution is supported in the following Regions:

| Region |
| ----------------- |
| Northern Virginia |
| Oregon |
| Ireland |
| Sydney |
| London |
| Frankfurt |
| Singapore |
| Tokyo |
| Canada Central |

### Clone the git repo and build a version

First, install all prerequisites:
Install node.js moodules of QnABot:

```shell
npm install
Expand All @@ -102,7 +66,7 @@ Next, set up your configuration file:
npm run config
```

now edit config.json with you information.
now edit `config.json` for the following parameters:

| param | description |
| ------------------ | --------------------------------------------------------------------------- |
Expand All @@ -111,13 +75,13 @@ now edit config.json with you information.
| namespace | a logical name space to run your templates in such as dev, test and/or prod |
| devEmail(required) | the email to use when creating admin users in automated stack launches |

Next, use the following command to launch a CloudFormation template to create the S3 bucket to be used for lambda code and CloudFormation templates. Wait for this template to complete (you can watch progress from the command line or [AWS CloudFormation console](https://console.AWS.amazon.com/cloudformation/home))
Next, use the following command to launch a CloudFormation template to create the S3 bucket to be used for Lambda code and CloudFormation templates. Wait for this template to complete (you can watch progress from the command line or [AWS CloudFormation console](https://console.AWS.amazon.com/cloudformation/home))

```shell
npm run bootstrap
```

Finally, use the following command to launch template to deploy the QnAbot in your AWS account. When the stack has completed you will be able to log into the Designer UI (The URL is an output of the template). A temporary password to the email in your config.json:
Finally, use the following command to launch template to deploy the QnABot in your AWS account. When the stack has completed you will be able to log into the Designer UI (The URL is an output of the template). A temporary password to the email in your config.json:

```shell
npm run up
Expand All @@ -129,12 +93,12 @@ If you have an existing stack you can run the following to update your stack:
npm run update
```

#### Designer UI Compatibility
## Designer UI Compatibility

Currently the only browsers supported are:

- Chrome
- FireFox
- Firefox
We are currently working on adding Microsoft Edge support.

## Built With
Expand All @@ -144,18 +108,14 @@ Currently the only browsers supported are:

## License

Refer to [LICENSE.md](LICENSE.md) file for details.
Refer to [LICENSE.txt](LICENSE.txt) file for details.

## New features

Refer to [CHANGELOG.md](CHANGELOG.md) file for details of new features in each version.

A [workshop](https://qnabot.workshop.aws) is available
that will walk you through QnABot features.

## Known Behavior

When deploying the Cloudformation stack rarely, the custom resource creating Amazon OpenSearch Service resources timesout and causes the deployment fail. Deleting the failed deployment and re-deploying the Cloudformation stack fixes this issue.
A [workshop](https://qnabot.workshop.aws) is also available
that walks you through QnABot features.

---

Expand Down
36 changes: 22 additions & 14 deletions docs/lambda_hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ QnABot comes with a simple Lambda Hook function example that you can explore:
1. Log in to the Content Designer, and choose **Import** from the tools menu ( ☰ ).
2. Open Examples/Extensions, and choose **LOAD** from the ‘GreetingHook’ example.

![Greeting Hook Example](./images/GreetingHookExample.jpg)
3. When the import job has completed, return to the edit page, and examine the item “GreetingHookExample.” Note that the Lambda Hook field is populated with a Lambda function name.
4. Use the Web UI to say “_What are lambda hooks?_”. Note that the answer is prepended with a dynamic greeting based on the current time of day – in this case ‘_good afternoon_’:
![Greeting Hook Web UI Example](./images/WebUiGreetingHook.jpg)
5. Inspect the example function (ExampleJSLambdahook) using the [AWS Lambda console](https://console.aws.amazon.com/lambda/home?region=us-east-1#/functions/qna-QnABot-hello?tab=graph).
![Greeting Hook Example](./images/GreetingHookExample.jpg) 3. When the import job has completed, return to the edit page, and examine the item “GreetingHookExample.” Note that the Lambda Hook field is populated with a Lambda function name. 4. Use the Web UI to say “_What are lambda hooks?_”. Note that the answer is prepended with a dynamic greeting based on the current time of day – in this case ‘_good afternoon_’:
![Greeting Hook Web UI Example](./images/WebUiGreetingHook.jpg) 5. Inspect the example function (ExampleJSLambdahook) using the [AWS Lambda console](https://console.aws.amazon.com/lambda/home?region=us-east-1#/functions/qna-QnABot-hello?tab=graph).

Choose **Lambda Hooks** from the Content Designer tools menu ( ****) to display additional information to help you create your own Lambda hook functions.

---------
---

The Lambda hook receives the current QnABot response in the `res` attribute of the input event of your Lambda handler.
You can override values from this event in your Lambda hook code.
Expand Down Expand Up @@ -45,7 +42,7 @@ def handler(event, context):

In Content Designer, use the following syntax to reference your Lambda hook function:

- QNA:EXT*LambdaHookName (e.g _QNA:EXTMyLambdaHook_)
- QNA:EXT\*LambdaHookName (e.g _QNA:EXTMyLambdaHook_)

The ARN of your installed lambda hook will be referenced at runtime by the QnABot Fulfillment function using environment variables. I.e. the fulfillment function is set up (during installation) with environment variable `EXTMyLambdaHook` and the value is the ARN of your installed function.
Using the environment variable indirection is preferable to using your function ARN, since you can maintain separate function instances for different QnABot stacks / environments, and you can easily export/import content that does not contain ARN references to specific function instances in specific accounts and regions.
Expand All @@ -54,17 +51,28 @@ Using the environment variable indirection is preferable to using your function

Add importable content packages in the `./ui_imports/content` folder using two files as follows:

- \<name>.json -- the JSON representation of the QnA documents to be imported (can be a file that was previous exported from Content Designer.
- \<name>.txt -- a short tagline description of the content that will be displayed in the Content Designer listing.
- \<name>.json -- the JSON representation of the QnA documents to be imported (can be a file that was previous exported from Content Designer.
- \<name>.txt -- a short tagline description of the content that will be displayed in the Content Designer listing.

## Preprocessing and postprocessing Lambda hooks
## Pre-processing and post-processing Lambda hooks

You can also add Lambda hooks globally that run before (preprocessing) and after every question is run via the settings page.
A Lambda hook can be called as the first step in the fulfillment pipeline (PREPROCESS), as part of processing a specific question (HOOK) or after processing has completed (POSTPROCESS ) and before the `userInfo` is saved to DynamoDB and the result has been sent back to the client.

You can add pre-processing and post-processing Lambda hooks (that run before preprocessing and after every question is run) via the `Settings` page.

![settings hooks](./images/pre_post_hook.png)

## Lambda Hook SDK (Javascript)

Lambda hook SDK hides the internal and lower-level complexities of modifying the QnABot request and response, and provides a simple high-level code layer.
For more details on the supported methods refer to the [Lambda Hook SDK readme](../lambda_hook_sdk.MD).

Additionally, with a QnABot deployment, the Lambda Hook SDK (Javascript) is also available as a Lambda Layer (with the layer name as: `JsLambdaHookSDK`), which can be included in a custom Lambda function.

For an example implementation using Lambda Hook -- refer to this [example](../../templates/examples/extensions/js_lambda_hooks/CreateRecentTopicsResponse/CreateRecentTopicsResponse.js) javascript file.

## [](#notes)NOTES

- The `Makefile` residing in the extensions folder creates separate zip packages for each separate Lambda hook function
- Lambda hook functions use nodejs12.x or python3.9 only at this time
- Lambda hook functions will be allocated 2048MB memory (defined in index.js)
- The `Makefile` residing in the extensions folder creates separate zip packages for each separate Lambda hook function
- Lambda hook functions use nodejs12.x or python3.9 only at this time
- Lambda hook functions will be allocated 2048MB memory (defined in index.js)
Loading

0 comments on commit 2de5fed

Please sign in to comment.