Skip to content

getChatHistory

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

Returns messages in a chat.
The messages are returned in a reverse chronological order (i.e., in order of decreasing message_id).
For optimal performance the number of returned messages is chosen by the library.
This is an offline request if only_local is true.

getChatHistory(chat_id, from_message_id, offset, limit, only_local, callback, data)
Field Type Description
chat_id int53 Chat identifier
from_message_id int53 Identifier of the message starting from which history must be fetched; use 0 to get results from the beginning (i.e., from oldest to newest).
offset int32 Specify 0 to get results from exactly the from_message_id or a negative offset to get the specified message and some newer messages.
limit int32 The maximum number of messages to be returned; must be positive and can't be greater than 100. If the offset is negative, the limit must be greater than -offset. Fewer messages may be returned than specified by the limit, even if the end of the message history has not been reached.
only_local Bool If true, returns only messages that are available locally without sending network requests.

Example

  • Get messages in a chat 1234567890.

    getChatHistory(1234567890)

    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 = "1234567890",
          contains_unread_mention = false,
          content = {
            ["@type"] = "messageText",
            text = {
              ["@type"] = "formattedText",
              entities = {},
              text = "tas sud"
            }
          },
          date = 1530427735,
          edit_date = 0,
          id = "16333668352",
          is_channel_post = false,
          is_outgoing = true,
          media_album_id = "0",
          reply_to_message_id = 0,
          sender_user_id = 999999999,
          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 = false,
          can_be_edited = true,
          can_be_forwarded = true,
          chat_id = "1234567890",
          contains_unread_mention = false,
          content = {
            ["@type"] = "messageText",
            text = {
              ["@type"] = "formattedText",
              entities = {
                {
                  ["@type"] = "textEntity",
                  length = 4,
                  offset = 0,
                  type = {
                    ["@type"] = "textEntityTypeBotCommand"
                  }
                }
              },
              text = "/tas"
            }
          },
          date = 1530427729,
          edit_date = 0,
          id = "16332619776",
          is_channel_post = false,
          is_outgoing = true,
          media_album_id = "0",
          reply_to_message_id = 0,
          sender_user_id = 99999999,
          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 = false,
          can_be_edited = true,
          can_be_forwarded = true,
          chat_id = "1234567890",
          contains_unread_mention = false,
          content = {
            ["@type"] = "messageText",
            text = {
              ["@type"] = "formattedText",
              entities = {
                {
                  ["@type"] = "textEntity",
                  length = 5,
                  offset = 0,
                  type = {
                    ["@type"] = "textEntityTypeBotCommand"
                  }
                }
              },
              text = "/pong"
            }
          },
          date = 1530427187,
          edit_date = 0,
          id = "16331571200",
          is_channel_post = false,
          is_outgoing = true,
          media_album_id = "0",
          reply_to_message_id = 0,
          sender_user_id = 99999999,
          ttl = 0,
          ttl_expires_in = 0,
          via_bot_user_id = 0,
          views = 0
        }
      },
      total_count = 3
    }

Frequently Asked Questions
The Functions

Clone this wiki locally