# Populating metadata and retrieving in custom code

**URL:** <https://forum.rasa.com/t/populating-metadata-and-retrieving-in-custom-code/43499>\
**Category:** Rasa Open Source\
**Created:** [May 12, 2021, 10:18am UTC](https://forum.rasa.com/t/populating-metadata-and-retrieving-in-custom-code/43499 "2021-05-12T10:18:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joggerjoel](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/joggerjoel/32/14583_2.png) [@joggerjoel](https://forum.rasa.com/u/joggerjoel)\
**Post date:** [May 12, 2021, 10:18am UTC](https://forum.rasa.com/t/populating-metadata-and-retrieving-in-custom-code/43499/1 "2021-05-12T10:18:56Z")

</div>

I used this link but can’t see the metadata on rasa-server:

> **[Custom Connectors](https://rasa.com/docs/rasa/connectors/custom-connectors/)**
>
> Deploy and Run a Rasa Chat Bot on a custom chat interface

```auto
curl --request POST --url https://localhost/rasa/webhooks/myio/webhook --header 'Content-Type: application/json' --data '{
            "sender": "test_user",
            "text": "Hello",
            "metadata": {"username": "joel"}
}'

```

Copied and updated files content based on link for: addons/custom\_channel.py credentials.yml

rasa run --endpoints endpoint.yml --credentials.yml --debug -log-file log.txt

One thing to note is that I am bypassing the response from intent -text in domain.yml and have achieved this from a database lookup. However I see that channel is required here.

```auto
domain.yml
responses:
  utter_greet:
    - text: Hi! I'm the default greeting.
    - text: Hi! I'm the custom channel greeting
      **channel: myio**
```

---

<div class="post-metadata">

**Author:** ![joggerjoel](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/joggerjoel/32/14583_2.png) [@joggerjoel](https://forum.rasa.com/u/joggerjoel)\
**Post date:** [May 12, 2021, 10:57am UTC](https://forum.rasa.com/t/populating-metadata-and-retrieving-in-custom-code/43499/5 "2021-05-12T10:57:33Z")

</div>

I have identified that curl localhost/rasa/webhooks/myio is executing

```auto
@custom_webhook.route("/", methods=["GET"])
        async def health(request: Request) -> HTTPResponse:
            return response.json({"status": "ok2"})

```

---

<div class="post-metadata">

**Author:** ![joggerjoel](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/joggerjoel/32/14583_2.png) [@joggerjoel](https://forum.rasa.com/u/joggerjoel)\
**Post date:** [May 12, 2021, 11:02am UTC](https://forum.rasa.com/t/populating-metadata-and-retrieving-in-custom-code/43499/6 "2021-05-12T11:02:37Z")

</div>

Just so it is clear:

I want to be able to get the metadata json object passed by client into the actions.py parameters:

```auto

class Chitchat(Action):
    def name(self) -> Text:
        return "action_chitchat"

    def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:

```

I was thinking I would obtain the information from tracker object

---

<div class="post-metadata">

**Author:** ![joggerjoel](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/joggerjoel/32/14583_2.png) [@joggerjoel](https://forum.rasa.com/u/joggerjoel)\
**Post date:** [May 12, 2021, 11:09am UTC](https://forum.rasa.com/t/populating-metadata-and-retrieving-in-custom-code/43499/7 "2021-05-12T11:09:25Z")

</div>

If I change the webhook to here:

```auto
       @custom_webhook.route("/webhook", methods=["POST"])
        async def receive(request: Request) -> HTTPResponse:
            sender_id = request.json.get("sender") # method to get sender_id 
            text = request.json.get("text") # method to fetch text
            input_channel = self.name() # method to fetch input channel
            metadata = self.get_metadata(request) # method to get metadata
            print (metadata)
            collector = CollectingOutputChannel()
            
            # include exception handling

            await on_new_message(
                UserMessage(
                    text,
                    collector,
                    sender_id,
                    input_channel=input_channel,
                    metadata=metadata,
                )
            )

            return response.json({"status": text})
            #return response.json(collector.messages)

```

I’m getting back text, but metadta is null when I try to set it in the client.

---

<div class="post-metadata">

**Author:** ![joggerjoel](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/joggerjoel/32/14583_2.png) [@joggerjoel](https://forum.rasa.com/u/joggerjoel)\
**Post date:** [May 12, 2021, 11:17am UTC](https://forum.rasa.com/t/populating-metadata-and-retrieving-in-custom-code/43499/8 "2021-05-12T11:17:07Z")

</div>

Ok I solved it, I changed:

```auto
metadata = request.json.get("metadata")

```

and it works
