Hello darkness, my old friend,
I've come to talk with you again,
I'm trying to mark messages as read. To do this, I've checked issues, backuper.py and lib inner part.
Together I've combined code, but it doesn't work due to exceptions in stacktrace. What is wrong?
First - I get my channel Peer
#get peer of channel for testing
result = clientP(GetDialogsRequest(
offset_date=None,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=20
))
entities = clientP.get_dialogs(len(result.dialogs))
entity1 = entities[1][15] # entity of my channel for tests
peerP1 = clientP.get_input_entity(entity1)
messages = clientP.get_message_history(entity1, 100, None, 0, 0, 0, 0) // make sure there are 4 unread messages
Channel Peer variable and fields
CONSTRUCTOR_ID = {int} 548253432
SUBCLASS_OF_ID = {int} 3374092470
access_hash = {int} -5999047433666320008
channel_id = {int} 1125899094
confirm_received = {Event}
content_related = {bool} False
request_msg_id = {int} 0
rpc_error = {NoneType} None
I use send_read_acknowledge command
clientP.send_read_acknowledge(peerP, messages[1]) #exception
send_read_acknowledge stacktrace
File "C:/Users/Little-Dany/PycharmProjects/TG2/main2.py", line 296, in test
clientP.send_read_acknowledge(peerP, messages[1])
File "C:\Users\Little-Dany\AppData\Local\Programs\Python\Python36-32lib\site-packages\telethon\telegram_client.py", line 477, in send_read_acknowledge
max_id=max_id
File "C:\Users\Little-Dany\AppData\Local\Programs\Python\Python36-32lib\site-packages\telethon\telegram_bare_client.py", line 448, in call
result = self._invoke(sender, call_receive, *requests)
File "C:\Users\Little-Dany\AppData\Local\Programs\Python\Python36-32lib\site-packages\telethon\telegram_bare_client.py", line 506, in _invoke
raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_errors_400.PeerIdInvalidError: (PeerIdInvalidError(...), 'An invalid Peer was used. Make sure to pass the right peer type.')
I've found this behaviour strange. Fortunately there was another way to get peer
entity2 = clientP.get_input_entity('onetimeshit') #another way to cast channel
result = clientP(ReadHistoryRequest(entity2, 20))
ReadHistoryRequest stacktrace
File "C:/Users/Little-Dany/PycharmProjects/TG2/main2.py", line 312, in
test()
File "C:/Users/Little-Dany/PycharmProjects/TG2/main2.py", line 297, in test
result = clientP(ReadHistoryRequest(entity2, 20))
File "C:\Users\Little-Dany\AppData\Local\Programs\Python\Python36-32lib\site-packages\telethon\telegram_bare_client.py", line 448, in call
result = self._invoke(sender, call_receive, *requests)
File "C:\Users\Little-Dany\AppData\Local\Programs\Python\Python36-32lib\site-packages\telethon\telegram_bare_client.py", line 506, in _invoke
raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_errors_400.PeerIdInvalidError: (PeerIdInvalidError(...), 'An invalid Peer was used. Make sure to pass the right peer type.')
What is wrong?
Definitely not obvious error.
Changing from
from telethon.tl.functions.messages import ReadHistoryRequest
to
from telethon.tl.functions.messages import ReadHistoryRequest
fixed everything.
Thanks a lot! @Lonami , you're awesome
Definitely not obvious error.
Make sure to pass the right peer type.
Well, it was telling you to use the right type. That should hint something.
Changing from
from telethon.tl.functions.messages import ReadHistoryRequest
to
from telethon.tl.functions.messages import ReadHistoryRequest
fixed everything.
Actually both lines are identical. ¯\_(ツ)_/¯
They probably meant functions.channels in one, @BondarenkoArtur.
Most helpful comment
Actually both lines are identical.
¯\_(ツ)_/¯