Is it possible to import conversation id from actions.py to another file?

Hi, I wonder if it is possible to import conversation id from actions.py to another python file as a variable? I’ve tried to do that by doing:

### actions.py
class ActionTellID(Action):

    """Informs the user about the conversation ID."""

    def name(self) -> Text:

        return "action_tell_id"

    async def run(

        self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]

    ) -> List[Dict[Text, Any]]:

        conversation_id = tracker.sender_id

        return[]


### example.py
from actions.actions import ActionTellID

actions.ActionTellID()
print(conversation_id)

It didn’t work. Do you have an idea how to do that?

I’ve tried also this option but it didn’t work too:

### example.py
from actions.actions import ActionTellID

conversation_id = ActionTellID()
print conversation_id

Do I have to use async def run in example.py? Or ActionTellID is okay?

The first problem here is that you are not using the run method, you’re just instantiating an instance of the ActionTellID class.

Secondly, even if you used the run method ActionTellID().run (which yes, needs to be await ed since it is async), it is not returning anything, so you will not get back the conversation ID.

Finally, a custom action is expected to be run by being called in a conversation; see the expected arguments for the run method.

Maybe it’s better to start with what you want to accomplish in example.py where you are trying to import the conversation ID?

My goal is to simply get conversation_id at the beginning of the conversation without using custom action like ActionTellID so I can save it to the database for example.

Ok, in that case what you’d want to do is create a custom ActionSessionStart which saves the conversation ID to wherever you want. See the documentation for customizing action_session_start