Get user input in custom action or skip NLU classification

Hello everyone,

I am currently developing a bot, and I have a question about how to implement one functionality.

So far, basically, the bot is working alright answering general questions from a specific domain. Now, I want to add one functionality where the user asks the bot to do some kind of search based on his/her input.

To put it more clearly, here are the steps that I want to execute:

1. User asks "I want to search."
2. Bot determines that it is intent WANT_TO_SEARCH
3. Bot utters "What is your query text"
4. User enters query text.
5. Bot executes text similarity search between query text and corpus of documents. 

I already have an action that is doing text similarity search. My problem is how to get the user query text from step 4, because if the user enters something, the bot is trying to classify its intent. I would also like to mention that the query text that user can enter is random and can’t be put in one intent. Basically, that’s the main point of this functionality. To provide at least some results for questions that are not covered in the main domain.

Here’s what I have already thought of, but didn’t find a solution.

1. Somehow to invoke action_listen inside my custom action and to get the user input there and proceed with my action.
- I searched about this and as far as I know this is not possible in Rasa yet.
2. To put 2 followup actions, firstly 'action_listen' and then my action that is doing text similarity search.
- I tried this, but it is not functioning as I thought it would. It completely skips 'action_listen'.

I would be very grateful if someone provides me an answer, or an opinion on how to solve this. If my question is not clear enough, I can try explaining it better the parts that are confusing you.

Thanks in advance

You’re probably looking to create what’s called a FormAction. It is RASA’s way of designing chat systems where you want to take direct input from the user and store it somewhere (that somewhere being memory banks called Slots).

So, what you would do is, you would define a FormAction and tell it to ask for the user’s search term. (Hint: have a look at the required_slots part of the first article).

Next, you map that slot to the user’s raw message. (This part’s also explained in the article, look for the slot_mappings method.)

Finally, you run that raw message through your custom search action in the submit method.

I’ve kept this answer intentionally vague to avoid handholding you and to encourage you to try it out for yourself first, but if you have any questions or get stuck, feel free to let me know.


Hi, @ActuallyAcey

Thank you for your answer. I thought about Form Action as well. I have implemented one basic FormAction just to get myself familiar with it, but I am still not familiar with them in-depth.

The part where I am having trouble is the slot_mappings. Let’s say that my form action is activated and the bot asks the user to provide query.

My first question is how to map whatever user types to a slot, no matter which intent is recognized or if an entity is recognized. Would it be: self.from_text(intent=None)?

And then my second question is, would there be a way to stop or exit from the form, because I would have made whatever user types to map into the query slot. So, if user types something that my bot already have an intent and an answer for, it would go to stop the form action(handle unhappy path) and proceed with the answer.

I appreciate your help.

That’s absolutely correct. The way I like to write that statement is self.from_text() instead, potentially avoiding any intent-checking issues.

You may have to play around with the various types of slot mapping functions (such as intent=, not_intent= and so on) for this. You can find a list of usable mapping functions as well as some great examples here.

1 Like

Thank you for your answer and for your time. I am pretty sure this will do exactly what I wanted, but I will try it and accept your answer after it.

Hi, even I am solving the similar use-case.

I want to take user input & process it & give back the output. The input user will provide isn’t in my intents. I will be taking that user input & searching against a corpus through my custom action & give matching output.

Here, how should my story flow should be? I am trying out with forms. I got it how the slots_mapping will be done after user is giving input. But can you please suggest how the story flow should be? The form will take the latest message from user, but my question is how do i write intent for that user input as after that user input only I will have to activate form .