All Projects → cuamckuu → tg-inviter

cuamckuu / tg-inviter

Licence: MIT license
Generate personal invite links for Telegram channels

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to tg-inviter

Google-IAP
Android Library for easing Google Play Billing to your apps with support for Subscriptions, In-App Purchases and Consumables with a beautiful sample app.
Stars: ✭ 129 (+396.15%)
Mutual labels:  subscription, subscriptions
telegram-channel-views-boost
A Python3 script built to increase post views on Telegram channels.
Stars: ✭ 57 (+119.23%)
Mutual labels:  telegram-channel, telegram-channels
Cryptolist
Curated collection of blockchain & cryptocurrency resources.
Stars: ✭ 3,501 (+13365.38%)
Mutual labels:  links, telegram-channel
allukabot
Modular HunterxHunter themed Telegram Bot for managing your group with additional features.
Stars: ✭ 21 (-19.23%)
Mutual labels:  python-telegram-bot, telethon
ZeldrisRobot
An anime themed group management bot, running on python with telethon and ptb.
Stars: ✭ 41 (+57.69%)
Mutual labels:  python-telegram-bot, telethon
youtube-playlist
❄️ Extract links, ids, and names from a youtube playlist
Stars: ✭ 73 (+180.77%)
Mutual labels:  links
laravel-linkable
URL binding for Laravel models
Stars: ✭ 22 (-15.38%)
Mutual labels:  links
vue-link
One component to link them all 🔗
Stars: ✭ 65 (+150%)
Mutual labels:  links
Links
A responsive webpage for putting all our links in. A substitute for linktree created using HTML, CSS and JS using custom admin dashboard.
Stars: ✭ 18 (-30.77%)
Mutual labels:  links
Telegram-mailer
Web-application for sending messages to list of users. Use several accounts to avoid ban.
Stars: ✭ 28 (+7.69%)
Mutual labels:  telethon
utopia-crm
Utopía is an open source platform for community based newsrooms to manage their subscriptions
Stars: ✭ 15 (-42.31%)
Mutual labels:  subscription
AR9285-rebranding
Wireless card rebranding
Stars: ✭ 17 (-34.62%)
Mutual labels:  whitelist
Cryptora
An all in one cryptocurrency bot for Telegram.
Stars: ✭ 25 (-3.85%)
Mutual labels:  python-telegram-bot
cashier-paystack
Cashier provides an expressive, fluent interface to Paystack's subscription billing services.
Stars: ✭ 44 (+69.23%)
Mutual labels:  subscriptions
KGrabber
Userscript for extracting links from kissanime.ru and similar sites.
Stars: ✭ 29 (+11.54%)
Mutual labels:  links
telemirror
Telegram forwarder from channels via Telegram Client API (telethon)
Stars: ✭ 66 (+153.85%)
Mutual labels:  telethon
get cnip
获取国内 IP 和域名,生成路由表和 PAC 文件
Stars: ✭ 206 (+692.31%)
Mutual labels:  whitelist
killbill-admin-ui
Kill Bill Administrative UI engine
Stars: ✭ 39 (+50%)
Mutual labels:  subscriptions
spotify telegram bio updater
This userbot updates the biography of a telegram user according to their current spotify playback.
Stars: ✭ 21 (-19.23%)
Mutual labels:  telethon
robustlinks
Links on the web break all the time, robustify them!
Stars: ✭ 40 (+53.85%)
Mutual labels:  links

Alert

Telegram team added new invite links

Along with the main invite link, owners and admins can now create additional links with a limited duration, number of uses, or both.

So, this library seems outdated and should not be used. Prefer createChatInviteLink from docs


Telegram Inviter - tginviter

tginviter is a Python3 module to generate and process personal invite links for Telegram channels.

Demo

Demo GIF

Why tginviter?

Some projects requires personal invite liks for joining channels, because joinchat link is can easy be stolen. Unfortunately, Telegram API and existing Pytohn modules lacks functional to protect invite links, that's why I decided to code it by myself.

How does it work?

This module combines power of python-telegram-bot and telethon , so that tginviter can use bot's and client's Telegram API at the same time.

  • python-telegram-bot and bot's API is used to process deeplinks and store invite tokens to some kind of users whitelist.

  • telethon and client's API is used for periodic checks that all users in channels are in whitelist, othervise that user will be banned.

Both actions are highly customizable for your purposes, cause they are specified by callback functions deeplink_handler and job_handler.

Installation

For now you could clone repository and copy module to needed location. Soon I will add more convinient way to install.

git clone https://github.com/cuamckuu/tg-inviter.git
cd tg-inviter
python setup.py install

# Or

python -m pip install git+https://github.com/cuamckuu/tg-inviter.git#egg=tg-inviter

Usage

See example.py to find code used in gif.

Specify your keys in .env file or in code:

# Telethon
export TELETHON_API_ID='12***19'
export TELETHON_API_HASH='48c***559417****120eae******2798'
export TELETHON_SESSION_NAME="./sessions/Inviter.session"

# py-telegram-bot
export TELEGRAM_BOT_TOKEN='13921*****:AAGLC**********v1OMJdy9-****wI6hy-U'

Create callback functions deeplink_handler and job_handler

In example I did it like so:

def create_callbacks(storage, client):
    def deeplink_handler(update, context):
        if not context.args:
            return

        token = context.args[0]
        if storage.uses_left(token) <= 0:
            if update.message:
                update.message.reply_text("Error")
            return

        payload = storage.get_payload(token)

        joinchat_key = payload["joinchat_key"]
        keyboard = InlineKeyboardMarkup.from_button(
            InlineKeyboardButton(
                text="Join channel",
                url=generate_joinchat_link(joinchat_key)
            )
        )

        channel_id = payload["channel_id"]
        user_id = update.effective_user.id

        storage.add_subscription(channel_id, user_id)
        storage.count_new_use(token)

        if update.message:
            update.message.reply_text(
                "Success",
                reply_markup=keyboard
            )

    job_num = 0
    def job_handler(context):
        nonlocal job_num
        job_num += 1

        if job_num == 1:
            for channel_id in storage.get_channel_ids():
                client.subscribe_everyone(channel_id, storage)
        else:
            for channel_id in storage.get_channel_ids():
                client.ban_extra_users(channel_id, storage)

    return deeplink_handler, job_handler

Initialize Storage, PythonTelegramBot and TelethonClient

Storage shoild be inherited from tginviter.storage.BaseStorage. You can add support for your database or ORM.

storage = MemoryStorage()

client = TelethonClient(
    api_id=TELETHON_API_ID,
    api_hash=TELETHON_API_HASH,
    session=TELETHON_SESSION_NAME
)

deeplink_handler, job_handler = create_callbacks(storage, client)
bot = PythonTelegramBot(
    token=TELEGRAM_BOT_TOKEN,
    deeplink_handler=deeplink_handler,
    job_handler=job_handler,
    interval=4  # Call job_handler every 4 seconds
)
bot_name = bot.get_name()

Generate invite links, add them to storage and start bot

Payload 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.

payload = {
    "channel_id": -100123123123,  # Your channel id
    "joinchat_key": "AAAAAEzKBlgClOKabErxyg",  # Last part from joinchat url
}

link, token = generate_invite_link(bot_name)
storage.insert(token, max_uses=1, payload=payload)
print(link)

# Generate and save more links here, if needed...

bot.start()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].