{"id":26171513,"url":"https://github.com/kingwingfly/telegram_sync_bot","last_synced_at":"2026-03-16T10:03:37.909Z","repository":{"id":252280665,"uuid":"839900796","full_name":"kingwingfly/telegram_sync_bot","owner":"kingwingfly","description":"A telegram bot to sync files to local server.","archived":false,"fork":false,"pushed_at":"2025-03-11T18:31:37.000Z","size":246,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2025-03-11T18:34:30.178Z","etag":null,"topics":["bot","telegram"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kingwingfly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-08T14:51:10.000Z","updated_at":"2025-03-11T18:30:59.000Z","dependencies_parsed_at":"2025-03-11T18:34:37.149Z","dependency_job_id":null,"html_url":"https://github.com/kingwingfly/telegram_sync_bot","commit_stats":null,"previous_names":["kingwingfly/fav_sync_bot","kingwingfly/telegram_sync_bot"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingwingfly%2Ftelegram_sync_bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingwingfly%2Ftelegram_sync_bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingwingfly%2Ftelegram_sync_bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingwingfly%2Ftelegram_sync_bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kingwingfly","download_url":"https://codeload.github.com/kingwingfly/telegram_sync_bot/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243097498,"owners_count":20235856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","telegram"],"created_at":"2025-03-11T19:27:04.308Z","updated_at":"2026-03-16T10:03:37.904Z","avatar_url":"https://github.com/kingwingfly.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nThis is a telegram bot that can be used to download files forwarded to the bot by the owner.\n\nBuild with Rust and Teloxide.\n\n## file sent directly to the bot\n\nThe bot will download the file and save it to the specified directory.\n\nThe owner can then react to the messages with emoji to manage the file:\n- \"👍\" | \"❤\": pin and move the file to favorite directory\n- \"👎\": move the file to trash\n\n## file sent to bot managed channel\n\nInitially, the bot owner send `/toggle \u003cbypasskey\u003e` to the bot to toggle among states:\n- `paused`: pause the bot\n- `active`: sync files and answer reactions\n- `partially active`: answer reactions but not sync files\n\n(the `\u003cbypasskey\u003e` can be seen in the log, and send `/bypasskey` to reprint the pwd in the log)\n\nThe bot will set \"🫡\" reaction to the file message to indicate the file is downloading.\n\nOnce done, the bot will set \"👌\". (\"😭\" if failed, \"😨\" if canceled, \"👾\" for inner bug)\n\nPeople can react to the file with emoji, and the bot will count the score of the file.\n\n| Emoji | Score |\n| --- | --- |\n|👍😁🙏😇🤗|+1|\n|❤🔥🥰🎉🍌💋💘😘|+2|\n|👎🤯😱😢🥴🌚😐🖕😨|-1|\n|🤬🤮💩🤡💔😡|-2|\n\nIf the score \u003e= fav_score_limit, the bot will hard-link the file to favorite directory and pin it.\n\nIf the score \u003c delete_score_limit, the bot will hard-link the file to trash and delete from channel.\n\nOtherwise, the bot will hard-link the file to normal directory and unpin the file if necessary.\n\nNote: it takes minites to get ReactionCountUpdate, so the bot will not handle reaction from channel immediately.\n\n# Deploy\n\nYou could create a `.env` file with the following content:\n\n```\n# Get from botfather\nTELOXIDE_TOKEN=xxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n# Your telegram id found in your profile\nBYPASS_USERS=xxxxx,xxxxx\n# if you want to use local server:\nTELEGRAM_API_ID=...\nTELEGRAM_API_HASH=...\n```\n\nDeploy:\n## File size limit 20MB\n\n```\nA telegram bot to sync files to local server.\n\nUsage: telegram_sync_bot \u003cCOMMAND\u003e\n\nCommands:\n  run     Run the bot\n  delete  Delete files by file_name in the data dir, and delete the record in the database, delete the message in the channel. The database should not be locked by other process, and there should not be any other bot instance.\n```\n\n```sh\ntelegram_sync_bot run -d /path/to/data\n```\n\n## No file size limit (local server)\n\nYou need to apply for telegram api id and hash from [Telegram](https://core.telegram.org/api/obtaining_api_id) first.\n(If you always get `Error` during applying, try `cloudflare warp` as VPN)\n\nAll methods below running local server in container first.\n\n(You can also run local server natively, just omit `-c` and `-i` args when start `telegram_sync_bot`.\nI'll just skip this method here)\n\nGet local server image first:\n\nPrepare (Windows and MacOS with podman only):\n```sh\npodman machine init -v /path/to/output:/path/to/output bot_machine\npodman machine start bot_machine\n```\n\nYou can use the following command to build the telegram api bot local server image:\n```sh\npodman build --target server -t server --network host server\n```\nOr download and load from the release page (`server.tar.gz`), I've built one through GitHub Action for you.\n\nWe provide 4 ways here:\n- native\n- pod\n- podman kube play\n- k8s\n\n### normal way: server in container but bot native\n\n```sh\npodman run --name server -itd --env-file .env -p 8081:8081 server\n\ntelegram_sync_bot run -d /path/to/output -l http://127.0.0.1:8081 -c podman -i server\n```\n\n### run as pod\n\nBuild `telegram_sync_bot` into container image:\n```sh\n# build bot image\npodman build --target bot -t bot:$(cargo pkgid -p telegram_sync_bot | sed -n \"s/.*@//p\") --network host bot\n```\nOr download and load from the release page (bot.tar.gz).\n\nStart server and bot in a pod:\n```sh\npodman pod create sync_bot\n\npodman run --pod sync_bot --name server -itd --env-file .env \\\n    -v /path/to/data:/app/data server\npodman run --pod sync_bot --name bot -itd --env-file .env --stop-signal SIGINT \\\n    -v /path/to/data:/app/data  \\\n    bot:0.X.0 \\\n    run -d /app/data -l http://server:8081\n```\n\n### run with podman kube play\n\nModify `sync-bot.yaml` to fit your need.\n\nYou can download and load `server.tar.gz` and `bot.tar.gz` from the release page first.\nOr command below will automatically build the images for you which cost a lot of time.\n```sh\npodman kube play sync-bot.yaml\n```\n\n### run with k8s\n\nBuild and save the image as `.tar.gz` or download from the release page first.\n\nModify `.env` and `k8s/pv.yaml` and so on to fit your need.\n```sh\n# load local images\nsudo ctr -n=k8s.io images import /tmp/server.tar.gz\nsudo ctr -n=k8s.io images import /tmp/bot.tar.gz\n\nsudo crictl image\n# you should see localhost/bot and localhost/server available\n\nkubectl apply -k .\n```\n\n# Systemd Service\n## Native without local server:\n```ini\n# /etc/systemd/system/sync-bot.service\n[Unit]\nDescription=Telegram file sync bot\nAfter=network-online.target\n\n[Service]\nType=simple\nUser=\u003c...\u003e\nWorkingDirectory=\u003c/path/to/output\u003e\nExecStart=/usr/local/bin/telegram_sync_bot run\nRestart=on-failure\nEnvironment=\"TELOXIDE_TOKEN=\u003c...\u003e\"\nEnvironment=\"BYPASS_USERS=\u003c...\u003e\"\n\n[Install]\nWantedBy=multi-user.target\n```\n## or with local server container and native telegram_sync_bot (after the first setup):\n```ini\n# /etc/systemd/system/sync-bot.service\n[Unit]\nDescription=Telegram file sync bot\nAfter=network-online.target\n\n[Service]\nType=simple\nUser=\u003c...\u003e\nWorkingDirectory=\u003c/path/to/output\u003e\nExecStartPre=/usr/bin/podman restart server\nExecStart=/usr/local/bin/telegram_sync_bot run -l http://127.0.0.1:8081 -c podman -i server\nExecStop=/bin/bash -c 'kill -SIGINT $MAINPID; for i in {1..5}; do sleep 1; kill -0 $MAINPID 2\u003e/dev/null || exit 0; done; kill -SIGKILL $MAINPID'\nExecStopPost=/usr/bin/podman stop server\nRestart=on-failure\nEnvironment=\"TELOXIDE_TOKEN=\u003c...\u003e\"\nEnvironment=\"BYPASS_USERS=\u003c...\u003e\"\n\n[Install]\nWantedBy=multi-user.target\n```\n## or with pure pod (after images are built or loaded):\n```ini\n# /etc/container/systemd/users/\u003cUserID\u003e/sync-bot.kube\n[Unit]\nDescription=Telegram file sync bot\nAfter=network-online.target\n\n[Kube]\nYaml=/etc/containers/systemd/users/\u003cUserID\u003e/sync-bot.yaml\n\n[Install]\nWantedBy=default.target\n```\nSearch `podman quadlet` for using podman kube play as systemd service.\n\n```sh\nsystemctl --user daemon-reload\nsystemctl start --user sync-bot\n```\n\nNote: you can use `/usr/lib/systemd/system-generators/podman-system-generator --user --dryrun` to check the generated service file.\n\n# Tips\n\nUse `fd` to delete database, channel message, and files in the data dir,\n\n```sh\nfd \".*\\.[jpg|mp4]\" '/path/to/data' -X podman run --name bot -it --env-file .env -v /path/to/data:/app/data --replace bot:0.X.0 delete -d /app/data {/}\n```\n\n# Development\n\n**Rust 2024 is essencial**\n\nSet `DATABASE_URL` in `.env` to generate entity crate.\n\n```\n# .env\nDATABASE_URL=sqlite://data/data.db\n```\n\nThen you can run the following command to create the database and generate the entity:\n\n```sh\ncargo install sea-orm-cli\nmkdir data\nsea-orm-cli migrate refresh\nsea-orm-cli generate entity --expanded-format -o bot/src/storage/entity/inner\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingwingfly%2Ftelegram_sync_bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkingwingfly%2Ftelegram_sync_bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingwingfly%2Ftelegram_sync_bot/lists"}