Custom action based on previous utterence

I am trying to get custom input from the user based on the previous utterance from the bot. Here is an example.

Bot: Sorry to hear that you are leaving us, please provide us with reasons.

User: Random reason

How to capture this random reason in the intent? Or, can it be identified through previous bot utterance? Any help is appreciated.

Not really sure how to do this generally, though there is similar exame of free form input in the formbot example on github which requests a free form feedback from the user. Cheers!

1 Like

@kxr123330 you need to overwrite slot_mapping method in your form action class as described here Slot Filling

for you case you should try something like

def slot_mappings(self): ‘’’ self.from_text(intent=intent_name) will use the next user utterance to fill the text slot slot_name regardless of user intent if intent_name is None else only if user intent is intent_name. ‘’’ return {"slot_name ":[self.from_entity(entity="slot_name "), self.from_text()]}

Thanks @apurva. How will you set the intent, story and slot for this use case?

@kxr123330 Intent=inform (or can be any other intent that you might have defined to handle this); story: this within the flow of your story form: inform{“customer_response”:“any text or empty”}; slot customer_response with type text or as applicable for your use case.