我有一个解决这个问题的方法:
if ChooseCase == 'Case 1' and CaseOneChosen == 'Yes' and not CaseOneQuestion:
# Assign current inputTranscript to slots
intent_request['currentIntent']['slots']['CaseOneQuestion'] = intent_request['inputTranscript']
CaseOneQuestion = intent_request['inputTranscript']
# After the user enter the text, check if the current slot value is the same as the previous slot,
# if it is, then this is the first time the user elicit this slot
# Else, assign the current inputTranscript to the current slot (done above)
if intent_request['currentIntent']['slots']['CaseOneQuestion'] == intent_request['currentIntent']['slots']['CaseOneChosen']:
return elicit_slot(
output_session_attributes,
intent_request['currentIntent']['name'],
intent_request['currentIntent']['slots'],
'CaseOneQuestion',
{'contentType': 'PlainText', 'content': 'Answer for case 1'},
None
)
说明:前一个槽是“CaseOneChosen”,这个槽的值为“是”,那么第3行将把那个值赋给槽“CaseOneQuestion”。现在它们都具有相同的值,因此 if 语句为 TRUE。该机器人将让用户引出槽“CaseOneQuestion”(我假设用户输入了“cat”)。在此之后,第 3 行会将“cat”分配给“CaseOneQuestion”槽。所以现在 if 语句是 FALSE。机器人不会再提示用户引出“CaseOneQuestion”插槽。槽值现在是“cat”。希望这可以帮助。