How to access conversation history from default tracker store ?? how to write code in action.py file to extract chat conversation??
You can get the whole Conversation by using this API http://localhost:5005/conversations/{replace_with_sender_id}/tracker
There is no way to get the conversation in the action.py program by using the tracker object. you can use request.get() method and get the whole conversation as a JSON response.
Thanks for your quick response
Can you explain how to use request.get() method to get the whole conversation with code if possible
Thanks in advance
Here is the screenshot of how the request looks like
here is the code you can use in actions.py
# importing the requests library
import requests
# api-endpoint
sender_id = mention_sender_id_here
URL = "http://localhost:5005/"+sender_id+"/ali/tracker"
# sending get request and saving the response as response object
r = requests.get(url = URL)
# extracting data in json format
data = r.json()
If you follow this approach you will get the conversation history only when custom actions are called but if you want to access the whole conversation history from tracker, you can check this code:
Instead of calling api, we can also get the conversation using as_dialogue
method of the tracker
https://rasa.com/docs/rasa/api/tracker/#rasa.core.trackers.DialogueStateTracker.as_dialogue
hey @JiteshGaikwad I tried this method to store conversations but in chatHistoryLogger I’m get “undefined variable error” for “logger.debug”
Hey @kpreetsid make sure you have imported the logging module in the chathistoryLogger
import logging
Hey @JiteshGaikwad,
I’ve already imported the said module in chthistoryLogger file.
Still getting the same error.
can you show me the chatHistoryLogger.py
hi @kpreetsid, thanks for stating the issue, I had forgot the logger
definition.
logger = logging.getLogger(name)
just add it to line no. 8
what does “name” stands here?, because I’ve checked whole file but there is no variable named “name”.
name is a built-in variable which evaluates to the name of the current module.
Hey @JiteshGaikwad,
Thanks , it’s working now
I have implemented Rasa-ChatHistory-Logger .Is it possible to get specific sender _id log information?
@Saranya96, you can get it, can you let me know how are you storing the data, I mean logging it to db or json file?
I am logging as a json file only.
If your json file is something similar to this file:
you need to write the code as below:
- you need to write a function which accepts the
sender_id
- Inside the function, you need to maintain a variable let’s say
sender_logs
of datatypelist
that will store the sender’s log info - and then you need to write the code that will loop over the json data and check the info with sender’s id and once matched it will append the data to the
sender_logs
variable - once the loops end, you need to return the
sender_logs
variable