Skip to content

Forwarding messages

Lonami edited this page Jun 9, 2017 · 9 revisions

For some reason, ForwardMessageRequest (note it's Message, singular) does not seem to work.

You should use ForwardMessagesRequest (note it's Messages, plural) as follows:

from telethon.utils import generate_random_long
from telethon.helpers import get_input_peer

messages = foo()  # Logic to retrieve a few messages.
from_entity = bar()  # Who has the original messages.
to_entity = baz()  # Who you want to forward them to.

client.invoke(ForwardMessagesRequest(
    from_peer=get_input_peer(from_entity),
    id=[msg.id for msg in messages],
    random_id=[generate_random_long() for _ in range(len(messages))],
    to_peer=get_input_peer(to_entity)
))

The named arguments are there for clarity, although they're not needed because they appear in order. You can obviously just wrap a single message on the list too, if that's all you have.