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

Commit d921229

Browse files
committed
Update to version v1.3.0
1 parent 763fe0e commit d921229

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+25267
-62
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
.staging
99
.DS_STORE
1010
node_modules/
11-
__pycache__
11+
venv/
12+
__pycache__/
13+
.pytest_cache
14+
geckodriver.log

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.3.0] - 2020-10-27
8+
### Added
9+
- 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).
10+
- When the customer starts their order, the chatbot retrieves the pizza menu from the back-end database, and displays it to the customer.
11+
- The chatbot interacts with the customer to extract order details (for example, type and size of the pizza) and confirms the order.
12+
- The order history is stored in a DynamoDB table, which helps facilitate a personalized customer experience.
13+
- Functionality to automatically extract user's email, used by Amazon Cognito to authenticate the user with Amazon API Gateway, to use it as customerId.
14+
715
## [1.2.0] - 2020-6-30
816
### Added
9-
- Support for using API keys to get weather data
10-
- Functionality to write customer feedback to DynamoDB
17+
- Support for using API keys to get weather data.
18+
- Functionality to write customer feedback to DynamoDB.
1119

1220
### Changed
13-
- Synchronized audio and text response in sample web client
21+
- Synchronized audio and text response in sample web client.
1422

1523
## [1.1.0] - 2020-3-30
1624
### Added

NOTICE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ underscore.string under the Massachusetts Institute of Technology (MIT) license
4646
util under the Massachusetts Institute of Technology (MIT) license
4747
uuid under the Massachusetts Institute of Technology (MIT) license
4848
winston under the Massachusetts Institute of Technology (MIT) license
49+
order-id under the Massachusetts Institute of Technology (MIT) license
4950

5051
The licenses for these third party components are included in LICENSE.txt

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The solution is deployed using a CloudFormation template with a lambda backed cu
2121
Contains a nodejs module named b2.core that is used in train-model lambda function and polly-service lambda function.
2222

2323
**source/samples**
24-
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.
24+
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.
2525

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

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

4242
### 1. Create an Amazon S3 Bucket
@@ -77,4 +77,4 @@ Unless required by applicable law or agreed to in writing, software
7777
distributed under the License is distributed on an "AS IS" BASIS,
7878
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7979
See the License for the specific language governing permissions and
80-
limitations under the License.
80+
limitations under the License.removed api and email

deployment/architecture.png

-9.99 KB
Loading

deployment/build-s3-dist.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ npm ci
107107
zip -q -r9 $build_dist_dir/train-model.zip *
108108
rm -fR $source_dir/services/train-model/node_modules
109109
echo ""
110+
echo ""
111+
echo "------------------------------------------------------------------------------"
112+
echo "[Packing] Order Pizza"
113+
echo "------------------------------------------------------------------------------"
114+
cd $source_dir/samples/order-pizza
115+
npm ci
116+
zip -q -r9 $build_dist_dir/order-pizza.zip *
117+
rm -fR $source_dir/samples/order-pizza/node_modules
118+
echo ""
110119
echo "------------------------------------------------------------------------------"
111120
echo "[Packing] Sample Bot Weather Forecast"
112121
echo "------------------------------------------------------------------------------"

deployment/serverless-bot-framework-sample.yaml

Lines changed: 138 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Parameters:
3232
MinLength: 0
3333
MaxLength: 64
3434
AllowedPattern: '[a-zA-Z0-9]*'
35+
ConstraintDescription: API key must only contain uppercase and lowercase letters and numbers
3536
NoEcho: True
3637
Default: ""
3738

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

253+
OrderPizzaFunctionRole:
254+
Type: AWS::IAM::Role
255+
Properties:
256+
AssumeRolePolicyDocument:
257+
Statement:
258+
- Effect: Allow
259+
Principal:
260+
Service:
261+
- lambda.amazonaws.com
262+
Action:
263+
- sts:AssumeRole
264+
Policies:
265+
- PolicyName: WebClientBucket
266+
PolicyDocument:
267+
Version: '2012-10-17'
268+
Statement:
269+
- Effect: Allow
270+
Action:
271+
- s3:GetObject
272+
Resource: !Join
273+
- ''
274+
- - 'arn:aws:s3:::'
275+
- !Ref 'WebClient'
276+
- /
277+
- 'pizza-menus'
278+
- /*
279+
- PolicyName: DynamoDB
280+
PolicyDocument:
281+
Version: '2012-10-17'
282+
Statement:
283+
- Effect: Allow
284+
Action:
285+
- dynamodb:BatchGetItem
286+
- dynamodb:BatchWriteItem
287+
- dynamodb:PutItem
288+
- dynamodb:DeleteItem
289+
- dynamodb:GetItem
290+
- dynamodb:Scan
291+
- dynamodb:Query
292+
- dynamodb:UpdateItem
293+
Resource:
294+
- !GetAtt 'DynamoPizzaOrders.Arn'
295+
- !Join
296+
- ''
297+
- - !GetAtt 'DynamoPizzaOrders.Arn'
298+
- /*
299+
- !GetAtt 'DynamoPizzaMenus.Arn'
300+
- !Join
301+
- ''
302+
- - !GetAtt 'DynamoPizzaMenus.Arn'
303+
- /*
304+
- PolicyName: CloudWatchLogs
305+
PolicyDocument:
306+
Version: '2012-10-17'
307+
Statement:
308+
- Effect: Allow
309+
Action:
310+
- logs:CreateLogGroup
311+
- logs:CreateLogStream
312+
- logs:PutLogEvents
313+
Resource: !Join
314+
- ':'
315+
- - arn:aws:logs
316+
- !Ref 'AWS::Region'
317+
- !Ref 'AWS::AccountId'
318+
- log-group:/aws/lambda/*
252319

253320
Logs:
254321
Type: AWS::S3::Bucket
@@ -295,7 +362,7 @@ Resources:
295362
-
296363
SSM_REFERENCE_TO_API_KEY: !Ref "AWS::NoValue"
297364
API_PROVIDER: !Ref "AWS::NoValue"
298-
365+
299366
WriteAPIToSSMCustomResourceLambda:
300367
Type: AWS::Lambda::Function
301368
Condition: WeatherAPIChosen
@@ -307,7 +374,7 @@ Resources:
307374
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
308375
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "write-api-to-ssm-custom-resource.zip"]]
309376
Description: Write APIKey to SSM
310-
377+
311378
WriteKey:
312379
Type: "Custom::WriteKey"
313380
Condition: WeatherAPIChosen
@@ -330,7 +397,29 @@ Resources:
330397
Timeout: 60
331398
Environment:
332399
Variables:
333-
TABLE_NAME: !GetAtt DynamoLeaveFeedback.Arn
400+
TABLE_NAME: !Ref 'DynamoLeaveFeedback'
401+
402+
KnowledgeOrderPizza:
403+
Type: AWS::Lambda::Function
404+
Properties:
405+
Code:
406+
S3Bucket: !Join ["-", [!FindInMap ["SourceCode", "General", "S3Bucket"], Ref: "AWS::Region"]]
407+
S3Key: !Join ["/", [!FindInMap ["SourceCode", "General", "KeyPrefix"], "order-pizza.zip"]]
408+
Description: Order Pizza Function
409+
Handler: index.handler
410+
MemorySize: 128
411+
Environment:
412+
Variables:
413+
PIZZA_MENUS_INITIALIZATION_BUCKET: !Ref 'WebClient'
414+
PIZZA_MENUS_INITIALIZATION_FILE: 'pizza-menus/pizza-menu.json'
415+
PIZZA_ORDERS_TABLE: !Ref 'DynamoPizzaOrders'
416+
PIZZA_MENUS_TABLE: !Ref 'DynamoPizzaMenus'
417+
PIZZA_MENU_ID: 'main_menu_1'
418+
PIZZA_ORDERS_GLOBAL_INDEX_NAME: 'customerId-orderTimestamp-index'
419+
RE_INITIALIZE_MENUS_TABLE: 'false'
420+
Role: !GetAtt 'OrderPizzaFunctionRole.Arn'
421+
Runtime: nodejs12.x
422+
Timeout: 180
334423

335424
DynamoLeaveFeedback:
336425
Type: AWS::DynamoDB::Table
@@ -343,7 +432,46 @@ Resources:
343432
KeySchema:
344433
- AttributeName: "uuid"
345434
KeyType: HASH
346-
BillingMode: "PAY_PER_REQUEST"
435+
BillingMode: "PAY_PER_REQUEST"
436+
437+
DynamoPizzaOrders:
438+
Type: AWS::DynamoDB::Table
439+
Properties:
440+
SSESpecification:
441+
SSEEnabled: true
442+
AttributeDefinitions:
443+
- AttributeName: orderId
444+
AttributeType: S
445+
- AttributeName: customerId
446+
AttributeType: S
447+
- AttributeName: orderTimestamp
448+
AttributeType: N
449+
KeySchema:
450+
- AttributeName: orderId
451+
KeyType: HASH
452+
BillingMode: "PAY_PER_REQUEST"
453+
GlobalSecondaryIndexes:
454+
- IndexName: customerId-orderTimestamp-index
455+
KeySchema:
456+
- AttributeName: customerId
457+
KeyType: HASH
458+
- AttributeName: orderTimestamp
459+
KeyType: RANGE
460+
Projection:
461+
ProjectionType: ALL
462+
463+
DynamoPizzaMenus:
464+
Type: AWS::DynamoDB::Table
465+
Properties:
466+
SSESpecification:
467+
SSEEnabled: true
468+
AttributeDefinitions:
469+
- AttributeName: menuId
470+
AttributeType: S
471+
KeySchema:
472+
- AttributeName: menuId
473+
KeyType: HASH
474+
BillingMode: "PAY_PER_REQUEST"
347475

348476
Outputs:
349477
WebClient:
@@ -370,3 +498,9 @@ Outputs:
370498
LeaveFeedbackDynamoDBTable:
371499
Description: DynamoDB table name for feedback
372500
Value: !Select [1, !Split ['/', !GetAtt DynamoLeaveFeedback.Arn]]
501+
KnowledgeOrderPizza:
502+
Description: Knowledge order pizza function name.
503+
Value: !Ref 'KnowledgeOrderPizza'
504+
KnowledgeOrderPizzaArn:
505+
Description: Knowledge order pizza function ARN.
506+
Value: !GetAtt 'KnowledgeOrderPizza.Arn'

deployment/serverless-bot-framework.yaml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Resources:
135135
Parameters:
136136
WeatherAPIKey: !Ref WeatherAPIKey
137137
WeatherAPIProvider: !Ref WeatherAPIProvider
138-
138+
139139
LogsBucket:
140140
Type: AWS::S3::Bucket
141141
DeletionPolicy: Retain
@@ -445,6 +445,7 @@ Resources:
445445
Resource:
446446
- !GetAtt 'SampleStack.Outputs.KnowledgeWeatherForecastArn'
447447
- !GetAtt 'SampleStack.Outputs.KnowledgeLeaveFeedbackArn'
448+
- !GetAtt 'SampleStack.Outputs.KnowledgeOrderPizzaArn'
448449
- PolicyName: CloudWatchLogs
449450
PolicyDocument:
450451
Version: '2012-10-17'
@@ -460,15 +461,7 @@ Resources:
460461
- !Ref 'AWS::Region'
461462
- !Ref 'AWS::AccountId'
462463
- log-group:/aws/lambda/*
463-
- PolicyName: xrayLambdaPolicy
464-
PolicyDocument:
465-
Version: "2012-10-17"
466-
Statement:
467-
- Action:
468-
- "xray:PutTraceSegments"
469-
- "xray:PutTelemetryRecords"
470-
Effect: Allow
471-
Resource: "*"
464+
472465
Core:
473466
Type: AWS::Lambda::Function
474467
Properties:
@@ -587,6 +580,15 @@ Resources:
587580
Integration:
588581
Type: AWS
589582
IntegrationHttpMethod: POST
583+
RequestTemplates:
584+
"application/json": "{
585+
\"body\" : $input.json('$'),
586+
\"userInfo\" : {
587+
\"email\" : \"$context.authorizer.claims.email\",
588+
\"sub\" : \"$context.authorizer.claims.sub\"
589+
}
590+
}"
591+
PassthroughBehavior: WHEN_NO_TEMPLATES
590592
Uri: !Join
591593
- ''
592594
- - 'arn:aws:apigateway:'
@@ -598,7 +600,7 @@ Resources:
598600
- ResponseParameters:
599601
method.response.header.Access-Control-Allow-Origin: '''*'''
600602
ResponseTemplates:
601-
application/json: ''
603+
application/json: ''
602604
StatusCode: '200'
603605
ResourceId: !Ref 'BotResourceCore'
604606
RestApiId: !Ref 'BotApi'
@@ -944,6 +946,7 @@ Resources:
944946
CognitoUserPoolId: !GetAtt 'SecurityStack.Outputs.CognitoUserPoolId'
945947
CognitoUserPoolClientId: !GetAtt 'SecurityStack.Outputs.CognitoUserPoolClientId'
946948
SampleWeatherForecastBotArn: !GetAtt 'SampleStack.Outputs.KnowledgeWeatherForecast'
949+
SampleOrderPizzaBotArn: !GetAtt 'SampleStack.Outputs.KnowledgeOrderPizza'
947950
TrainModelArn: !GetAtt 'TrainModel.Arn'
948951
StackName: !Ref 'AWS::StackName'
949952

0 commit comments

Comments
 (0)