I am building an agent in Amazon Lex with around 3 intents. All the 3 intents have a variable which has been ticked as 'required', meaning the agent has to prompt for those variables when the user query is missing it.
However when I am using a lambda function as codehook validation the , function gets triggered without prompting for the missing variable.
For example: Intent which describes call notes from a call with a specific person:
The prompt is " Specify the name of the person whose notes you want to see'
The objective of the lambda function is to print out "Call notes for the person is XYZ'
When I don't use any lambda function through codehook validation, I get a prompt for the name of the person,
but when I use codehook validation, the lambda function gets triggered and I get the reply as "Call notes for None is XYZ".
None because , there wasn't any mention of the person's name in the user query nor am I getting prompted for the person's name.
Can anybody help regarding this? I have tried all sorts of modifications in the lambda function , but shouldn't the prompt be an independent functionality from the lambda function?
I have been browsing and trying things regarding this since 2~3 days and have hit a dead end.
This is happening because Lambda initialization and validation happens before Slot filling in Amazon Lex. You can still check that user have provided the "person" slot in DialogCodeHook i.e validation part. Something like below code will get your work done:
def build_validation_result(is_valid, violated_slot, message_content):
if message_content == None:
return {
'isValid': is_valid,
'violatedSlot': violated_slot
}
return {
'isValid': is_valid,
'violatedSlot': violated_slot,
'message': {'contentType': 'PlainText', 'content': message_content}
}
def validate_person(person):
# apply validations here
if person is None:
return build_validation_result(False, 'person', 'Please enter the person name')
return build_validation_result(True, None, None)
def get_notes(intent_request):
source = intent_request['invocationSource']
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
slots = intent_request['currentIntent']['slots']
person = slots['person']
if source == 'DialogCodeHook':
# check existence of "person" slot
validation_result = validate_person(person)
if not validation_result['isValid']:
slots[ticket_validation_result['violatedSlot']] = None
return elicit_slot(
output_session_attributes,
intent_request['currentIntent']['name'],
slots,
validation_result['violatedSlot'],
validation_result['message']
)
return delegate(output_session_attributes, slots)
If the "person" slot is empty, user will be prompted the error message. This way you don't need to tick on "Required" on the slot. This was the only workaround I could think of when I faced this problem while using DialogCodeHook. Hope it helps.
来源:https://stackoverflow.com/questions/47436959/amazon-lex-not-prompting-for-missing-variables-when-using-codehook-validation