Closed msa21974 closed 7 years ago
Sorry could you please be a bit more specific? You don't show how you forward the messages, which is the really relevant part.
For Example i wrote this codes :
total_count, messages , senders = client.get_message_history(Channel_entity, limit=10) messages[0].id 2719 client.invoke(forward_message.ForwardMessageRequest(InputPeerUser(User_entity.id,User_entity.access_hash),messages[0].id,6558654545555))
telethon.errors.RPCError: (RPCError(...), 'Unknown error message with code 400: MESSAGE_ID_INVALID')
"6558654545555" is random id that prevent to send duplicate message (should be unique)
i do same way for UserEntity and get messages then forward them without error!
can you test it yourself?
I don't even think ForwardMessageRequest
works. Definitely try ForwardMessagesRequest
(note the s). Take a look at the original tdesktop
if you need more information. Like forwarding a single message doesn't specify to who you're forwarding while the plural method does.
I just tried ForwardMessageRequest
and it works. All I did was:
!h
istory.self.invoke(ForwardMessageRequest(get_input_peer(entity), <ID>, generate_random_long()))
.Closing this issue.
I still have this issue with ForwardMessageRequest. The first parameter is the destination chat which is fine. The 2nd parameter (message_id) is the issue because it's not unique. When I get the message history of a channel, it starts with 1, 2, 3, etc. When I forward message wrong message from another chat gets forwarded, not from the channel I intended. message_id by itself doesn't seem to be unique, and source channel should be also specified, or there should be some other ID to use.
Here is my code:
total_count, messages, senders = client.get_message_history(
source_chat, limit=10)
for msg in reversed(messages):
print ("msg:", msg.id, msg)
msg = messages[0]
print ("msg id:", msg.id) # prints 1!
dest_chat = InputPeerChat(dest_chat_id)
result = client.invoke(ForwardMessageRequest(dest_chat, msg.id, generate_random_long()))
@KiteBoarder did you try using ForwardMessageRequest
as I mentioned above?
@Lonami I tried to follow your steps in my code above. Is there anything different? There are two ids, one is a hex and another one is int which has small value and is not definitely unique. Which ID are you using?
Because of the bug in InteractiveTelegramClient for channels which !h doesn't print I am not sure which ID you are referring to for channels. The bug is fixed but it's not there in pip. So I just printed the message myself and observed there are two IDs. With the small id we definitely forward wrong message.
from_peer | who has the original messages |
id | id of the messages to forward |
to_peer | to who you want to forward them |
one is a hex
What?
This is a print of a message from a channel. One ID is 0xc09bexxx (hex) and there is another id: 12.
(message (ID: 0xc09bexxx) = (out=None, mentioned=None, media_unread=None, silent=None, post=True, id=12, from_id=None, to_id=(peerChannel (ID: 0xbdddexxx) = (channel_id=1137398xxx)), fwd_from=None, via_bot_id=None, reply_to_msg_id=None, date=2017-06-17 12:02:12, message=hi, media=None, reply_markup=None, entities=None, views=2, edit_date=None))
The one you have posted (from_peer, id, to_peer) is for forwardedMessages with s, not forwardMessage. I thought you had mentioned you tested forwardMessageRequest (with no s) and it works, isn't that true?
By the way @KiteBoarder the (ID: 0x123456)
is just the ID of the class so you don't have to censor that.
I thought you had mentioned you tested forwardMessageRequest (with no s) and it works, isn't that true?
Yes I tested it, but probably not with a channel. I can't remember now. Anyway the plural form is way more powerful. Telegram's API has a few of these strange things (like this).
@KiteBoarder did you make it work? At the moment I am trying to use https://lonamiwebs.github.io/Telethon/methods/channels/get_messages.html
However, I am getting the channel's message id only. So I can't do proper forward because of
telethon.errors.rpc_error_list.MessageIdInvalidError: (MessageIdInvalidError(...), 'The specified message ID is invalid')
The error with message ID confused me, was looking at wrong place. When I updated a little from_peer and to_peer parameters, it works. So the real problem was not in message id.
So the real problem was not in message id.
Different peer type (user or channel/megagroup), different message IDs. So yes it was probably an invalid ID.
Hi Dears, when i take messages with command total_count, messages, senders = client.get_message_history(entity, limit=10) and forward received messages , wrong message forwarded! but in user message (if entity is User) all job's work fine