Custom buttons in action.py file

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.
1 Like

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.

8 Likes

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?

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.

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

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

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.

1 Like

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.

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.

1 Like

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.

1 Like

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

I had used this code to add the button… but I need to know how to link this button with PDF file… please help if anyone can help me with this

This is something you want to show the user right?

If you’re developing an app or something, you can do it in the backend.

I’m not developing an app… but yes I want to add a button to my chatbot which once clicked can open a pdf file can you help??

What exactly is the application?

Maybe I can help better if you give some info.

Can u please send link of your project … I am also working on rasa project! I would be great help. Thanks in advance

Hii @Kaira2112 Kindly check the attached link for the same:

  1. SLOT FILLING WITH BUTTONS IN RASA CHATBOT | INNOVATE YOURSELF - YouTube
  2. How to customize your whole rasa webchat || Complete Tutorial - YouTube

Let me know in case of any help.