Validate form input from frontend data


I have a problem when validating data on forms. So the problem is, whenever, the user inputs data into the form, I wanna validate it from the data from the frontend. I know about custom validation actions, however, I’m not sure how I can get data from the frontend meanwhile I’m in an action. I know about payloads, I can use them to get data from the frontend, but how can I make the action wait until I get data?

For example, the user asks to call a person (let’s call this call_person), this intent activates the form. Now the form asks for the person’s name which is a slot. After the user passes in the person’s name, I want to verify if this person’s name exists in my data which is on the frontend, if it exists then move on with the form, else give a list of similar names from the frontend data and allow the user to choose from it.

Can you check this example? 05-validation

Look this action. I think you just need to replace to check the person name exist

Thank you for your reply. Yes, this is somewhat like what I need. However, the problem is that the list of names from which I want to confirm the name is not on the RASA end (python), but is on the frontend. So somehow I want to request the frontend using RASA during the validation (maybe through a hidden response, or a custom response) to give me the list of names so that I can use it in the custom form validation during the validation action.

You can’t request to frontend

Frontend can make get/post requests to backend but backend(rasa) can’t make request to frontend

I’m not seeing many ways. I think the best way to do that is just make validation until send to backend using Javascript

Or, send the list in payload to rasa but i think is a garbage :joy: :joy:

Can you put this list name in some database or json/xml file?

Maybe @ChrisRahme has others ideas :smiley:

:sob: :sob:

I can’t store the list on a database as this is a contact list on the user’s phone and will be different for each user :frowning_face:

@ChrisRahme please help if you have any ideas to deal with this :sob:

Maybe you can build something do ask permission to get phone list of user, send to rasa and storage it in some slot.

What is your frontend? Mobile application or web?

So basically we have a Flutter app (mobile application), and we were planning to somehow request the list of contacts once the user requests RASA to call a person. We can get the list of contacts and store it in some slot, but then the problem would be when should I request it, because I don’t know when will the user request to call a person :frowning_face: and the user may update their contact list just before call request.

So… i think something like that

User press button call -> post request with text: /user_need_call -> 
trigger this intent -> rasa return with payload {text:"please, give permission": payload:need_user_list} -> 
frontend check response (if response.payload == 'need_user_list': get list phone and send to rasa)

What do you thing?

1 Like

Yes, this will work fine I think but will create a lot of back and forth between the app and RASA. I was looking for a way using form validation, as I have further questions too in the form which need to be filled after verifying the name :frowning_face:

Let’s say I have a case of the message, where the user wants to send a message, I can get the person’s name using your method, however, now I want the message that needs to be sent too (which was my next slot in the form), but since the form is not running anymore and the message that the user needs to send can be anything (i.e. can’t be predicted beforehand), I can’t create an intent for it so that RASA can identify it and fill in the required slot :sob:

What you can do is either

  • Make an API that you can call is the custom validation action - Useful when the data is always changing so you can call that API when needed only

  • Send the frontend data as a hidden payload - Useful when the data is static or does not change that often so that you can send it to Rasa when it changes

1 Like

Thank you for your reply!

For the first option, do you mean to make an API on the frontend (Flutter) end? I don’t think that’s possible, since, it’s not deployed on a server, it’s installed locally on the user’s smartphone.

For the second option, do you mean to send a hidden payload regardless of whether the user wants to make a call or not? If that is the case, then won’t that be wasteful in the sense of available resources?

Yup that’s what I meant!

Yeah I thought that would be the case, but I tried my luck :slight_smile:

Send a hidden payload - yes. It would be wasteful - it depends.

It would be wasteful if there was no way to predict when the frontend changes and you keep sending it. It would be less wasteful to do it when the frontend changes only.

If it’s okay to have a 1 minute delay between each hidden message to Rasa, then this wouldn’t be very heavy (what is 1 message per minute in a conversation, really?).

The least wasteful way is if there is a way to detect when the slots will be needed (through a hidden message from Rasa as I explained here).

Right, that makes sense, thank you :slightly_smiling_face:

1 Like

@itsjhonny Is there a way to interrupt the form in the middle and perform the above-suggested method for verification and continue the same form again?

I think you can use conditionals in storie :smiley:

Take a look, maybe its help you

financial-demo line 113

and @ChrisRahme comment in this thread Running a form in the middle of another one - #4 by f.batiri