Where can i access metadata from Tracker?

hi. i was wondering how and where i can access the metadata from the tracker variable. i used to access it before through:

tracker.latest_message[“metadata”]

i need the metadata so i can get the message id of the inlinekeyboardbutton (telegram) in order for me to update the same message. i used to access it before through:

tracker.latest_message[“metadata”][“callback_query”][“message”][“message_id”]

but now tracker.latest_message has empty metadata {}

did rasa change this? my chatbot hasnt been functioning ever since i updated rasa ): and now the tracker.latest_message[“message_id”] variable gives a different message id when i click the button ):

please help. thank you

@ccloud Hey! If I get you correctly, you want to get the session id, conversation and metadata of both bot and user? right

I guess tracker.events with give you all the details of the bot/user conversation or logs.

OR

Do check these codes, I used it before but optimised as per your need.

```
for e in tracker.events[::-1]:
    if e["event"] == "user":
        message_metadata = e["metadata"]
```

OR

chatbot_events = next(e for e in reversed(tracker.events) if e["event"] == "bot")
chatbot_events = next(e for e in reversed(tracker.events) if e["event"] == "user")
chatbot_events = next(e for e in reversed(tracker.events) if e["event"] == "actions")

This will go through the reversed list of events (making it from latest to oldest) and pick the first bot event using the next() function.

Tip: Do remember the metadata are is JSON and if its store in database; even the column still be JSON.

Good Luck!

2 Likes

thank u so much! ill try this :slight_smile:

@ccloud Is my suggestion helped you?

hi! i havent tried this yet but i found a workaround by using get_metadata() function in my custom channel!

@ccloud Ok, No worries. If you able to solve this query, I request close this thread with the solution or share the code you used for this query for other seekers.

Hi @ccloud , how do I use this get_metadata() function?