Upload file to Telegram


I would like to use my telegram bot to provide capability for the user to upload a file via Telegram and then have RASA upload the file to an external system via an existing API they provide.

Can I check if this is possible and also how best to approach this?

Example would be

user: I would like to upload a file BOT: Sure please upload file User: Action uploads file via Telegram BOT: Receives file and uploads to external API and then return results to user.

I am happy for the file to reside on the local file system if this is a requirement or use Telegram to upload the file directly to the target API, I am just not entirely sure how to approach this. Any advice would be much appreciated.


Hi @itsecstudy,

I made something similar to the facebook channel. But I had to change the facebook channel on rasa_core a little bit. You probably could do something similar to telegram.

What I did was: In facebook when you send a file or image facebook will send a webhook with this parameters:

 "attachments": [
        "type": "<image|video|audio|file>",
        "payload": {
          "url": "<ATTACHMENT_URL>"

So in the facebook channel on the message method, here is the current code of the current version:

    async def message(self, message: Dict[Text, Any]) -> None:
    """Handle an incoming event from the fb webhook."""

    if self._is_user_message(message):
        text = message["message"]["text"]
    elif self._is_audio_message(message):
        attachment = message["message"]["attachments"][0]
        text = attachment["payload"]["url"]
            "Received a message from facebook that we can not "
            "handle. Message: {}".format(message)

    await self._handle_user_message(text, self.get_user_id())

I added a new static method to the channel, for exemplo, “self._is_file”. And if this method returned true. Instead of sending to the bot:

await self._handle_user_message(text, self.get_user_id())

You would send:

await self._handle_user_message('/file_msg{"url": THE_URL_HERE}', self.get_user_id())

So in my bot I have an intent called “file_msg” and you execute a custom action that would get the URL and send the URL or file to whatever api you want to.