Skip to content

Instantly share code, notes, and snippets.

@babakc babakc/checkLex.py Secret
Created Dec 18, 2017

Embed
What would you like to do?
def elicit_slot(messageType, messageContent, slots, slotToElicit, completed):
response = {
"sessionAttributes": {
"Completed": completed
},
"dialogAction": {
"type": "ElicitSlot",
"message": {
"contentType": messageType,
"content": messageContent
},
"intentName": "ResetPW",
"slots": slots,
"slotToElicit": slotToElicit
}
}
return response
def delegate_slot(slots, completed):
response = {
"sessionAttributes": {
"Completed": completed
},
"dialogAction": {
"type": "Delegate",
"slots": slots
}
}
return response
def chkUserId(slots, sessionAttributes):
if((slots['UserID'] is None) or ((slots["UserID"] is not None) and (len(slots["UserID"]) != 6))):
messageContent = "That format seems incorrect. Let's try again. What is your user id?"
return elicit_slot("PlainText", messageContent, slots, "UserID", "None")
else:
return delegate_slot(slots, "userid")
def chkDob(slots, sessionAttributes):
if(slots["DOB"] is None):
messageContent = "That format seems incorrect. Let's try again. What is your Date of Birth?"
return elicit_slot("PlainText", messageContent, slots, "DOB", "userid")
else:
return delegate_slot(slots, "dob")
def chkMonth(slots, sessionAttributes, confirmation, outputDialogMode):
if(slots["MonthStarted"] is None):
messageContent = "That month seems incorrect. Let's try again. What month did you start?"
return elicit_slot("PlainText", messageContent, slots, "MonthStarted", "dob")
else:
return confirmIntent(slots, sessionAttributes, confirmation, outputDialogMode)
def confirmIntent(slots, sessionAttributes, confirmation, outputDialogMode):
if(confirmation == "None"):
endData = {
"dialogAction": {
"type": "ConfirmIntent",
"message": {
},
"intentName": "ResetPW",
"slots": slots
}
}
if(outputDialogMode == "Voice"):
endData["dialogAction"]["message"]["contentType"] = "SSML"
endData["dialogAction"]["message"]["content"] = "<speak>Just to confirm, your user id is <say-as interpret-as=\"digits\">" + slots["UserID"] + \
"</say-as>, your date of birth is " + \
slots["DOB"] + " and the month of your start date is " + \
slots["MonthStarted"] + ". Is that correct?</speak>"
else:
endData["dialogAction"]["message"]["contentType"] = "PlainText"
endData["dialogAction"]["message"]["content"] = "Just to confirm, your user id is " + slots["UserID"] + \
", your date of birth is " + \
slots["DOB"] + " and the month of your start date is " + \
slots["MonthStarted"] + ". Is that correct?"
elif((confirmation == "Denied")):
endData = {
"dialogAction": {
"type": "Close",
"fulfillmentState": "Failed",
"message": {
"contentType": "PlainText",
"content": "Please call back and try again."
}
}
}
else:
endData = delegate_slot(slots, "confirmed")
return endData
def lambda_handler(event, context):
slots = event['currentIntent']['slots']
sessionAttributes = event['sessionAttributes']
confirmation = event['currentIntent']["confirmationStatus"]
outputDialogMode = event["outputDialogMode"]
if(sessionAttributes is None or "Completed" not in sessionAttributes):
messageContent = "Sure, i can help with that! But first, i need to verify your identity. What is your user id?"
return elicit_slot("PlainText", messageContent, slots, "UserID", "None")
if(sessionAttributes["Completed"] == "None"):
return chkUserId(slots, sessionAttributes)
if(sessionAttributes["Completed"] == "userid"):
return chkDob(slots, sessionAttributes)
if(sessionAttributes["Completed"] == "dob"):
return chkMonth(slots, sessionAttributes, confirmation, outputDialogMode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.