This repository contains the code for a Telegram bot that, given a link to a youtube video, will download the audio version of it and send it over to the user.
The commands that are exposed by the bot are:
/start,/stop,/help: info commands for the user to interact with the bot/adduser(for admin users only): will add the passed user id to the list of users allowed to use the bot (e.g./adduser CHAT_ID)
When a message is sent to the bot, it checks whether it's a slash command, if not, it will use assume that it is a link to a YouTube video.
It will use yt-dl to download such video in mp3 format and send it back to the user.
If any errors occour, these will be passed to the user that contacted the bot.
For each user request, a new folder will be created where the audio will be downloaded. After being sent to the user, this will be deleted.
This repository contains a Dockerfile that will let you package the app as a container image via the following commands:
docker build --no-cache -t telego-yt-dlp .
docker run -e ADMIN_USERS=ADMIN_CHAT_ID_1,ADMIN_CHAT_ID_2 -e ALLOWED_CHAT_IDS=CHAT_ID_1,CHAT_ID_2,CHAT_ID_3 -e TOKEN=BOT_TOKEN telego-yt-dlp To run the script directly, execute: go run telegram.go, making sure that the ADMIN_USERS, ALLOWED_CHAT_IDS, TOKEN and YOUTUBE_DL_PATH have been exported.
The ADMIN_USERS and ALLOWED_CHAT_IDS are optional variables, yet you need to add your own id to the allowed list to be able to use the bot.
Either locally or by connecting to the instantiated container, you can validate that the video is downloaded and the audio is sent to the user via the following commands.
docker exec CONTAINER_ID /bin/sh
watch -n 0.2 ls -lahR ❯ clear
Every 0.1s: ls -lahR 2025-07-26 08:56:21
.:
total 9M
drwxr-xr-x 1 appuser appgroup 4.0K Jul 26 08:56 .
drwxr-xr-x 1 root root 4.0K Jul 26 08:55 ..
drwxr-xr-x 2 appuser appgroup 4.0K Jul 26 08:56 278271623-usunh6lf
-rwxr-xr-x 1 appuser appgroup 9.4M Jul 26 08:47 telegram-bot
./REQUESTER_CHAT_ID-usunh6lf:
total 6M
drwxr-xr-x 2 appuser appgroup 4.0K Jul 26 08:56 .
drwxr-xr-x 1 appuser appgroup 4.0K Jul 26 08:56 ..
-rw-r--r-- 1 appuser appgroup 1.5M Jul 26 08:56 Murubutu - Le notti bianche - feat. Claver Gold (prod. XxX-Fila).mp3
-rw-r--r-- 1 appuser appgroup 4.9M Jul 26 08:56 Murubutu - Le notti bianche - feat. Claver Gold (prod. XxX-Fila).webm
To run the code locally, besides needing go installed, there are a couple of dependencies that need to be satisfied:
The external Telegram library used for this project is telego.