-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into main v0.3.0
- Loading branch information
Showing
11 changed files
with
574 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
This example deploys a Banker Bot based on the [Lex V2 Workshop](https://amazonlex.workshop.aws/) | ||
which showcases various Lex V2 capabilities. | ||
|
||
The template shows how to attach a [Lambda Fulfillment Code Hook](https://docs.aws.amazon.com/lexv2/latest/dg/lambda.html) | ||
and how to configure [Text Conversation Logs](https://docs.aws.amazon.com/lexv2/latest/dg/conversation-logs-configure.html) | ||
|
||
Before you use this example, you should deploy the Custom Resource stack | ||
in your AWS account. The Custom Resource stack name is passed as a parameter | ||
when deploying this example. This stack name parameter is used to import the | ||
values of the Lambda function and the IAM role created by the Custom Resource. | ||
|
||
The bot in this example can be deployed using the | ||
[AWS Serverless Application Model Command Line Interface (SAM CLI)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html): | ||
|
||
```bash | ||
sam build --use-container | ||
sam deploy --guided | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html | ||
# https://aws.amazon.com/blogs/compute/optimizing-serverless-development-with-samconfig/ | ||
|
||
version=0.1 | ||
[default.deploy.parameters] | ||
stack_name = "lex-v2-cfn-cr-banker-bot" | ||
s3_bucket = "lex-v2-cfn-cr-artifacts-506886316466-us-east-1" | ||
s3_prefix = "sam-artifacts/lex-v2-cfn-banker-bot" | ||
region = "us-east-1" | ||
fail_on_empty_changeset = false | ||
confirm_changeset = true | ||
capabilities = "CAPABILITY_IAM CAPABILITY_AUTO_EXPAND" | ||
parameter_overrides = """ | ||
LexV2CfnCrStackName=lex-v2-cfn-cr \ | ||
""" |
118 changes: 118 additions & 0 deletions
118
examples/banker-bot/src/lambda_functions/banker_bot/lambda_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
""" | ||
MIT No Attribution | ||
Copyright 2021 Amazon Web Services | ||
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. | ||
""" | ||
|
||
# https://amazonlex.workshop.aws/banker-bot/create-first-lambda.en.files/BankingBotEnglish.py | ||
|
||
import json | ||
import random | ||
import decimal | ||
|
||
def random_num(): | ||
return(decimal.Decimal(random.randrange(1000, 50000))/100) | ||
|
||
def get_slots(intent_request): | ||
return intent_request['sessionState']['intent']['slots'] | ||
|
||
def get_slot(intent_request, slotName): | ||
slots = get_slots(intent_request) | ||
if slots is not None and slotName in slots and slots[slotName] is not None: | ||
return slots[slotName]['value']['interpretedValue'] | ||
else: | ||
return None | ||
|
||
def get_session_attributes(intent_request): | ||
sessionState = intent_request['sessionState'] | ||
if 'sessionAttributes' in sessionState: | ||
return sessionState['sessionAttributes'] | ||
|
||
return {} | ||
|
||
def elicit_intent(intent_request, session_attributes, message): | ||
return { | ||
'sessionState': { | ||
'dialogAction': { | ||
'type': 'ElicitIntent' | ||
}, | ||
'sessionAttributes': session_attributes | ||
}, | ||
'messages': [ message ] if message != None else None, | ||
'requestAttributes': intent_request['requestAttributes'] if 'requestAttributes' in intent_request else None | ||
} | ||
|
||
|
||
def close(intent_request, session_attributes, fulfillment_state, message): | ||
intent_request['sessionState']['intent']['state'] = fulfillment_state | ||
return { | ||
'sessionState': { | ||
'sessionAttributes': session_attributes, | ||
'dialogAction': { | ||
'type': 'Close' | ||
}, | ||
'intent': intent_request['sessionState']['intent'] | ||
}, | ||
'messages': [message], | ||
'sessionId': intent_request['sessionId'], | ||
'requestAttributes': intent_request['requestAttributes'] if 'requestAttributes' in intent_request else None | ||
} | ||
|
||
def CheckBalance(intent_request): | ||
session_attributes = get_session_attributes(intent_request) | ||
slots = get_slots(intent_request) | ||
account = get_slot(intent_request, 'accountType') | ||
#The account balance in this case is a random number | ||
#Here is where you could query a system to get this information | ||
balance = str(random_num()) | ||
text = "Thank you. The balance on your "+account+" account is $"+balance+" dollars." | ||
message = { | ||
'contentType': 'PlainText', | ||
'content': text | ||
} | ||
fulfillment_state = "Fulfilled" | ||
return close(intent_request, session_attributes, fulfillment_state, message) | ||
|
||
def FollowupCheckBalance(intent_request): | ||
session_attributes = get_session_attributes(intent_request) | ||
slots = get_slots(intent_request) | ||
account = get_slot(intent_request, 'accountType') | ||
#The account balance in this case is a random number | ||
#Here is where you could query a system to get this information | ||
balance = str(random_num()) | ||
text = "Thank you. The balance on your "+account+" account is $"+balance+" dollars." | ||
message = { | ||
'contentType': 'PlainText', | ||
'content': text | ||
} | ||
fulfillment_state = "Fulfilled" | ||
return close(intent_request, session_attributes, fulfillment_state, message) | ||
|
||
|
||
def dispatch(intent_request): | ||
intent_name = intent_request['sessionState']['intent']['name'] | ||
response = None | ||
# Dispatch to your bot's intent handlers | ||
if intent_name == 'CheckBalance': | ||
return CheckBalance(intent_request) | ||
elif intent_name == 'FollowupCheckBalance': | ||
return FollowupCheckBalance(intent_request) | ||
|
||
raise Exception('Intent with name ' + intent_name + ' not supported') | ||
|
||
def lambda_handler(event, context): | ||
response = dispatch(event) | ||
return response |
Empty file.
Oops, something went wrong.