1. Telegram API Application#
Open https://my.telegram.org/apps, select Apps after logging in, fill in the relevant information, and automatically generate apiId and apiHash information. If you have applied before, you can see it after entering Apps.
2. Building a Telegram Bot#
- Download the script
git clone <https://github.com/alonedogboy/telegram_channel_downloader.git>
- Install rclone. If you only need to download to your local machine, you don't need to install this step.
- Enter the script directory
- Install dependencies
pip3 install -r requirements.txt
- Modify the relevant information in the telegram_channel_downloader.py file:
api_id, api_hash: Information obtained from the telegram api, fill in the corresponding positions respectively;
bot_token: Contact @BotFather to create a bot, it can also be an existing one. Fill in the obtained token;
admin_id: Contact @get_id_bot to send a random message and obtain it;
If you need to upload to OD: You should modify the following parameters in the script: drive_id="", drive_name='onedrive', onedrive is the name of the cloud drive you filled in when configuring rclone, and replace "fclone" with "rclone" on line 102;
There are corresponding notes for all configurations, modify them as needed.
- Run the script: Can be kept online with SCREEN
# Enter the phone number associated with telegram, get the verification code and enter it
Screen related commands:
# Create a screen session: screen -S xx #xx is the name of the session to be created # Hide and keep the current session window: Press Ctrl+A, then press the "D" key # Restore the session window: screen -r xx #Restore the session with the name xx # If you forget or haven't set the session name: screen -ls #List all sessions, find and use the restore command # Close the session window exit
- Run: Send /start followed by the link to the channel to the bot, and you can start running the script and downloading files.
Link to the channel: Click on your channel name to see the channel link;
0: This is the message ID, you can define it yourself. 0 represents the earliest message. If you want to download from a specific message onwards, right-click on the message and choose "Copy Message Link" to see the message ID number at the end of the link.