How to customize get_metadata() for Telegram user name?


I’m clear that in order to retrieve first and last names from de objetct telegram.user of telegram.message i need to customize , return in get_metadata() values extracted from the message of Telegram writting in the tracker record metadata field.

But…, anyone have an example of doing that?


I did this in my in rasa\core\channels\

def get_metadata(self, request: Request) -> Optional[Dict[Text, Any]]:
        metadata=request.json#transfers the request to a python dictonary and make it readable in python
        print("Metadata: ",str(metadata))
        print("Type Metadaten: ",type(metadata))
        print("User ID:", metadata["message"]["from"]["id"])
        return metadata

In my I did this

class ActionGetSenderId(Action):

def name(self):
    return "action_get_sender_id"

def run(self, dispatcher, tracker, domain):
    str_greet_name="Your name is "+user_name

And like always you need to add you action to your domain and story…

Since I overwrote get_metadata it transvers the metadata to the in my channels.

1 Like