在AWS控制台中,单击您的Lex bot,然后选择“Slot Types”选项卡。选择要添加“Slot capture: failure response”选项的槽类型,然后选择“Edit”.在“Prompt”字段下,添加一个新的提示。选择“Custom response”选项,然后单击“Add custom message”。在“Message content”字段中输入以下内容:
{ "contentType": "PlainText", "content": "Sorry, I didn't catch that. Can you please try again?" }
保存更改后,在您的Lambda函数中为该槽位添加以下代码:
if not source: response['dialogAction']['slotDetails'][slot]['resolutions'] = { "resolutionsPerAuthority": [ { "authority": "aws:bot:amzn1.ask.skill.1234-5678-90ab-cdef", "status": { "code": "ER_SUCCESS_NO_MATCH", "message": "Failed to match any of the slot values" } } ] }
在这个例子中,我们设置了一个状态代码和一条信息,告诉用户输入与任何槽位值不匹配。这将触发我们在前面步骤中创建的Custom Response,向用户请求重新输入。