Created
September 13, 2018 19:04
-
-
Save soundmasteraj/eb19c5465690df559b57f981c4abf7c9 to your computer and use it in GitHub Desktop.
Tri boolean handling yes, no and doesn't exist with the AWS Lambda session object attributes and Alexa Endpoint
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
''' | |
(Python) | |
Using yes and no (intents) worked very well for me. | |
I enjoy coding for yes and no intents. | |
I found that users enjoy the experience and understand it intuitively. | |
The below variables derive from: | |
... | |
attributes_in = session['attributes'] <-- if session.get('attributes') <-- session obj | |
attributes_in = {} <-- if not session.get('attributes') <-- session obj | |
... | |
intent_name <- request['intent']['name'] <-- event['request'] <-- event obj | |
''' | |
#... Start keeping track of happiness. | |
# If they are already happy, keep going. | |
elif intent_name == "AMAZON.YesIntent": | |
cur_attributes_in = attributes_in | |
if not cur_attributes_in.get('userIsHappy'): | |
cur_attributes_in.update({'userIsHappy': True}) | |
return doSomethingCoolFunc(request, cur_attributes_in) | |
else: | |
return doSomethingCoolFunc(request, cur_attributes_in) | |
#... If they are unhappy once, try again. | |
# If they were never happy or became unhappy twice, exit gracefully. | |
elif intent_name == "AMAZON.NoIntent": | |
cur_attributes_in = attributes_in | |
if cur_attributes_in.get('userIsHappy') != None: | |
if cur_attributes_in.get('userIsHappy') == False: | |
return do_graceful_stop({},{}) | |
else: | |
cur_attributes_in.update({'userIsHappy': False}) | |
return trySomethingElseFunc(request, cur_attributes_in) | |
else: | |
return do_graceful_stop({},{}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment