alfem / telegram-download-daemon

A simple script to automate telegram download of big files
Other
424 stars 119 forks source link

Need help with the interactig part of docker compose #110

Closed shahram7 closed 1 year ago

shahram7 commented 1 year ago

Hi there, first I would like to thank you guys for your great work. I am trying to install your docker image via portainer stacks. I got my api_id and api_hash from my.telegram.org and I got the channel ID from the bot @getmyid_bot. when I deploy telegram-download-daemon I see this logs:

Please enter your phone (or bot token): #Traceback (most recent call last):
  File "/app/./telegram-download-daemon.py", line 179, in <module>
    proxy=proxy).start() as client:
  File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 128, in start
    else self.loop.run_until_complete(coro)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 165, in _start
    value = phone()
  File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 22, in <lambda>
    phone: typing.Callable[[], str] = lambda: input('Please enter your phone (or bot token): '),
EOFError: EOF when reading a line
Please enter your phone (or bot token): 

my stack looks like this: (I use gluetun as a proxy)

version: '3.5'

services:
  gluetun:
    image: qmcgaw/gluetun
    cap_add:
      - NET_ADMIN
    environment:
      - VPN_SERVICE_PROVIDER=nordvpn
      - OPENVPN_USER=nordid
      - OPENVPN_PASSWORD=nordpass
      - SERVER_REGIONS=Netherlands
    restart: unless-stopped   
  telegram-download-daemon:
    #build: .
    image: alfem/telegram-download-daemon:latest
    container_name: telegram-download
    network_mode: service:gluetun
    depends_on:
      - gluetun
    read_only: true
    environment:
      TELEGRAM_DAEMON_API_ID: "myid"
      TELEGRAM_DAEMON_API_HASH: "myhash" 
      TELEGRAM_DAEMON_CHANNEL: "mychid"
      TELEGRAM_DAEMON_DEST: "/downloads"
      TELEGRAM_DAEMON_SESSION_PATH: "/session"
      #TELEGRAM_DAEMON_WORKERS: 2
    volumes:
       - /path/to/nas:/downloads
       - sessions:/session
    restart: unless-stopped
volumes:
    sessions:

could you guys help me with the interactig part?

When you use docker-compose, the .session file, where the login is stored is kept in Volume outside the container. Therefore, when using docker-compose you are required to:

$ docker-compose run --rm telegram-download-daemon Interact with the console to authenticate yourself. See the message "Signed in successfully as {youe name}" Close the container $ docker-compose up -d See the sessions volume in the docker-compose.yml file.

Best regards, Shahram

shahram7 commented 1 year ago

I have forgotten portainer and installed compose and done as described

nickiman commented 1 year ago

@shahram7 could you please help me in the same issue? I´m stucked in the same part...

I´ve made docker compose following the instructions. Using the same docker-compose.yml structure file.

version: '3.5'

services:
  telegram-download-daemon:
    #build: .
    image: alfem/telegram-download-daemon:latest
    container_name: telegram-download
    read_only: true
    environment:
      TELEGRAM_DAEMON_API_ID: xxxxxxxx
      TELEGRAM_DAEMON_API_HASH: xxxxxxxxxxxxxxxxxxxxxxxxxxx
      TELEGRAM_DAEMON_CHANNEL: -xxxxxxxxxxxxxxxxxxxx
      TELEGRAM_DAEMON_DEST: /downloads
      TELEGRAM_DAEMON_SESSION_PATH: /session
      TELEGRAM_DAEMON_WORKERS: 1
    volumes:
       - /share/Downloads/telegram:/downloads
       - /share/Container/container-station-data/application/telegram_session:/session
    restart: unless-stopped

volumes:
    downloads:
    sessions:

I´m using a QNAP NAS... once I´ve created the container doesn´t run having the same errors like you. In that moment I try to run the command to authenticate me, but getting this error:

[~] # docker compose run --rm telegram-download-daemon
no configuration file provided: not found
[~] #

Best regards

shahram7 commented 1 year ago

@shahram7 could you please help me in the same issue? I´m stucked in the same part...

I´ve made docker compose following the instructions. Using the same docker-compose.yml structure file.

version: '3.5'

services:
  telegram-download-daemon:
    #build: .
    image: alfem/telegram-download-daemon:latest
    container_name: telegram-download
    read_only: true
    environment:
      TELEGRAM_DAEMON_API_ID: xxxxxxxx
      TELEGRAM_DAEMON_API_HASH: xxxxxxxxxxxxxxxxxxxxxxxxxxx
      TELEGRAM_DAEMON_CHANNEL: -xxxxxxxxxxxxxxxxxxxx
      TELEGRAM_DAEMON_DEST: /downloads
      TELEGRAM_DAEMON_SESSION_PATH: /session
      TELEGRAM_DAEMON_WORKERS: 1
    volumes:
       - /share/Downloads/telegram:/downloads
       - /share/Container/container-station-data/application/telegram_session:/session
    restart: unless-stopped

volumes:
    downloads:
    sessions:

I´m using a QNAP NAS... once I´ve created the container doesn´t run having the same errors like you. In that moment I try to run the command to authenticate me, but getting this error:

[~] # docker compose run --rm telegram-download-daemon
no configuration file provided: not found
[~] #

Best regards

I've done just like description.

$ docker-compose run --rm telegram-download-daemon
# Interact with the console to authenticate yourself.
# See the message "Signed in successfully as {youe name}"
# Close the container
$ docker-compose up -d

once you have the session file you can deploy, it in anyway. I have deployed it in my downloader stack in Portainer.

shahram7 commented 1 year ago

Hi @alfem , I've run the container and given my Tel number and logged in successfully. when I copy the DownloadDaemon.session to the Volume folder of my Portainer Stack I get this error messages. It was working and I had no problem until today. Can you maybe drop a hint?

[WARNING/2023-10-10 09:07:32,943]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075471806465, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:32,986]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075658559489, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:32,995]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075693954049, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:32,996]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075699684353, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:32,996]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075702576129, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:32,999]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075716621313, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,000]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075716983809, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,005]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075739841537, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,005]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075740138497, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,005]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075742980097, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,006]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,006]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075744972801, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,006]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,006]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075746455553, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,006]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,007]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075751924737, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,008]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,008]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075752453121, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,008]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,016]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075755452417, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,016]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,016]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075756327937, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,016]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,016]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075756618753, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,016]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,016]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075761255425, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,017]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,017]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075773795329, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,017]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,017]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075774394369, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,017]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,017]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075779732481, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,017]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,017]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075781500929, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,018]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,018]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075798947841, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,019]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:07:33,023]telethon.network.mtprotostate:Server sent a very new message with ID 7288254075820923905, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:07:33,024]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively

and when i change the session file inside the container i get this error:

Session loaded from /session/DownloadDaemon.session
Traceback (most recent call last):
  File "/app/./telegram-download-daemon.py", line 178, in <module>
    with TelegramClient(getSession(), api_id, api_hash,
  File "/app/sessionManager.py", line 24, in getSession
    return StringSession(_getStringSessionIfExists())
  File "/usr/local/lib/python3.10/site-packages/telethon/sessions/string.py", line 37, in __init__
    self._dc_id, ip, self._port, key = struct.unpack(
struct.error: unpack requires a buffer of 275 bytes
Session loaded from /session/DownloadDaemon.session
Traceback (most recent call last):
  File "/app/./telegram-download-daemon.py", line 178, in <module>
    with TelegramClient(getSession(), api_id, api_hash,
  File "/app/sessionManager.py", line 24, in getSession
    return StringSession(_getStringSessionIfExists())
  File "/usr/local/lib/python3.10/site-packages/telethon/sessions/string.py", line 37, in __init__
    self._dc_id, ip, self._port, key = struct.unpack(
struct.error: unpack requires a buffer of 275 bytes
Traceback (most recent call last):
  File "/app/./telegram-download-daemon.py", line 178, in <module>
Session loaded from /session/DownloadDaemon.session
    with TelegramClient(getSession(), api_id, api_hash,
  File "/app/sessionManager.py", line 24, in getSession
    return StringSession(_getStringSessionIfExists())
  File "/usr/local/lib/python3.10/site-packages/telethon/sessions/string.py", line 37, in __init__
    self._dc_id, ip, self._port, key = struct.unpack(
struct.error: unpack requires a buffer of 275 bytes
alfem commented 1 year ago

Maybe is related to cipher in session file. You should use the container interactively once ir order to obtain a valid sessión file.

I do not know your Portainer deployment but things like timezone configuration can cause errors like those you posted.

shahram7 commented 1 year ago

Maybe is related to cipher in session file. You should use the container interactively once ir order to obtain a valid sessión file.

I do not know your Portainer deployment but things like timezone configuration can cause errors like those you posted.

Hi @alfem , thank you for your replay. I have created a new folder and a new docker compose file and I run the command docker compose run --rm telegram-download-daemon and I've seen the message "You have logged in as xxxxx" then I druck "Ctrl+C" and gave docker compose up -d Now i get this message in the log:

asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of 8 expected bytes
[WARNING/2023-10-10 09:56:47,715]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766352023553, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,727]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766401642497, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,736]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766440570881, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,738]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766450518017, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,740]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766458586113, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,741]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766463223809, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,742]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766468185089, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,743]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766474561537, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,745]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766481709057, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,750]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766501907457, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,750]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:56:47,754]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766514146305, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,754]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
[WARNING/2023-10-10 09:56:47,757]telethon.network.mtprotostate:Server sent a very new message with ID 7288266766530632705, ignoring (see FAQ for details)
[WARNING/2023-10-10 09:56:47,757]telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
shahram7 commented 1 year ago

Hi @alfem,

I've noticed if you enter the BOT Token instead of your Tel Number you don't need to enter any code. Is it possible to pass the "bot token" as a environment variable in docker compose in order to skip this interacting part? so the authentication is performed at every restart!

Best regards, Shahram

alfem commented 1 year ago

Where are you running docker? In a Windows PC, Linux server, NAS?

shahram7 commented 1 year ago

Where are you running docker? In a Windows PC, Linux server, NAS?

Debian 12 vm.

alfem commented 1 year ago

'Vm' hosted by...?

shahram7 commented 1 year ago

proxmox 7.4-3

alfem commented 1 year ago

I meant the base OS

shahram7 commented 1 year ago

I have my docker engine on a Debian 12 vm which run on my proxmox node (Debian 11)