# Where can i access metadata from Tracker?

**URL:** <https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297>\
**Category:** Rasa Open Source\
**Created:** [July 29, 2021, 4:18pm UTC](https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297 "2021-07-29T16:18:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccloud](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@ccloud](https://forum.rasa.com/u/ccloud)\
**Post date:** [July 29, 2021, 4:18pm UTC](https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297/1 "2021-07-29T16:18:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [July 29, 2021, 5:34pm UTC](https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297/2 "2021-07-29T17:34:02Z")

</div>

> [@ccloud](#):
>
> tracker.latest\_message[“metadata”]

@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

```auto
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!

---

<div class="post-metadata">

**Author:** ![ccloud](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@ccloud](https://forum.rasa.com/u/ccloud)\
**Post date:** [July 31, 2021, 1:10am UTC](https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297/3 "2021-07-31T01:10:29Z")

</div>

thank u so much! ill try this 🙂

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [August 1, 2021, 1:32pm UTC](https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297/4 "2021-08-01T13:32:09Z")

</div>

@ccloud Is my suggestion helped you?

---

<div class="post-metadata">

**Author:** ![ccloud](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@ccloud](https://forum.rasa.com/u/ccloud)\
**Post date:** [August 4, 2021, 1:07am UTC](https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297/5 "2021-08-04T01:07:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [August 4, 2021, 8:17am UTC](https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297/6 "2021-08-04T08:17:12Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![AnkitChouhan](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@AnkitChouhan](https://forum.rasa.com/u/AnkitChouhan)\
**Post date:** [August 10, 2021, 6:37am UTC](https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297/8 "2021-08-10T06:37:09Z")

</div>

Hi @ccloud , how do I use this get\_metadata() function?

---

<div class="post-metadata">

**Author:** ![dedanirungu](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dedanirungu/32/13448_2.png) [@dedanirungu](https://forum.rasa.com/u/dedanirungu)\
**Post date:** [February 2, 2024, 9:19am UTC](https://forum.rasa.com/t/where-can-i-access-metadata-from-tracker/46297/9 "2024-02-02T09:19:44Z")

</div>

Working solution [Telegram integration with rasa - #2 by fabiolamfleury](https://forum.rasa.com/t/telegram-integration-with-rasa/41940/2)

Going to post the solution i found:

Implemented a custom input channel in a file called `custom_telegram.py` the same folder that the `credentials.yml` is, with the content:

```auto
from rasa.core.channels import TelegramInput
from typing import Text

class TelegramInputChannel(TelegramInput):
    def get_metadata(self, request):
        metadata=request.json
        return metadata

```

Then, edited my `credentials.yml` using:

```auto
custom_telegram.TelegramInputChannel:
  access_token: "token provided by father bot"
  verify: "bot_username"
  webhook_url: "https://address/webhooks/telegram/webhook"

```

After that, it was possible to access in actions file:

```auto
    telegram_username = tracker.latest_message["metadata"]["from"]["username"] #user that sent the message
    telegram_chat_type = tracker.latest_message["metadata"]["chat"]["type"]
    if telegram_chat_type == 'group':
        is_group = True
    return [
                SlotSet("is_in_telegram_group", is_group),
            ]

```
