Kurina11
Kurina11

Reputation: 105

How to read message that has been replied to in telegram using telethon

I need to have script to read last message of telegram channel. If last message of this channel is reply to something I want to read that message what has last message answered to. For example highlighted message on this picture.

https://i.sstatic.net/cRSzS.jpg

I have this code to read last message but I have no idea how to read that message, I know I can use parameter is_reply to know if last message is reply to something but I don't know what to do next, any ideas?

async def get_mess():
    limit = 1
    global new
    async for message in client.iter_messages('Passive Lifestyle Forex Signals', limit):
        new = message.text

whlie True:
    get_mess()

I know it isn't most effective but that's not important. Any ideas how to code this? I can answer you if you need something more specific.

Upvotes: 1

Views: 5606

Answers (2)

TheKill-996
TheKill-996

Reputation: 1069

I would suggest to use get_messages to get the last message so you can also omit the limit. Then you'll need to check if the message is replying to an another message and if yes, get it.

   async def get_mess():
       global new
       message = await client.get_messages('YOUR CHAT') # you can omit the limit
       if message.is_reply:
           new = await message.get_reply_message()
   while True:
       get_mess() 

Upvotes: 1

stranger555
stranger555

Reputation: 59

async def get_mess():
    limit = 1
    global new
    async for message in client.iter_messages('Passive Lifestyle Forex Signals', limit):
        new = message
        if new.reply_to_msg_id:
            yourtext = await new.get_reply_message()

whlie True:
    get_mess()

Upvotes: 0

Related Questions