Custom buttons in action.py file

(Nishet Vyas) #1

Hello @Juste and all can you please help me? i want a button in action.py file for custom use?below i show you a example?can you please help me for that .i search all topic and blog but i cannot found anything.Can you please solve this problem?

Ex:- user- give me mobile no of rohan bot:- There is 2 rohan in database

  1. rohan shah
  2. rohan pandya ->i want buttons for employee names, if i click on that employee name button it should give me details of that employee on click event of that button. Thanks for the help.
0 Likes

(Srikar) #2

You can do this in custom actions. I believe you need to fetch that data from your DB. When the user asks give me mobile no. xx, first you need to capture the name of that person in a slot.

Then in your custom actions make your API call to the DB or however you want to fetch the user details. Use

# Fetch the data and store in the format used by buttons.
buttons = [{"title": "Rohan Shah", "payload": "/intent_name"}, {"title": "Rohan Pandya", "payload": "/intent_name"}]
dispatcher.utter_button_message("There are 2 people with the name Rohan:", buttons)

Once the user selects a button again trigger custom actions and fetch his details.

0 Likes

(Nishet Vyas) #3

Thanks you so much @srikar but how we can trigger on button click event?and in the buttons title "Rohan Shah " is static name here i want a name who i got in person slot. so i can do this?

0 Likes

(Srikar) #4

Hi,

First, capture Rohan in a slot and query your DB, then create buttons with all the search result matches, then on-clink, send that name as a message or set the slot in /inform{“person”: “The on-click name”}. Again use this name to fetch this particular user’s details. Yes, you have to create the buttons using the data you fetched from your DB.

0 Likes

(Nishet Vyas) #5

Ohk Thanks you. can please little bit help? you have any example ? if you have can you share with me?

0 Likes

(Srikar) #6

What do you need an example for? Let me know. For creating the buttons dynamically, use the method above.

0 Likes

(Nishet Vyas) #7

actually i want to make hr chatbot for my last sem project and i use SQLite database.so i also feeling stuff in insert employee detail in database if you know then also help me for that.Thanks in advance @srikar_1996.

0 Likes

(Srikar) #8

I haven’t used SQLite with RASA. All my data is in mongoDB, so I use APIs to fetch data from my DB. But I believe it is the same approach for any database. Query user search -> display buttons -> again query with specific user details.

0 Likes

(Nishet Vyas) #9

yes yes @srikar_1996 it’s similar to mongo db and now i got it how to create button. but now problem in insert data with validation. i mean like if hr want to insert data then first bots want name like rohan, then bot ask give a number then hr enter number, then bot ask give email id , then hr gives a email id. now i want all this data into database.i successfully insert employee name into database .i train all name into nlu.md file and then store using slot value.so its only for name.but now if i want to fatch all detail and insert into database.so how i can do this? everytime i train name ,mail,mobileno in slot and fatch that slot and insert?or any other method for that that store multiple slot? i see form action but i cannot find good example.and also form action may not provide validation.so how can i do this?Thanks.

0 Likes

(Srikar) #10

The best way to do this is formActions. Since you’re taking many details, you can ask them in order and finally insert all of the user details at once. You can do a lot with form actions. It also handles cases where the user enters all the slots in one utterance, for eg.: his name is xxx and email is yy then the form automatically captures email and name slots. There is a required_slots() method in forms.

FormAction does provide validation. Check this documentation, a very good description on how to use forms: forms

You need to provide the validations in the validate() method.

Hope it helps.

0 Likes

(Nishet Vyas) #11

Thanks @srikar_1996. i will try and let u know.

0 Likes