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

How to get channel/chat/user name of forwarded message? #335

Closed
mnvx opened this issue Oct 13, 2017 · 2 comments
Closed

How to get channel/chat/user name of forwarded message? #335

mnvx opened this issue Oct 13, 2017 · 2 comments

Comments

@mnvx
Copy link
Contributor

mnvx commented Oct 13, 2017

I try to get name of channel by channel id:

    result = self._client(GetHistoryRequest(
            entity,
            limit=100,
            offset_date=None,
            offset_id=0,
            max_id=0,
            min_id=last_read_message_id,
            add_offset=0
        ))
    for message in result.messages:
        if isinstance(message.fwd_from, MessageFwdHeader):
            fwd_channel_id = message.fwd_from.channel_id
            if fwd_channel_id:
                fwd_result = self._client(GetFullChannelRequest( # problem!!!
                    InputPeerChannel(message.fwd_from.channel_id, 0)
                ))

message.fwd_from looks like:

    fwd_from=MessageFwdHeader(
      channel_id=1053596007, 
      date=datetime.fromtimestamp(1507891987.0), 
      post_author=None, # None!!!
      from_id=None, 
      channel_post=3030
    ), 

So, I cant take channel name from message.fwd_from. And I dont join into this channel.

When I try to call GetFullChannelRequest, I have next error:

ChannelInvalidError(...), 'Invalid channel object. Make sure to pass the right types, for instance making sure that the request is designed for channels or otherwise look for a different one more suited.'

How to get name of channel properly?

ps
Question on stackoverflow

@Lonami
Copy link
Member

Lonami commented Oct 13, 2017

You should be able to client.get_input_entity(PeerChannel(fwd.from_id)), as the library saves id/hash pairs automatically and by default for you. Using 0 as the hash for the InputChannel simply won't work.

@Lonami Lonami closed this as completed Oct 13, 2017
@mnvx
Copy link
Contributor Author

mnvx commented Oct 13, 2017

@Lonami Thanks so much! It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants