Skip to main content

messages.search

Search for messages.

func (c *Client) MessagesSearch(ctx context.Context, request *MessagesSearchRequest) (MessagesMessagesClass, error)

Calling this method

client.Run(ctx, func(ctx context.Context) error {
api := client.API()

res, err := api.MessagesSearch(ctx, &tg.MessagesSearchRequest{
// see Parameters
})
if err != nil {
return err
}
_ = res // MessagesMessagesClass
return nil
})

Parameters

NameTypeRequiredDescription
PeerInputPeerClassyesUser or chat, histories with which are searched, or (inputPeerEmpty) constructor to search in all private chats and normal groups (not channels) ». Use messages searchGlobal to search globally in all chats, groups, supergroups and channels.
QstringyesText search request
FromIDInputPeerClassOnly return messages sent by the specified user ID
SavedPeerIDInputPeerClassSearch within the saved message dialog » with this ID.
SavedReaction[]ReactionClassYou may search for saved messages tagged » with one or more reactions using this flag.
TopMsgIDintThread ID
FilterMessagesFilterClassyesFilter to return only specified message types
MinDateintyesIf a positive value was transferred, only messages with a sending date bigger than the transferred one will be returned
MaxDateintyesIf a positive value was transferred, only messages with a sending date smaller than the transferred one will be returned
OffsetIDintyesOnly return messages starting from the specified message ID
AddOffsetintyesAdditional offset
LimitintyesNumber of results to return, can be 0 to only return the message counter.
MaxIDintyesMaximum message ID to return
MinIDintyesMinimum message ID to return
Hashint64yesHash

Returns

MessagesMessagesClass

Possible errors

CodeTypeDescription
400CHANNEL_INVALIDThe provided channel is invalid.
400CHANNEL_PRIVATEYou haven't joined this channel/supergroup.
403CHAT_ADMIN_REQUIREDYou must be an admin in this chat to do this.
400CHAT_ID_INVALIDThe provided chat id is invalid.
400FROM_PEER_INVALIDThe specified from_id is invalid.
400INPUT_FILTER_INVALIDThe specified filter is invalid.
400INPUT_USER_DEACTIVATEDThe specified user was deleted.
400MSG_ID_INVALIDInvalid message ID provided.
400PEER_ID_INVALIDThe provided peer id is invalid.
400PEER_ID_NOT_SUPPORTEDThe provided peer ID is not supported.
400SEARCH_QUERY_EMPTYThe search query is empty.
400TAKEOUT_INVALIDThe specified takeout ID is invalid.
400USER_ID_INVALIDThe provided user ID is invalid.

References