diff --git a/telethon/utils.py b/telethon/utils.py index 40ab9e3e..b781e937 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -211,6 +211,12 @@ def get_input_peer(entity, allow_self=True, check_hash=True): if isinstance(entity, types.InputUserSelf): return types.InputPeerSelf() + if isinstance(entity, types.InputUserFromMessage): + return types.InputPeerUserFromMessage(entity.peer, entity.msg_id, entity.user_id) + + if isinstance(entity, types.InputChannelFromMessage): + return types.InputPeerChannelFromMessage(entity.peer, entity.msg_id, entity.channel_id) + if isinstance(entity, types.UserEmpty): return types.InputPeerEmpty() @@ -248,6 +254,9 @@ def get_input_channel(entity): if isinstance(entity, types.InputPeerChannel): return types.InputChannel(entity.channel_id, entity.access_hash) + if isinstance(entity, types.InputPeerChannelFromMessage): + return types.InputChannelFromMessage(entity.peer, entity.msg_id, entity.channel_id) + _raise_cast_fail(entity, 'InputChannel') @@ -285,6 +294,9 @@ def get_input_user(entity): if isinstance(entity, types.InputPeerUser): return types.InputUser(entity.user_id, entity.access_hash) + if isinstance(entity, types.InputPeerUserFromMessage): + return types.InputUserFromMessage(entity.peer, entity.msg_id, entity.user_id) + _raise_cast_fail(entity, 'InputUser') @@ -854,11 +866,11 @@ def get_peer(peer): return types.PeerUser(peer.user_id) peer = get_input_peer(peer, allow_self=False, check_hash=False) - if isinstance(peer, types.InputPeerUser): + if isinstance(peer, (types.InputPeerUser, types.InputPeerUserFromMessage)): return types.PeerUser(peer.user_id) elif isinstance(peer, types.InputPeerChat): return types.PeerChat(peer.chat_id) - elif isinstance(peer, types.InputPeerChannel): + elif isinstance(peer, (types.InputPeerChannel, types.InputPeerChannelFromMessage)): return types.PeerChannel(peer.channel_id) except (AttributeError, TypeError): pass