User information with Telegram integration

Hello everyone,

I am currently using RASA Open Source to create a telegram chatbot. I’ve integrated Telegram as instructed by the documentation. Now, I would like to access some of the data that the telegram api provides for user messages. However, when I use the tracker to get the latest message in my actions, I don’t have that information available. Is there any way to access them in my actions?

Hi @alextdnreb, if you want to send along extra information from the incoming message, I would recommend extending the TelegramInputChannel class. There is already a get_metadata function that is called in the input channel, which by default does not do anything. If you write a class that inherits from TelegramInputChannel and have it return the entire user message as metadata, it will send all of the information along to the action server.

Hi @erohmensing

that was the hint I needed, thanks a lot!! :relaxed:

1 Like

Hello, I just need to get (imperiously) the username, something like … chat_id = update.message.chat_id first_name = update.message.chat.first_name last_name = update.message.chat.last_name in the context of actions.py

Should I really extend the get_metadata () function in channel.py? How do I later transmit that data to actions.py?

on the other hand, do I have to do a specific intent /start for telegram (i.e. can’t I unify everything in action_session_start used for facebook?

Has anyone been able to solve this?

Regards.

yes you need to extend the get_metadate function. Or at least it worked for me. This is how my get_metadata function looks like

def get_metadata(self, request: Request) -> Optional[Dict[Text, Any]]:
   metadata=request.json
   return metadata

in the actions you can access the metadata and informations like first_name, last_name,…

tracker.latest_message.metadata #access metadata

tracker.latest_message.metadata["metadata"]["message"]["from"]["first_name"] #get first_name