I need to get my session_id for every conversation to be able to work with every separate conversation in the future (i.e., when playing with data analysis techniques). However, I cannot find any session_id’s neither in my database retrieved, nor even logs. How can I withdraw this parameter (together with all other needed ones like intent_name, sender_id, etc.)?
You can get the sender_id from the tracker. Typically, you’d do this in action_session_start and store it in a slot but this depends on your use case. You can see an example here.
To get intent information, you can see an example here.
Thank you a lot for your response! However, I need not sender_id, but session_id (for every separate session I have). Will this work for that? Or is there another solution for that?
I assumed you were using the REST channel which doesn’t have a separate session_id. sender_id and session_id are the same. However, you can set your own metadata to create session_id or any other value you want. What channel are you using?
I believe I am using the REST channel. How can I set my own metadata to create session_id? Could you give me a hint? Or is there any tutorial I could use ('cause I cannot find any)?
To add metadata to a REST channel call in Rasa, you can include the metadata key in the JSON payload of your POST request. Here is an example of how the JSON payload should look:
I asked chatgpt to write an action_session_start to retrieve the metadata:
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SessionStarted, ActionExecuted
from rasa_sdk.executor import CollectingDispatcher
class ActionSessionStart(Action):
def name(self) -> Text:
return "action_session_start"
async def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]
) -> List[Dict[Text, Any]]:
# Retrieve the metadata from the tracker's slots
metadata = tracker.get_slot("session_started_metadata")
# ... (rest of your custom action logic goes here)
# The session should begin with a `session_started` event
events = [SessionStarted()]
# An `action_listen` should be added at the end as a user message follows
events.append(ActionExecuted("action_listen"))
return events