{"id":13988550,"url":"https://github.com/cuamckuu/tg-inviter","last_synced_at":"2025-07-22T09:31:17.440Z","repository":{"id":43166438,"uuid":"288869263","full_name":"cuamckuu/tg-inviter","owner":"cuamckuu","description":"Generate personal invite links for Telegram channels","archived":false,"fork":false,"pushed_at":"2022-10-07T23:33:53.000Z","size":3084,"stargazers_count":46,"open_issues_count":0,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-29T07:36:46.595Z","etag":null,"topics":["bot","inviter","invites","links","moderator","python-telegram-bot","subscription","subscriptions","telegram","telegram-channel","telegram-channels","telethon","whitelist"],"latest_commit_sha":null,"homepage":"","language":"Python","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/cuamckuu.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-20T00:45:43.000Z","updated_at":"2024-11-20T23:59:22.000Z","dependencies_parsed_at":"2023-01-19T14:40:13.282Z","dependency_job_id":null,"html_url":"https://github.com/cuamckuu/tg-inviter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cuamckuu/tg-inviter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuamckuu%2Ftg-inviter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuamckuu%2Ftg-inviter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuamckuu%2Ftg-inviter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuamckuu%2Ftg-inviter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cuamckuu","download_url":"https://codeload.github.com/cuamckuu/tg-inviter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuamckuu%2Ftg-inviter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266465059,"owners_count":23933052,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","inviter","invites","links","moderator","python-telegram-bot","subscription","subscriptions","telegram","telegram-channel","telegram-channels","telethon","whitelist"],"created_at":"2024-08-09T13:01:13.839Z","updated_at":"2025-07-22T09:31:16.668Z","avatar_url":"https://github.com/cuamckuu.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Alert\n\nTelegram team added new [invite links](https://telegram.org/blog/autodelete-inv2?ln=r#expiring-invite-links) \n\n\u003e Along with the main invite link, owners and admins can now create additional links with a limited duration, number of uses, or both.\n\nSo, this library seems outdated and should not be used. Prefer `createChatInviteLink` from [docs](https://core.telegram.org/bots/api#createchatinvitelink)\n\n---\n\n# Telegram Inviter - `tginviter`\n\n`tginviter` is a Python3 module to generate and process personal invite links for Telegram channels.\n\n## Demo\n![Demo GIF](./demo.gif)\n\n## Why `tginviter`?\n\nSome projects requires personal invite liks for joining channels, because joinchat link is can easy be stolen. Unfortunately, Telegram API and existing Python modules lacks functional to protect invite links, that's why I decided to code it by myself.\n\n## How does it work?\n\nThis module combines power of [`python-telegram-bot`](https://github.com/python-telegram-bot/python-telegram-bot) and [`telethon`](https://github.com/LonamiWebs/Telethon) , so that `tginviter` can use bot's and client's Telegram API at the same time.\n\n- `python-telegram-bot` and bot's API is used to process [deeplinks](https://core.telegram.org/bots#deep-linking) and store invite tokens to some kind of users whitelist.\n\n- `telethon` and client's API is used for periodic checks that all users in channels are in whitelist, othervise that user will be banned.\n\nBoth actions are highly customizable for your purposes, cause they are specified by callback functions `deeplink_handler` and `job_handler`.\n\n## Installation\n\nFor now you could clone repository and copy module to needed location.\n**Soon I will add more convinient way to install**.\n\n```bash\ngit clone https://github.com/cuamckuu/tg-inviter.git\ncd tg-inviter\npython setup.py install\n\n# Or\n\npython -m pip install git+https://github.com/cuamckuu/tg-inviter.git#egg=tg-inviter\n```\n\n## Usage\n\nSee `example.py` to find code used in gif.\n\n### Specify your keys in `.env` file or in code:\n```bash\n# Telethon\nexport TELETHON_API_ID='12***19'\nexport TELETHON_API_HASH='48c***559417****120eae******2798'\nexport TELETHON_SESSION_NAME=\"./sessions/Inviter.session\"\n\n# py-telegram-bot\nexport TELEGRAM_BOT_TOKEN='13921*****:AAGLC**********v1OMJdy9-****wI6hy-U'\n```\n\n### Create callback functions `deeplink_handler` and `job_handler`\n\nIn example I did it like so:\n\n```python3\ndef create_callbacks(storage, client):\n    def deeplink_handler(update, context):\n        if not context.args:\n            return\n\n        token = context.args[0]\n        if storage.uses_left(token) \u003c= 0:\n            if update.message:\n                update.message.reply_text(\"Error\")\n            return\n\n        payload = storage.get_payload(token)\n\n        joinchat_key = payload[\"joinchat_key\"]\n        keyboard = InlineKeyboardMarkup.from_button(\n            InlineKeyboardButton(\n                text=\"Join channel\",\n                url=generate_joinchat_link(joinchat_key)\n            )\n        )\n\n        channel_id = payload[\"channel_id\"]\n        user_id = update.effective_user.id\n\n        storage.add_subscription(channel_id, user_id)\n        storage.count_new_use(token)\n\n        if update.message:\n            update.message.reply_text(\n                \"Success\",\n                reply_markup=keyboard\n            )\n\n    job_num = 0\n    def job_handler(context):\n        nonlocal job_num\n        job_num += 1\n\n        if job_num == 1:\n            for channel_id in storage.get_channel_ids():\n                client.subscribe_everyone(channel_id, storage)\n        else:\n            for channel_id in storage.get_channel_ids():\n                client.ban_extra_users(channel_id, storage)\n\n    return deeplink_handler, job_handler\n  ```\n\n### Initialize `Storage`, `PythonTelegramBot` and `TelethonClient`\n\nStorage shoild be inherited from `tginviter.storage.BaseStorage`. You can add support for your database or ORM.\n\n```python3\nstorage = MemoryStorage()\n\nclient = TelethonClient(\n    api_id=TELETHON_API_ID,\n    api_hash=TELETHON_API_HASH,\n    session=TELETHON_SESSION_NAME\n)\n\ndeeplink_handler, job_handler = create_callbacks(storage, client)\nbot = PythonTelegramBot(\n    token=TELEGRAM_BOT_TOKEN,\n    deeplink_handler=deeplink_handler,\n    job_handler=job_handler,\n    interval=4  # Call job_handler every 4 seconds\n)\nbot_name = bot.get_name()\n```\n### Generate invite links,  add them to `storage` and start bot\n\nPayload must contain `channel_id` and `joinchat_key` to proprly create users whitelist and 'Join channel' button. Also you can add own keys to payload, if needed.\n```python3\npayload = {\n    \"channel_id\": -100123123123,  # Your channel id\n    \"joinchat_key\": \"AAAAAEzKBlgClOKabErxyg\",  # Last part from joinchat url\n}\n\nlink, token = generate_invite_link(bot_name)\nstorage.insert(token, max_uses=1, payload=payload)\nprint(link)\n\n# Generate and save more links here, if needed...\n\nbot.start()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuamckuu%2Ftg-inviter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuamckuu%2Ftg-inviter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuamckuu%2Ftg-inviter/lists"}