please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Web/
Message/
SDK
  • Install Chat SDK
  • Initialize Chat SDK
  • Login and Logout
  • Client APIs
  • Changelog
  • Message
    • Overview
    • Send a Message
    • Receive a Message
    • Historical Message
    • Forward Messages
    • Modify a Message
    • Delete Messages
    • Clear History Message
    • Recall a Message
    • Send an Online Message
    • Message Read Receipt
    • Query Messages
    • Targeted Group Message
    • Do not Notify
    • Key-Value Extensions
    • Translation
  • Conversation
    • Overview
    • Conversation List
    • Get Conversations
    • Unread Count
    • Pin Conversations
    • Delete Conversations
    • Mark
    • Conversation Group
  • Group
    • Overview
    • Group Management
    • Group Profile
    • Group Member Management
    • Group Member Profile
    • Custom Group Attribute
    • Group Counter
  • Community Topic
    • Community Management
  • User Profile and Relationship Chain
    • User Profile
    • User Status
    • Friend Management
    • Friend Group
    • Block List
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Historical Message

Feature Description

The SDK supports message pull by page, sequence, or time range. Historical messages stored in the cloud are subject to the following time limits:
Developer edition: The free storage period is 7 days and cannot be extended.
Standard edition: The free storage period is 7 days and cannot be extended.
Premium edition: The free storage period is 30 days and cannot be extended.
Note
Extending the storage period of historical messages is a Value-Added Service. You can log in to the Chat Console to modify the relevant configuration. For billing details, see Pricing.
Rich media messages (such as images, files, and audios) have the same storage periods as historical messages.

Pulling a Message List

getMessageList

This API is used to pull the list of messages in a specified conversation by page. It needs to be called when the message list is rendered for the first time after the user enters the conversation, or when the user pulls down the list to view more messages.
Note
This API can be used to pull historical messages.
API
chat.getMessageList(options);
Parameter
The options parameter is of the Object type. It contains the following attribute values:
Name
Type
Description
conversationID
String
Conversation ID, which consists of:
C2C${userID} (for one-to-one chats)
GROUP${groupID} (for group chats)
GROUP${topicID} (topic)
@TIM#SYSTEM (system notification conversation)
nextReqMessageID
String | undefined
Message ID used for the subsequent paged pull. Leave this field empty for the first pull and enter its the value returned by the getMessageList API for the subsequent pull.
Returned value
Promise
Sample
// Pull the message list for the first time when a conversation is opened
let promise = chat.getMessageList({conversationID: 'C2Ctest'});
promise.then(function(imResponse) {
const messageList = imResponse.data.messageList; // Message list
// This parameter must be passed in for the next pull by page.
const nextReqMessageID = imResponse.data.nextReqMessageID;
// It indicates whether all messages have been pulled.
const isCompleted = imResponse.data.isCompleted;
});
// Pull down the message list to view more messages
let promise = chat.getMessageList({conversationID: 'C2Ctest', nextReqMessageID});
promise.then(function(imResponse) {
const messageList = imResponse.data.messageList; // Message list
// This parameter must be passed in for the next pull by page.
const nextReqMessageID = imResponse.data.nextReqMessageID;
// It indicates whether all messages have been pulled.
const isCompleted = imResponse.data.isCompleted;
});

getMessageListHopping

This API is used to pull a message list by specified sequence or time range.
API
chat.getMessageListHopping(options);
Parameter
The options parameter is of the Object type. It contains the following attribute values:
Name
Type
Description
conversationID
String
Conversation ID, which consists of:
C2C${userID} (for one-to-one chats)
GROUP${groupID} (for group chats)
GROUP${topicID} (topic).
sequence
Number | undefined
sequence of the message starting from which to pull roaming group messages
time
Number | undefined
Server time of the message, starting from which to pull roaming one-to-one messages
direction
Number
Message pull direction, which defaults to 0.
0: pull in reverse chronological order to get older messages;
1: pull in chronological order to get recent messages
count
Number | undefined
Number of messages to be pulled. It defaults to 15, which is also the maximum value, indicating that up to 15 messages can be pulled and returned at a time.
Returned value
Promise
Sample
// Pull roaming group messages by sequence.
// `direction`: 0: pull in reverse chronological order to get older messages
// 1: pull in chronological order to get recent messages
let promise = chat.getMessageListHopping({
conversationID: 'GROUPtest',
sequence: 100,
count: 15,
direction: 0
});
promise.then(function(imResponse) {
const messageList = imResponse.data.messageList; // Message list
});

// Pull roaming one-to-one messages by time range.
// `direction`: 0: pull in reverse chronological order to get older messages
// 1: pull in chronological order to get recent messages
let promise = chat.getMessageListHopping({
conversationID: 'C2Ctest',
time: xxx,
count: 15,
direction: 0
});
promise.then(function(imResponse) {
const messageList = imResponse.data.messageList; // Message list
});