import re, telethon
from telethon import TelegramClient, sync
from telethon import events
from telethon.tl.functions.messages import ImportChatInviteRequest
api_id = '' # https://my.telegram.org/apps
api_hash = ''
client = TelegramClient('session', api_id, api_hash)
@client.on(events.NewMessage())
async def normal_handler(event):
user_mess = event.message.to_dict()['message']
print(user_mess)
if re.search(r'https://t.m', user_mess):
m = re.search(r'e/\S+', user_mess).group(0)
r = m[3:]
print(r)
rs = await client(ImportChatInviteRequest(r))
print(rs)
client.start()
client.run_until_disconnected()