Is there a way to send other parameters with the API endpoint that rasa offers with enable api?
For example the current format is
{
“sender”: “<user_id>”,
“message”: “”
}
However can I add additional parameters for example,
hi @shreehari what do want to achieve ?
you can implement your own custom endpoint that takes the payload:
{ “sender”: “<user_id>”, “message”: “”, “parameters_1”: “<parameter_1 value>”, “parameters_2”: “<parameter_2 value>”, … }
and from that end point you can call the Rasa REST endpoint with { “sender”: “<user_id>”, “message”: “”}
Hey Utsuk thanks for the response. So I have an additional parameter that I want to send to the Rasa server because I use that parameter in a logic inside action server. So building a wrapper API is not going to work for me considering my logic mostly lies within the action server.
{ “sender”: “<user_id>”, “message”: “”, “parameters_1”: “<parameter_1 value>”, “parameters_2”: “<parameter_2 value>”, … }
For example I use the parameters_1 and append it to the user message. Which intern calls an internal API to retrieve something…So having these logics I’m confused on how to achieve this or if there is a way around.
hi @shreehari there can be multiple ways to achieve what you want to do. I can try to share my thoughts if you can explain your scenario with some examples.
However as far as I know the best way to get any message inside your custom action is via the tracker. Using tracker you can access your slots or the last message. Now having said it would be apt to think in terms of design that whatever you are trying to pass e.g. parameter_1, 2, etc. is something related to the NLU itself meaning - intent, entity, or slot OR it is something which is purely needed to perform some business logic.
If it something related to the message itself that would make sense to be extracted via the NLU then it can some as a message itself and the Rasa NLU will be able to extract it and you ca get it in the custom action via the Tracker.
If it is something which is not relevant for the NLU, however you still need it to build some specific business logic few thing come to my mind -
Approach#1
assuming it is not relevant for the NLU itself, you can append the parameter_1, 2, etc. to every message with some predefined format that the user types.
then have your intent / entity logic work as per your raining data, so it calls the relevant custom action.
in the custom action get the latest message via tracker.latest_message. parse your parameters and do whatever logic you need with them.
Approach#2
if these parameters are something which can be fetched in the custom action itself, fetch them via a API call or DB query and then execute the logic needed.
Those are great ideas. Yes you are correct this has nothing to do with the NLU. Even I was thinking of the approach 2. Currently Im using a delimiter to send the parameter within the ‘sender’. However, I can see many edge cases where this approach might fail.
My only thought on approach #2 was that it might be slow considering with every single request I’d be fetching from DB. But looks like it is also the most apt solution to this problem.
Thanks for sharing your thoughts on this. Appreciate it!