Похожие чаты

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 ответов

39 просмотров

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

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

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

30500 за редактор? )
Владимир
47
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Anyone else having this error when trying to make transactions?
Datzel
11
Question: How viable is it to use Anvil as the backend infrastructure for managing a TradFi portfolio, while integrating Flexa for instant liquidity and payment solutions? Cou...
Kevin
2
вы делали что-то подобное и как? может есть либы готовые? увидел картинку нокода, где всё линиями соединено и стало интересно попробовать то же в ddl на lua сделать. решил с ч...
Victor
8
Карта сайта