How to compare two tables in database?If bot asks for phone number, and user responds to it, I want to check the number with other table of my database, if it matches only, then the bot should reply. Is that possible?

If bot asks for phone number, and user responds to it, I want to check the number with other table of my database, if it matches only, then the bot should reply. Is that possible?

Hi @amina_anvar

I am not sure if I understand you correctly, because I don’t see where the “two tables” come in. If you want your conversational assistant to check the phone number that the user provided against some database, then the most natural way of doing this would be to use a form and implement a slot_validate function, see Forms

Inside the validation function you can execute any code you like. In particular, you can access a database and check if the provided phone number is valid. If it is not valid, you just let the function return {"phone_number": None}, where phone_number is the slot for the phone number.

1 Like

Thank you so so so so so much for the response… I wanted to check the phone number user gives with an another table. ie, I have two tables, in one table say ‘user_registration’, it has a list of phone number.(Not related to Chatbot values) And in another table say ‘reports’, I have created my chatbot and stored the values to the ‘report’ table. Now when a user enters into the bot, initially we will ask phone number, at the time itself I need to check the phone_number user provided with the table ‘user_registration’, if it matches only, we will allow them to forward the chat, otherwise we will utter some message. IS that Possible? How?

I still don’t see why you have two tables. What are “chatbot values”? In any case, using a form validation function, as I describe above, you can access any number of files you want. See Forms

1 Like

Two table as such is, There will be a list of numbers in a table named ‘user_registration’, (a series of number). LIke for example, I am taking a table and randomly adding a series of number to it. (As for my project, they will give me numbers(I am doing a self report bot)). Now In my Rasa, I have created a bot and stored values to an another table named ‘reports’. I didn’t tried the form, I stored it with slots. Here as I said, when user gets into the bot, they will ask for phone number first, and when they enter their phone number, I want to check the number is present in the ‘user_registration’ table, If so only, I need to give them access to further proceed the chat. IS this possible?

Ok, so you want your bot to ask the user for his/her phone number. The user provides a number and the bot stores it in the report list. Then the bot should also check if that number appears in the user_registration list and you are not sure how to do the latter. Is that right?

If you don’t want to use a form, you can still use a custom action, see Actions. Any project created with rasa init already shows you an file with some basic code example. So you can write your own python function that receives the phone_number entity and loads your user_registration list into memory and checks if the number is on the list. Does this help?

1 Like

Yes. Yes YES…I have an action file, from where all slot values are stored in database. My doubt is how to check the phone number entered by user is present in the table(user registration)? Can you give me a sample code(I apologise for the trouble). Coz, now I need to call the table user_registration(which has no connection with RASA) into my rasa bot and check the phone_number. IF it exist only, I will do the following actions. And where to write the sql code, in action file itself? IS that possible? Thank you so much for helping out.

Hmm… what the SQL query looks like depends on your database. Can’t you just write the phone numbers into a json file, load it with dataset = json.load... in python and then search by if phone_number in dataset? You can find some examples for custom actions in the rasa examples:

1 Like

Yeah, I will have a look at it. Thank you for reaching Out. Stay safe