Похожие чаты

Hello. Recently, I needed to get information about the channel

from the forward of its post to the bot. In the past, I made telegram bots in js with the Telegraf library and also in python with the telegram.ext library. I noticed that the telethon in the message object (from the context/event) does not provide the username and title information of the channel from the forward. The event has a header from which I can get the title, but as a result it is impossible to get the username of the channel, which means it is impossible to get the channel entity, since in telethon it is impossible to get the entity by the channel_id and title of the channel until the library "remembers" it and associates the channel_id with username, which means that without knowing the username in advance, it is impossible to get any information about the channel. (when trying to get_entity by channel_id from the message object, the library throws a ValueError "channel not found"). At the same time, telegram.ext gives out all the necessary information about the channel from the forward. Is this a bug or a feature?

And why the library removes -100 from chat id and calls it "channel id", i didn't find such mention in telegram api (getChat request requires chat id with -100 at the beginning)

Telethon forwarded message:
Message(id=595, peer_id=PeerUser(user_id=blabla), date=datetime.datetime(2023, 6, 11, 16, 40, 12, tzinfo=datetime.timezone.utc), message="bla", out=False, mentioned =False, media_unread=False, silent=True, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=MessageFwdHeader(date=datetime.datetime(2016) , 6, 7, 12, 59, 49, tzinfo=datetime.timezone.utc), imported=False, from_id=PeerChannel( only infromation channel_id=1049298544), from_name=None, channel_post=232, post_author=None, saved_from_peer=None, saved_from_msg_id =None, psa_type=None), via_bot_id=None, reply_to=None, media=None, reply_markup=None, entities=[], views=40754, forwards=2, replies=None, edit_date=None, post_author=None, grouped_id =None, reactions=None, restriction_reason=[], ttl_period=None)


Telegram.ext forwarded message:
Message(channel_chat_created=False, chat=Chat(first_name='Artem', id=895849563, type=<ChatType.PRIVATE>, username='Z3R0F0'), date=datetime.datetime(2023, 6, 11, 16, 28 , 49, tzinfo=<UTC>), delete_chat_photo=False, forward_date=datetime.datetime(2016, 6, 7, 12, 59, 49, tzinfo=<UTC>), forward_from_chat=Chat ( proper chat_id id=-1001049298544, title= 'VICE News Italia', type=<ChatType.CHANNEL>, here we go username='VICEnewsIT')...

2 ответов

11 просмотров

real channel ids don't have -100, that's just a bot api thing. Telethon doesn't use the bot api, so it doesn't have prefixes (but for compatibility reasons, it still accepts prefixed ids as input in most places)

for the ValueError part: 1- you have likely deleted the .session file and cache was gone. (if you haven't instantly inside the event handler did get_entity to that id) 2- server didn't send the full Channel object, you may need to refetch the message for now check the message.forward.chat custom class, it's not visible when printing, but that may have the Channel object for the -100 of ids, that's also as mentioned that's a botApi thing, telethon supports it in passing mode (note: also make sure you passed the id with -100 to get_entity, it might've mistaken it for user otherwise) telethon doesn't "need" it, just a simplification to store chat type in int, telethon is a full api, it's more common to use objects, you can pass the whole PeerChannel(id) object to get_entity instead of -100 to make chat type of id

Похожие вопросы

Обсуждают сегодня

30 BCH videos in Hausa Language successfully delivered. In December 2023, I created a Flipstarter to produce Bitcoin Cash videos in the Hausa language for greater outreach an...
Munnir
5
читать файл максимально быстро? странный вопрос))
zamtmn
53
братва! где куличи брать?
Alöscha
25
тоесть, указав return eax, сгенерируется никому ненужная инструкция mov eax,eax ?
Aiwan \ (•◡•) / _bot
24
Посоветуйте пожалуйста аудио плеер для библиотеки mp3- FLAC на компьютере. На Винде пользовался Aimp, в том числе для конвертации. Много нужных команд было прямо в контекст...
Виктор Кузнецов
31
📢Join the FUNToken X Pamtoken Zealy Campaign - Let the Quest Begin!🔥 📢Attention, FUNToken Community! We're excited to announce the launch of our Zealy Campaign in collaborat...
OJohnny
7
Добрый день. Созданию отношения таблиц для учёта кораблей, их движения между точками (портами) согласно расписания. Терзают сомнения в правильном ли направлении двигаюсь 😅 1...
Aleksey
1
Is FXTL another frax ecosystem token? Why need fxtl when there is already fxs? Why cant I find a straight answer for this? Maybe thats why people think its all so complicated
MBD Tan
12
Компания Elif ищет менеджера проектов, который будет заниматься поиском и ведением новых проектов. Прежде чем приступить к работе, вам нужно пройти наш недельный курс, где вы ...
Elif
1
Hi guys , do we have update on voting?
HB
16
Карта сайта