Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain chatid of a private channel by given joinlink using Telegram API?

I have a join link like this: https://t.me/joinchat/AAAAAEI95pT9clShebEcMg

I want to know the functions that leads me to obtain the chatid of that channel.

Thank you.

like image 747
Burzum Avatar asked Jan 18 '26 09:01

Burzum


1 Answers

You may use telegram API function messages.checkChatInvite

from telethon import TelegramClient
from telethon.tl.functions.messages.check_chat_invite import CheckChatInviteRequest


client = TelegramClient('session_id', '+phonenumber', api_id=1234, api_hash='0cxxxxxxx')
client.connect()

channel_hash = "AAAAAxxxxxxxx"
result = client.invoke(CheckChatInviteRequest(channel_hash))
print (result)

and the result would be something like this:

(chatInviteAlready (ID: 0x5abcdefg) = (chat=(channel (ID: 0x5abcdefg) = (creator=None, kicked=None, left=None, editor=True, moderator=None, broadcast=True, verified=None, megagroup=None, restricted=None, democracy=None, signatures=None, min=None, id=123456789, access_hash=615xxxxxxxxx, title=testChannel, username=None, photo=(chatPhotoEmpty (ID: 0x37xxxxxxx) = ()), date=2017-06-14 14:34:50, version=0, restriction_reason=None))))

Here the id in the response is the channel id you are looking for. The above example is using Telethon and python, but you may use any language and client to connect to telegram API.

like image 62
apadana Avatar answered Jan 21 '26 09:01

apadana