Reputation: 9298
I am building a chatbot that asks the user a question with a wide range of possible responses, for example:
Bot: "What do you want your user bio to say?"
UserA: "My name is Bob. #chatbots are cool!!!"
or
UserB: "123"
I want Lex to accept virtually any user response. Currently, it will keep repeating the same question if the user response is not compatible with the existing slot.
Is there a built-in slot for this, or a way to build a custom slot that behaves this way?
Upvotes: 4
Views: 2082
Reputation: 1696
An additional way I've found to do this is to check whether the transcript is one of the slot prompt strings. If it is, then it's safe to elicit the slot's value. If not, then you have probably already elicited the slot value and can change the fulfillment_state
to "Fulfilled"
Here's a simple example of eliciting a feedback slot when the bot gets prompted with "Thumbs up" or "Thumbs down":
current_intent = event["sessionState"]["intent"]
slot_to_elicit = event["proposedNextState"]["dialogAction"]["slotToElicit"]
transcript = event["inputTranscript"]
if slot_to_elicit and (transcript in ["Thumbs up", "Thumbs down"]):
response = elicit_feedback_slot(
slot_to_elicit=slot_to_elicit, intent=current_intent
)
else:
text = f"Thank you for your feedback!"
fulfillment_state = "Fulfilled"
response = close(
event=event,
fulfillment_state=fulfillment_state,
message_text=text,
)
I know this is still not a perfect solution, since you need to explicitly match the slot prompts. Maybe use a regex, or leverage Lex by getting the interpreted value rather than transcript. Hopefully Lex will some day have an AMAZON.SearchQuery
slot type..
Upvotes: 0
Reputation: 39
Lex does not have AMAZON.SearchQuery but one way to approach it is to include a lot of dissimilar values in the SlotType enumeration as is done in the Lex bot created by the CloudFormation stack from this blog post. The custom slot type in this case has 81 enumerated values including -
The slot value in this bot's case is used to search within an Elasticsearch instance.
You can try following that path. A custom slot type can have unto 10,000 enumerated values. Also note that the 'Expand Values' option has to be enabled.
Upvotes: 1
Reputation: 6800
You can create a slot without any value for the intent and uncheck the required checkbox. Then in Lambda initialization and validation hook
, just grab the input of user from event['inputTranscript']
and assign that value to the slot.
Hope it helps.
Upvotes: 2
Reputation: 2655
Within a Lambda initialization and validation hook
you can call elicit slot
in order to get back the entire user response as a parameter.
Have a look at some of the sample Lex lambda functions for an example of how to use elicit slot
.
Upvotes: 1