GetHistoryRequest
Only users can use this request. See code examples.
---functions--- messages.getHistory#4423e6c5 peer:InputPeer offset_id:int offset_date:date add_offset:int limit:int max_id:int min_id:int hash:long = messages.Messages
Returns
messages.Messages |
This type can be an instance of either:
ChannelMessages | Messages |
MessagesNotModified | MessagesSlice |
Parameters
peer | InputPeer | Anything entity-like will work if the library can find its Input version (e.g., usernames, Peer , User or Channel objects, etc.). |
offset_id | int | |
offset_date | date | |
add_offset | int | |
limit | int | |
max_id | int | |
min_id | int | |
hash | long |
Known RPC errors
This request can cause 7 known errors:
AuthKeyDuplicatedError | The authorization key (session file) was used under two different IP addresses simultaneously, and can no longer be used. Use the same session exclusively, or use different sessions. |
AuthKeyPermEmptyError | The method is unavailable for temporary authorization key, not bound to permanent. |
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. |
ChannelPrivateError | The channel specified is private and you lack permission to access it. Another reason may be that you were banned from it. |
ChatIdInvalidError | Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead. |
PeerIdInvalidError | An invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations). |
TimeoutError | A timeout occurred while fetching data from the worker. |
You can import these from telethon.errors
.
Example
Please refer to the documentation of client.iter_messages()
to learn about the parameters and see several code examples on how to use it.
The method above is the recommended way to do it. If you need more control over the parameters or want to learn how it is implemented, open the details by clicking on the "Details" text.
from telethon.sync import TelegramClient from telethon import functions, types with TelegramClient(name, api_id, api_hash) as client: result = client(functions.messages.GetHistoryRequest( peer='username', offset_id=42, offset_date=datetime.datetime(2018, 6, 25), add_offset=0, limit=100, max_id=0, min_id=0, hash=-12398745604826 )) print(result.stringify())