Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

what is the correct way to get channel/chat/user name of forwarded message? #47

Closed
AmirMahmood opened this issue Apr 12, 2018 · 4 comments
Labels

Comments

@AmirMahmood
Copy link

AmirMahmood commented Apr 12, 2018

what is the correct way to get channel/chat/user name and title of forwarded message?

p.s : I have the same question as LonamiWebs/Telethon#335

@delivrance
Copy link
Member

It depends whether you want to listen for new Messages or retrieve old ones.
In both cases you'll end up with a Message object which contains the optional fwd_from field; if the field exists (i.e.: is not None) the message is a forwarded message.

@AmirMahmood
Copy link
Author

i listen for updates with below code. i get forward id from "message.fwd_from" but how can i get username and title of channel or User by this id ?

def update_handler(client, update, users, chats):
    if isinstance(update, types.UpdateNewChannelMessage):
        message = update.message

        if isinstance(message, types.Message):  # Filter by Message to exclude MessageService and MessageEmpty
            if not chats[message.to_id.channel_id].megagroup:  # Only handle messages from Channels not Supergroups
                message_fwd_from_id = None
                message_fwd_from_username = None
                message_fwd_from_title = None

                if message.fwd_from is not None:
                    if message.fwd_from.channel_id is not None:
                        message_fwd_from_id = message.fwd_from.channel_id
                        message_fwd_from_username = ???
                        message_fwd_from_title = ???
                    if message.fwd_from.from_id is not None:
                        message_fwd_from_id = message.fwd_from.from_id
                        message_fwd_from_username = ???
                        message_fwd_from_title = ???

client.set_update_handler(update_handler)

@AmirMahmood
Copy link
Author

I have the same question as LonamiWebs/Telethon#335

@delivrance
Copy link
Member

From https://docs.pyrogram.ml/pyrogram/Client#pyrogram.Client.set_update_handler

chats (dict) – Dictionary of all Chat and Channel mentioned in the update. You can access extra info about the chat (such as title, participants_count, etc…) by using the IDs you find in the update argument (e.g.: chats[1701277281]).

omg-xtao pushed a commit to TeamPGM/pyrogram that referenced this issue May 13, 2024
…am#48)

* fix miss service message for MessageActionChatJoinedByRequest

Closes pyrogram#47 

---------

Co-authored-by: KurimuzonAkuma <31959970+KurimuzonAkuma@users.noreply.github.com>
meybj pushed a commit to meybj/pyrogram that referenced this issue May 30, 2024
…am#48)

* fix miss service message for MessageActionChatJoinedByRequest

Closes pyrogram#47 

---------

Co-authored-by: KurimuzonAkuma <31959970+KurimuzonAkuma@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants