I have been given a task to make the bot ask questions from a MySQL database, and also store the answers in the Database. The number of questions is not fixed, it can be any no. of questions. I’m not able to find a correct way to do this. Any suggestion will be helpful.
You can create a Dynamic Form in which you do a
for loop that outputs (
utter_message()) the next entry in the database each time.
You save the answers in a slot (e.g.
answer_list), and you write a rule to execute a certain action (e.g.
action_submit) when the form ends. In this action, you get the slot value back and save its contents in the database.
For displaying the questions I use dispatcher.utter_message(). But how do I take in the answer(input)?
But here in Slot Mappings, I need to define a function: async def extract_slot_name(), for each slot right? Is there any other way to do this? Because I don’t think I can define a function with dynamic names in python.
You could do your whole thing using just one slot, with whatever name, that you use each time to ask a question, use a slot mapping to fill it and send it to the database, then repeat (same slot, different question).
@ChrisRahme Thanks a lot. I felt it hard to understand at the beginning, but now it’s working. Thanks for explaining it to me, in a way I understand.
Yes, I agree forms have a steeper learning curve, but the more you work with them the more you’ll find them useful and flexible