Pass along users current location on website as a paramter to Rasa

Hi! I have a Rasa bot running on my website where it guides the users around the site. This means that in some cases the same question should have different answers and it only depends on where on the site the user is currently. Is it possible to pass along that information and use it when selecting a response?

There are quite many pages on my site and the questions answered this way would be quite simple so I therefore intend to use the Retrieval Actions for them.


From the top of my head … Technically, yes. It might be involved though.

If you can add a custom component to your pipeline that retrieves features for a specific user, then technically … sure. This is somewhat technically involved though.

Okay, hmmm.

Would it be possible to use a lot of Retrieval Actions, one for each page and somehow select the correct one from those? Or maybe it would be possible to use Knowledge Base Actions somehow? What do you think?

Thank you @akelad for pointing me to the metadata field.
(Pass along a location/context parameter used to select a response · Issue #5442 · RasaHQ/rasa · GitHub)

I see now how I can create a Custom Connector to pass along the page metadata. However I can’t come up with a good way to use that metadata to select a response.
You mentioned maybe using a custom action or something else. Do you have time to elaborate?


Yeah you can get that metadata from the custom action if you loop through the And then based on the value of that, you can send a different message

Say that a user asks the question:
“What am I supposed to do now?”

From the matadata I see where on the site the user currently is, but how do I set up Rasa in a way so that that information is used to select the correct response? Is it possible?


you have to do that with some if/else logic in your custom action

Okay, it still seams like a very hard problem though. I don’t know if there is anyone else who is interested in an official solution to this problem. Can I do anything to find that out?

Could you explain which part you have difficulty with? Have you managed to write a custom action like I suggested?

I created a Custom Connector that extracts the page id and started working on a Custom Action, but I don’t know what to put in the Custom Action.

For example: I now have the question asked by the user and the page id together i.e. something like: {“message”: “What am I supposed to do now?”, page_id: 23, …}

How do I use the page id to limit the set of possible responses? I.e. what should i put in the Custom Action?


something like:

if page_id == 23:

Hi again @akelad! You suggested using a custom action, but would it be possible to use a custom nlu component instead? I tried it but noticed that the metadata is only avaiable in rasa.core.channels.UserMessage not in rasa.nlu.training_data.Message for the input to the process functions.
Can I access the metadata field in custom nlu components in any other way?

Br, Johan

Why do you want to do this in an NLU component? The NLU components don’t have access to metadata fields like that, you’re right.

Because I use a modified ResponseSelector to select the correct response from a subset of all responses. I want to use the metadata to first filter all response down to that subset.


What’s the reason for doing that? If you want to do something like that, you may be better off not using the ResponseSelector, but regular intents instead

Would regular intents be better?
The problem that i have is that users can ask simple questions like “Where do i click now?” or “What should I write here?” etc. and they can do that on many different pages on my website. Those questions should have different answers depending on where on the website they are. I therefore pass along a page id in the metadata that i want to use to limit the response selection to those who belong to that page.


Yeah that would be better handled by regular intents, and then a custom action where you decide what message to send back to the user dependent on the metadata

So what you are saying is that I should use regular intents to get a list of potential intents and then extract the correct one with an action?

Wait now I see what you mean!
Hmm, could work but still not optimal since there are thousands of similar but different intents and each intent may only be valid on a few pages. That’s why i would like to do the filtering first.


what do you mean by thousands of similar but different intents?