I am using Rasa 2.8.15 and using forms.
after my bot or user says ‘bye’ (intent), I want the dialogue to finish, so the server needs to restart and reset all slot values… how can I do this?
It currently keeps open and so the conversation has no logic if I send more messages. Thanks all
But since I don’t know your level of knowledge, I will just drop a potential solution/guide here. If you have any difficulties or questions, feel free to ask
I don’t have the possibility to test right now, but it can be something close to this:
thanks again @ChrisRahme very helpful to see the event used. I will try it now, but I dont understand why the run function needs to be async? Other examples in Rasa use ‘def’. Let me know if there is a specific reasno thanks
Also @ChrisRahme before using AllSlotsReset() event I want to make sure they are saved, either in database or file. How can that be done do you know?
You don’t really need to, but using async might be better when you have lots of concurrent calls.
It’s actually written in the basic example for Custom Actions.
Yes, you can write any regular Python code in Rasa, so the database part is not Rasa-related
But, the part of getting slot is indeed related to Rasa, and you can use the domain variable for this, which transforms your YAML domain into a JSON domain:
class ActionEnd(Action):
def name(self):
return "action_end"
async def run(self, dispatcher, tracker, domain):
slot_names = domain['slots'].keys() # This will return all your slot names
slot_dict = {}
for slot_name in slot_names:
slot_value = tracker.get_slot(slot_name) # This will return the value of each slot
slot_dict[slot_name] = slot_value # Add {slot_name: slot_value} to your dictionary
save(slot_dict) # You custom save function
return [AllSlotsReset(), Restarted()]
@ChrisRahme thanks this is helpful will try it. Will also mark this as solution, but are there any guidelines on ways to save those slot values slot_dict from all interactions (database?) and then be able to use them in the next user-bot interaction. Do you have any recommendation or code to show?
You mean you want to re-use the old slots after the session has restarted and slots were reset?
If yes, what you’ll have to do is query the database again.
For that, I recommend saving the user ID in the database too, which you can get with tracker.sender_id. And maybe also the time, if you want to keep logs.
Then, in the next session, you can query the values of that sender_id again.
@ChrisRahme yes that is exactly what I mean. Is fetching info from database & saving slot info (plus user ID etc) something Rasa-related or are there any examples and easy ways to look at?
No, this is not linked to Rasa, but there are a lot of things you need to consider before proceeding, including:
Server RAM, CPU, and storage
Speed of data flow
Relationship between tables in the database
Structure (SQL vs NoSQL)
At first sight, I would suggest using MongoDB or ElasticSearch as a database. But a lot of starters prefer to use MySQL or the like, so you can go with that if you already know it (but you won’t really need the relational and structural aspects of it, they can even become a hindrance).
Study at least the differences between these databases before definitely sticking with one though. Then, you can look up tutorials on how to use that database with Python.