pythontelegram-bottelethon

how to work with topics through telethon?


I need to receive messages from a specific topic, and send them to my channel. there are no problems with sending, but when I try to receive a message from a group, I cannot understand which topic the message is from.

(it is not necessary to use telethon)

import asyncio


import telethon
from telethon import TelegramClient, events

api_id = 
api_hash = ""

client = TelegramClient("session_name", api_id, api_hash)
client.start()


@client.on(events.NewMessage([-1001941512580]))
async def main(event):
    print(event)

client.run_until_disconnected()

Solution

  • In v1, the topic is inside the MessageReplyHeader:

    msg = event.message
    if msg.reply_to and msg.reply_to.forum_topic:
        topic_id = msg.reply_to.reply_to_top_id