skip to Main Content

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.stack.imgur.com/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.

2

Answers


  1. 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()
    
    Login or Signup to reply.
  2. 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() 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search