Reputation: 311
I read telegram channel messages:
channel = await self.client.get_entity(entity)
messages = await self.client.get_messages(channel, limit=lim)
text_df = pd.DataFrame(columns=[
'channel_id',
'message_id',
'message_text',
'message_datetime'
])
for x in messages:
message_list = list(range(4))
message_list[0] = int(tg_channel[0])
message_list[1] = int(x.id)
message_list[2] = str(x.raw_text) #str(x.message)
message_list[3] = str(x.date)
text_df.loc[len(text_df)] = message_list
print(len(x.raw_text))
print(len(x.text))
print(len(x.message))
print('\n ############# \n')
It is not expected that on the same channel I may get 1 message containing text, and 4 other without text. I tried manual checking of those messages in telegram, and all I found is that messages with video content attached, but text below, do not return texts, but I am not sure if this is a 100% chance. I also saw messages with photos attached sometimes do not return text. I was getting the same outcome for message.raw_text
, message.text
, and message.message
, example is below.
Trying to get messages for https://t.me/DtRoad
0 0 0
#############
0 0 0
#############
0 0 0
#############
1011 1068 1011
#############
953 1019 953
#############
Got 5 messages
Two of them contain non-empty text content only.
What factor could affect the absence of the text?
Edit as of 18 december 2024.
Trying to get messages for https://t.me/bpshkola
0 0 0
#############
Got 1 messages
I got again an empty text, and immediately checked the telegram message
So it has text/captions and some pictures. It is still not clear why I get no text of that message.
Upvotes: 0
Views: 50
Reputation: 7141
Messages with media and without captions, or service messages, do not have text.
Upvotes: 1