I have saved user bot conversations in mongotrackerstore which is saving the user-bot conversation. suppose the user logs off and starts the conversation after some time with different device(say phone). Is there any way to get the past conversations and continue our next conversation as based on the previous ones.
I have tried a method
from rasa_core.trackers import DialogueStateTrackertracker1=DialogueStateTracker(sender_id,domain.slots)events=db.retrieve(sender_id).as_dialogue().event
@akelad
I got a solution where I am able to update the tracker as per past events for the same user so that user can continue the conversation from where he left the conversation.Also,i am able to print the USER-BOT conversation from the past events.
from rasa_core.trackers import DialogueStateTracker;tracker1=DialogueStateTracker(sender_id,domain.slots);events=db.retrieve(sender_id).as_dialogue().event;
for event in events:
tracker1.update(event);
event_dict=event.as_dict();
if event_dict['event']=='bot' or event_dict['event']=='user': print(event_dict['text'])
@akelad I tried with just retrieving the conversation and see whether it continues with the previous conversation. But it was not happening since tracker was not updated. We have to update the tracker with previous events to continue with the same conversation.
If you have given the details of tracker_store database in endpoints.yml, metadata of your conversation will get stored against the sender property that you use while sending messages to Rasa server.
{
"message": "Hi there!",
"sender": "JialiuXu"
}
This sender or rather sender_id is actually the conversation_id.
If you restart your server and send another message with the same sender id, the tracker will fetch all the metadata stored in your tracker store database and replay all those messages in the background to reach the previous state. You don’t have to manually retrieve/fiddle with any message.
Here the previous state refers to the state of tracker after the last message with the same sender_id was sent to Rasa server before restart.
That is what @akelad is referring to in her message.
The gentlemen that started this thread said that the solution was this peace of code
from rasa_core.trackers import DialogueStateTracker;tracker1=DialogueStateTracker(sender_id,domain.slots);events=db.retrieve(sender_id).as_dialogue().event;
for event in events:
tracker1.update(event);
event_dict=event.as_dict();
if event_dict['event']=='bot' or event_dict['event']=='user': print(event_dict['text'])
So i’m just trying to find out, where do i place this solution.
does it go inside my actions.py or any of the backend files(trackers.py or tracker_store.py)
@jacobdanielfcs
Did you finally figureout where to put that piece of Code?
@akelad can you please help with this matter as to where do we place the above code? do we put it in the actions.py?
This piece of code shouldn’t be necessary. If your tracker is persisted somewhere (e.g. MongoDB), the conversation should continue where the user left off if they have the same sender ID (depending on your sessions settings). You can also use the api to get the tracker of a conversation.