SearchRequest
Only users can use this request. See code examples.
---functions--- messages.search#29ee847a flags:# peer:InputPeer q:string from_id:flags.0?InputPeer saved_peer_id:flags.2?InputPeer saved_reaction:flags.3?Vector<Reaction> top_msg_id:flags.1?int filter:MessagesFilter min_date:date max_date:date offset_id:int 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.). |
q | string | |
filter | MessagesFilter | |
min_date | date | |
max_date | date | |
offset_id | int | |
add_offset | int | |
limit | int | |
max_id | int | |
min_id | int | |
hash | long | |
from_id | InputPeer | This argument defaults to None and can be omitted. Anything entity-like will work if the library can find its Input version (e.g., usernames, Peer , User or Channel objects, etc.). |
saved_peer_id | InputPeer | This argument defaults to None and can be omitted. Anything entity-like will work if the library can find its Input version (e.g., usernames, Peer , User or Channel objects, etc.). |
saved_reaction | Reaction | This argument defaults to None and can be omitted. Otherwise, a list must be supplied. |
top_msg_id | int | This argument defaults to None and can be omitted. |
Known RPC errors
This request can cause 9 known errors:
ChatAdminRequiredError | Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group. |
FromPeerInvalidError | The given from_user peer cannot be used for the parameter. |
InputConstructorInvalidError | The provided constructor is invalid. |
InputFilterInvalidError | The search query filter is invalid. |
InputUserDeactivatedError | The specified user was deleted. |
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). |
PeerIdNotSupportedError | The provided peer ID is not supported. |
SearchQueryEmptyError | The search query is empty. |
UserIdInvalidError | Invalid object ID for a user. Make sure to pass the right types, for instance making sure that the request is designed for users or otherwise look for a different one more suited. |
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.SearchRequest( peer='username', q='some string here', filter=types.InputMessagesFilterPhotos(), min_date=datetime.datetime(2018, 6, 25), max_date=datetime.datetime(2018, 6, 25), offset_id=42, add_offset=0, limit=100, max_id=0, min_id=0, hash=-12398745604826, from_id='username', saved_peer_id='username', saved_reaction=[types.ReactionEmoji( emoticon='some string here' )], top_msg_id=42 )) print(result.stringify())