I am making a script to analyse a telegram channel.
I would like to get the event.id or event.text of the original message when the channel is replying on a previous message.
Of course I looked in into the documentation but I am not able to figure it out.
My code:
@telegram_client.on(events.NewMessage(chats=testchannel))
def new_message_testchannel(event):
message_raw_text = event.raw_text
if event.is_reply:
print('Reply')
# Get original message ID and or content
message_raw_text_reply = event.get_message_reply()
# or
message_raw_text_reply = event.get_message_reply().raw_text
# or
message_raw_text_reply = event.get_message_reply().id
print(message_raw_text_reply)
else:
print('Normal message: ', message_raw_text)
telegram_client.start()
telegram_client.run_until_disconnected()
2
Answers
It had indeed something to do with the async here is my code example that is working :-)
Your code is partially correct but is missing the asyncio part.
Telethon is an async library so all network calls need to be awaited.