Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Commit

Permalink
Update to version v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aassadza committed Oct 27, 2020
1 parent 763fe0e commit d921229
Show file tree
Hide file tree
Showing 51 changed files with 25,267 additions and 62 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
.staging
.DS_STORE
node_modules/
__pycache__
venv/
__pycache__/
.pytest_cache
geckodriver.log
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ 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).

## [1.3.0] - 2020-10-27
### Added
- A dynamic chatbot that demonstrates how to integrate a chatbot with a back-end database, such as Amazon DynamoDB, to build an automated order taking service (in this example, a pizza ordering service).
- When the customer starts their order, the chatbot retrieves the pizza menu from the back-end database, and displays it to the customer.
- The chatbot interacts with the customer to extract order details (for example, type and size of the pizza) and confirms the order.
- The order history is stored in a DynamoDB table, which helps facilitate a personalized customer experience.
- Functionality to automatically extract user's email, used by Amazon Cognito to authenticate the user with Amazon API Gateway, to use it as customerId.

## [1.2.0] - 2020-6-30
### Added
- Support for using API keys to get weather data
- Functionality to write customer feedback to DynamoDB
- Support for using API keys to get weather data.
- Functionality to write customer feedback to DynamoDB.

### Changed
- Synchronized audio and text response in sample web client
- Synchronized audio and text response in sample web client.

## [1.1.0] - 2020-3-30
### Added
Expand Down
1 change: 1 addition & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ underscore.string under the Massachusetts Institute of Technology (MIT) license
util under the Massachusetts Institute of Technology (MIT) license
uuid under the Massachusetts Institute of Technology (MIT) license
winston under the Massachusetts Institute of Technology (MIT) license
order-id under the Massachusetts Institute of Technology (MIT) license

The licenses for these third party components are included in LICENSE.txt
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The solution is deployed using a CloudFormation template with a lambda backed cu
Contains a nodejs module named b2.core that is used in train-model lambda function and polly-service lambda function.

**source/samples**
Includes four components, two sample lambda functions, a custom resource and a front-end web client. This code can be extended to add different functionalities to the bot.
Includes five components, three sample lambda functions, a custom resource and a front-end web client. This code can be extended to add different functionalities to the bot.

**source/services**
Includes source code for three lambda functions, core, custom-resource, and polly-service.
Expand All @@ -36,7 +36,7 @@ To make changes to the solution, download or clone this repo, update the source

### Prerequisites:
* [AWS Command Line Interface](https://aws.amazon.com/cli/)
* Node.js 10.x or later
* Node.js 12.x or later
* (Optional) [AccuWeather](https://developer.accuweather.com/) or [OpenWeather](https://openweathermap.org/api) API keys

### 1. Create an Amazon S3 Bucket
Expand Down Expand Up @@ -77,4 +77,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.removed api and email
Binary file modified deployment/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions deployment/build-s3-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ npm ci
zip -q -r9 $build_dist_dir/train-model.zip *
rm -fR $source_dir/services/train-model/node_modules
echo ""
echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Order Pizza"
echo "------------------------------------------------------------------------------"
cd $source_dir/samples/order-pizza
npm ci
zip -q -r9 $build_dist_dir/order-pizza.zip *
rm -fR $source_dir/samples/order-pizza/node_modules
echo ""
echo "------------------------------------------------------------------------------"
echo "[Packing] Sample Bot Weather Forecast"
echo "------------------------------------------------------------------------------"
Expand Down
142 changes: 138 additions & 4 deletions deployment/serverless-bot-framework-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Parameters:
MinLength: 0
MaxLength: 64
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: API key must only contain uppercase and lowercase letters and numbers
NoEcho: True
Default: ""

Expand Down Expand Up @@ -249,6 +250,72 @@ Resources:
Resource: !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${AWS::StackName}-weather-api-key
- !Ref "AWS::NoValue"

OrderPizzaFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: WebClientBucket
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource: !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'WebClient'
- /
- 'pizza-menus'
- /*
- PolicyName: DynamoDB
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- dynamodb:BatchGetItem
- dynamodb:BatchWriteItem
- dynamodb:PutItem
- dynamodb:DeleteItem
- dynamodb:GetItem
- dynamodb:Scan
- dynamodb:Query
- dynamodb:UpdateItem
Resource:
- !GetAtt 'DynamoPizzaOrders.Arn'
- !Join
- ''
- - !GetAtt 'DynamoPizzaOrders.Arn'
- /*
- !GetAtt 'DynamoPizzaMenus.Arn'
- !Join
- ''
- - !GetAtt 'DynamoPizzaMenus.Arn'
- /*
- PolicyName: CloudWatchLogs
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: !Join
- ':'
- - arn:aws:logs
- !Ref 'AWS::Region'
- !Ref 'AWS::AccountId'
- log-group:/aws/lambda/*

Logs:
Type: AWS::S3::Bucket
Expand Down Expand Up @@ -295,7 +362,7 @@ Resources:
-
SSM_REFERENCE_TO_API_KEY: !Ref "AWS::NoValue"
API_PROVIDER: !Ref "AWS::NoValue"

WriteAPIToSSMCustomResourceLambda:
Type: AWS::Lambda::Function
Condition: WeatherAPIChosen
Expand All @@ -307,7 +374,7 @@ Resources:
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "write-api-to-ssm-custom-resource.zip"]]
Description: Write APIKey to SSM

WriteKey:
Type: "Custom::WriteKey"
Condition: WeatherAPIChosen
Expand All @@ -330,7 +397,29 @@ Resources:
Timeout: 60
Environment:
Variables:
TABLE_NAME: !GetAtt DynamoLeaveFeedback.Arn
TABLE_NAME: !Ref 'DynamoLeaveFeedback'

KnowledgeOrderPizza:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "order-pizza.zip"]]
Description: Order Pizza Function
Handler: index.handler
MemorySize: 128
Environment:
Variables:
PIZZA_MENUS_INITIALIZATION_BUCKET: !Ref 'WebClient'
PIZZA_MENUS_INITIALIZATION_FILE: 'pizza-menus/pizza-menu.json'
PIZZA_ORDERS_TABLE: !Ref 'DynamoPizzaOrders'
PIZZA_MENUS_TABLE: !Ref 'DynamoPizzaMenus'
PIZZA_MENU_ID: 'main_menu_1'
PIZZA_ORDERS_GLOBAL_INDEX_NAME: 'customerId-orderTimestamp-index'
RE_INITIALIZE_MENUS_TABLE: 'false'
Role: !GetAtt 'OrderPizzaFunctionRole.Arn'
Runtime: nodejs12.x
Timeout: 180

DynamoLeaveFeedback:
Type: AWS::DynamoDB::Table
Expand All @@ -343,7 +432,46 @@ Resources:
KeySchema:
- AttributeName: "uuid"
KeyType: HASH
BillingMode: "PAY_PER_REQUEST"
BillingMode: "PAY_PER_REQUEST"

DynamoPizzaOrders:
Type: AWS::DynamoDB::Table
Properties:
SSESpecification:
SSEEnabled: true
AttributeDefinitions:
- AttributeName: orderId
AttributeType: S
- AttributeName: customerId
AttributeType: S
- AttributeName: orderTimestamp
AttributeType: N
KeySchema:
- AttributeName: orderId
KeyType: HASH
BillingMode: "PAY_PER_REQUEST"
GlobalSecondaryIndexes:
- IndexName: customerId-orderTimestamp-index
KeySchema:
- AttributeName: customerId
KeyType: HASH
- AttributeName: orderTimestamp
KeyType: RANGE
Projection:
ProjectionType: ALL

DynamoPizzaMenus:
Type: AWS::DynamoDB::Table
Properties:
SSESpecification:
SSEEnabled: true
AttributeDefinitions:
- AttributeName: menuId
AttributeType: S
KeySchema:
- AttributeName: menuId
KeyType: HASH
BillingMode: "PAY_PER_REQUEST"

Outputs:
WebClient:
Expand All @@ -370,3 +498,9 @@ Outputs:
LeaveFeedbackDynamoDBTable:
Description: DynamoDB table name for feedback
Value: !Select [1, !Split ['/', !GetAtt DynamoLeaveFeedback.Arn]]
KnowledgeOrderPizza:
Description: Knowledge order pizza function name.
Value: !Ref 'KnowledgeOrderPizza'
KnowledgeOrderPizzaArn:
Description: Knowledge order pizza function ARN.
Value: !GetAtt 'KnowledgeOrderPizza.Arn'
25 changes: 14 additions & 11 deletions deployment/serverless-bot-framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Resources:
Parameters:
WeatherAPIKey: !Ref WeatherAPIKey
WeatherAPIProvider: !Ref WeatherAPIProvider

LogsBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Expand Down Expand Up @@ -445,6 +445,7 @@ Resources:
Resource:
- !GetAtt 'SampleStack.Outputs.KnowledgeWeatherForecastArn'
- !GetAtt 'SampleStack.Outputs.KnowledgeLeaveFeedbackArn'
- !GetAtt 'SampleStack.Outputs.KnowledgeOrderPizzaArn'
- PolicyName: CloudWatchLogs
PolicyDocument:
Version: '2012-10-17'
Expand All @@ -460,15 +461,7 @@ Resources:
- !Ref 'AWS::Region'
- !Ref 'AWS::AccountId'
- log-group:/aws/lambda/*
- PolicyName: xrayLambdaPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "xray:PutTraceSegments"
- "xray:PutTelemetryRecords"
Effect: Allow
Resource: "*"

Core:
Type: AWS::Lambda::Function
Properties:
Expand Down Expand Up @@ -587,6 +580,15 @@ Resources:
Integration:
Type: AWS
IntegrationHttpMethod: POST
RequestTemplates:
"application/json": "{
\"body\" : $input.json('$'),
\"userInfo\" : {
\"email\" : \"$context.authorizer.claims.email\",
\"sub\" : \"$context.authorizer.claims.sub\"
}
}"
PassthroughBehavior: WHEN_NO_TEMPLATES
Uri: !Join
- ''
- - 'arn:aws:apigateway:'
Expand All @@ -598,7 +600,7 @@ Resources:
- ResponseParameters:
method.response.header.Access-Control-Allow-Origin: '''*'''
ResponseTemplates:
application/json: ''
application/json: ''
StatusCode: '200'
ResourceId: !Ref 'BotResourceCore'
RestApiId: !Ref 'BotApi'
Expand Down Expand Up @@ -944,6 +946,7 @@ Resources:
CognitoUserPoolId: !GetAtt 'SecurityStack.Outputs.CognitoUserPoolId'
CognitoUserPoolClientId: !GetAtt 'SecurityStack.Outputs.CognitoUserPoolClientId'
SampleWeatherForecastBotArn: !GetAtt 'SampleStack.Outputs.KnowledgeWeatherForecast'
SampleOrderPizzaBotArn: !GetAtt 'SampleStack.Outputs.KnowledgeOrderPizza'
TrainModelArn: !GetAtt 'TrainModel.Arn'
StackName: !Ref 'AWS::StackName'

Expand Down
Loading

0 comments on commit d921229

Please sign in to comment.