问题
How do I give response to a user in Amazon Lex based on the choice that the user have made?
For example: If user is married then system should ask how many children do you have, if user is not married the system should ask when are you getting married.
Is there any way to do this?
回答1:
If it's purpose is simply responding to the user without any elicit slot or chaining intents then it can be done simply in Lambda function with an if condition
.
def close(message):
return {
"dialogAction":{
"type":"Close",
"fulfillmentState":"Fulfilled",
"message":{
"contentType":"PlainText",
"content":message
}
}
}
if user['married'] == True:
return close('how many children do you have')
else:
return close('when are you getting married')
If you are planning to trigger some different intent then inside if-else write code for intent switching. You will need to pass the confirmIntent
dialog action from the lambda with the intent you want to switch to.
Check this link for details about intent switching.
来源:https://stackoverflow.com/questions/47706177/how-to-give-response-based-on-user-response-in-amazon-lex