Skip to content

searchMessages

Sahri Riza Umami edited this page Jul 1, 2018 · 4 revisions

Searches for messages in all chats except secret chats.
Returns the results in reverse chronological order (i.e., in order of decreasing (date, chat_id, message_id)).
For optimal performance the number of returned messages is chosen by the library.

searchMessages(query, offset_date, offset_chat_id, offset_message_id, limit, callback, data)
Field Type Description
query string Query to search for.
offset_date int32 The date of the message starting from which the results should be fetched. Use 0 or any date in the future to get results from the beginning.
offset_chat_id int53 The chat identifier of the last found message, or 0 for the first request.
offset_message_id int53 The message identifier of the last found message, or 0 for the first request.
limit int32 The maximum number of messages to be returned, up to 100. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached.

Example

  • Searches for 2 messages contain "tandain" in all chats except secret chats.

    searchMessages('tandain')

    Response:

    {
      ["@type"] = "messages",
      messages = {
        {
          ["@type"] = "message",
          author_signature = "",
          can_be_deleted_for_all_users = true,
          can_be_deleted_only_for_self = false,
          can_be_edited = true,
          can_be_forwarded = true,
          chat_id = "-1001234567890",
          contains_unread_mention = false,
          content = {
            ["@type"] = "messageText",
            text = {
              ["@type"] = "formattedText",
              entities = {},
              text = "tes tandain"
            }
          },
          date = 1530429004,
          edit_date = 0,
          id = "16341008384",
          is_channel_post = false,
          is_outgoing = true,
          media_album_id = "0",
          reply_to_message_id = 0,
          sender_user_id = 9999999999,
          ttl = 0,
          ttl_expires_in = 0,
          via_bot_user_id = 0,
          views = 0
        },
        {
          ["@type"] = "message",
          author_signature = "",
          can_be_deleted_for_all_users = true,
          can_be_deleted_only_for_self = true,
          can_be_edited = false,
          can_be_forwarded = true,
          chat_id = -15387310,
          contains_unread_mention = false,
          content = {
            ["@type"] = "messageText",
            text = {
              ["@type"] = "formattedText",
              entities = {},
              text = "wah, tandain dulu mau ane tulis deh"
            }
          },
          date = 1530423944,
          edit_date = 0,
          id = "1875479887872",
          is_channel_post = false,
          is_outgoing = false,
          media_album_id = "0",
          reply_to_message_id = "1875478839296",
          sender_user_id = 161165904,
          ttl = 0,
          ttl_expires_in = 0,
          via_bot_user_id = 0,
          views = 0
        }
      },
      total_count = 28
    }

Frequently Asked Questions
The Functions

Clone this wiki locally