Rasa actions.py file should ask questions from users

Hi Everyone, I am working on rasa which allows user to write complains here on actions.py file my bot providing categories to select one of its category and when it is selected then the category send to database and database return 3 or more Boolean questions to ask from users but I don’t know how can i do this from actions to save Boolean responses one by one on a single slot

Example:

user: i want to complain in IT department

bot: select the option 1) Internet Issue 2) Hardware issue 3) Alarm Issue etc

user: Hardware Issue # from database [queston1, question2, question3] each question contain yes and no payload

bot: question1

user: yes

bot: question2

user: yes

bot: question3

user: no

how would i make it dynamic

note: each category contain different questions to ask from user

thanks

You could use forms and a separate slot for each question.

@stephens i don’t want to use separate slot for each question as i am receiving all questions from database

for example: user says hi: bot: returns main menu which I set in actions.py file and provide some categories like:

  1. eat
  2. sleep etc now bot ask from user to select one of it after that each category contain several questions to ask from user and save their response in a single slot

Hi @stephens I have resolved that issue finally and its working for me correctly. Here is what I did bunch_of_booleans = [] class ActionAskQuestionsResponse(Action):

def name(self):

    return "action_ask_QResponse"

def run(self, dispatcher: CollectingDispatcher,

    tracker: Tracker,domain:DomainDict)-> Dict[Text, Any]:

    get_category=tracker.get_slot('categories')

    get_boolean=tracker.get_slot('QResponse')

    print("what is category in action_ask_boolean",get_category)

    if get_category is not None:

        data = api_retrieve_questions_by_IT(get_category)

        new_slot_values = []

        # 'Did you check the power supply of the Device?','Did you check the Device is contact with your computer/Register/Terminal properly?','Did you check all the Device have proper cabling and Connected with computer?'

        for d in data["Response"]:

            AttributeName = d["AttributeName"]

            new_slot_values.append(AttributeName)

        print("length of bob ", len(bunch_of_booleans),"\n new_slot_values ",new_slot_values)

        dispatcher.utter_message(text=new_slot_values[len(bunch_of_booleans)])

async def validate_QResponse(self,slot_value:Any,dispatcher: CollectingDispatcher,

    tracker: Tracker,domain:DomainDict)-> Dict[Text, Any]:

    boolean=tracker.get_slot('QResponse')

    categories=tracker.get_slot('categories')

    print("Selceted QResponse:",boolean)

   

    if categories is not None:

        # questions = ['Did you check the power supply of the Device?','Did you check the Device is contact with your computer/Register/Terminal properly?','Did you check all the Device have proper cabling and Connected with computer?']

        data = api_retrieve_questions_by_IT(categories)

        new_slot_values = []

        # 'Did you check the power supply of the Device?','Did you check the Device is contact with your computer/Register/Terminal properly?','Did you check all the Device have proper cabling and Connected with computer?'

        for d in data["Response"]:

            AttributeName = d["AttributeName"]

            new_slot_values.append(AttributeName)

        print("what are the new slot values in validation == ", new_slot_values)

        if len(bunch_of_booleans) == (len(new_slot_values)-1):

            bunch_of_booleans.append(boolean[0])

            print("what is bunch_of_booleans in validation ", bunch_of_booleans)

            dispatcher.utter_message(text="Your compalin in BOOlean validation has been register under Token #")

            return {"QResponse":bunch_of_booleans}

        else:

            dispatcher.utter_message(text="Please Enter the correct boolean")

            print("what is boolean[0] ", boolean[0])

            bunch_of_booleans.append(boolean[0])

            print("what is the bunch of QResponse ", bunch_of_booleans)

            return {"QResponse":None}

the action_ask_QResponse will keep asking the questions by api and the validation will validate until the both length are equal that means my questions from database has been ended and it will append all responses to dynamic list and compare the length of dynamic list and the api list then it will fill that list slot on my required slot thanks for your response.

Good idea

thanks @stephens and i had a one more question is there any way where i set entity from action file and not define in nlu file and this entity should get accept any of the data which user provide or second we can restrict a form to not use/classify any other entity i have tried using use_entities but its not working for my situation and also i have tried to define not_intent which is used for stop classify the intent/set back wonder to know about it thanks

I don’t understand the question, but I’ll pick up on a few phrases.

set entity from action file and not define in nlu file

I think you’re wanting to entity extraction to be based on data you have in your db. It’s possible you could use a custom component like duckling for something like this. I would look at the source code for duckling.

1 Like

yes you are right and i think there must be another way to save all responses from user without classifying that entity is that can be done for example: i have a entity which i dont want it to classify the user response only for that entity it it possible if yes how ?