Populating metadata and retrieving in custom code

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

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.

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

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

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

Just so it is clear:

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


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

If I change the webhook to here:

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

Ok I solved it, I changed:

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

and it works