Search code examples
dockerdocker-composetelegramtwo-factor-authenticationtelethon

Telethon TelegramClient authentication in Docker container


we have a script to download files from Telegram Channel, using Telethon library for Python.

To create a Telethon instance, we using TelegramClient constructor. This method asks the user to insert his Telegram number to the console, then Telegram sends a security number, that should be written back to the console.

This authentication saved in Object/File/DB called session, so in the next execution, the TelegramClient will not ask for the phone number again.

Now, I want to create a Docker image for the script, and it's mean that when the user will create a container from the published Image, he will have to do an authentication process, and this is the question:

Which ways we have to do this authentication at most automatic as possible?

We can use Docker tricks, Telegram/Telethon tricks, and maybe Python tricks...


Solution

  • I will try to suggest one option to solve this.

    We can save the session in the host file system, and set the location of the session as a volume for the docker container.

    Then we can create a script for authenticating and creating this session, out of a container, and when the container will start it will have a session already.