LogoLogo
ALO.ai
Developer Documentation
Developer Documentation
  • Developer Documentation
  • Developer Account
    • API Key
  • SDKs
    • Authentication
    • Chat
      • Configuration
      • Send Messages
        • Upload Files
      • Message History
      • Message Actions
      • Message Counts
      • Translation
      • Typing Indicators
      • API Reference
        • Event
        • Message
    • Presence
      • Configuration
      • Basic Usage
      • Methods
    • Audio
      • Prerequisites
      • Instantiating Audio Service
      • Connect to a Channel
      • Disconnecting Audio Service
      • Push To Talk (PTT)
      • Full Duplex
      • Mute and Unmute Audio
      • Input/Output Device Selection
        • Microphone Selection
        • Speaker Selection
      • Channel Participants
      • Text To Speech Audio (TTS)
      • Automatic Reconnects
      • Handling Events
      • Classes
        • AloAudio
        • AudioUser
        • AudioChannel
        • Participant
    • Video
      • Prerequisites
      • Instantiating Video Service
      • Connect to a Channel
      • Disconnecting Video Service
      • Input Device Selection
        • Microphone Selection
        • Camera Selection
      • Publishing Streams
      • Modifying Published Streams
      • Channel Participants
      • Rendering Streams
        • Local Stream
        • Remote Streams
      • Muting/Unmuting Remote Streams
      • Recording Video (coming soon)
      • Automatic Reconnects
      • Handling Events
      • Classes
        • AloVideo
        • Participant
        • VideoChannel
        • VideoUser
  • ALO APPS
    • Overview
    • Creating Apps
    • Webhooks
      • Verifying Requests from ALO
    • Custom Action Forms
    • Using the ALO Platform API
  • ALO Platform API
    • Overview
    • Authentication
    • API
      • Actions and Periods
      • Channels
      • Channel Messages
      • Channel Users
      • Direct Message Channels
      • Direct Message Channel Chat Messages
      • Direct Message Channel Users
      • Groups
      • Periods
      • Types
      • Users
      • Video Management System
  • Misc
    • Supported Language Codes
Powered by GitBook
LogoLogo

ALO.ai

  • ALO.ai

© Copyright 2025 ALO.ai, Inc. • All Rights Reserved

On this page
  • Fetch messages in reverse chronological order
  • Fetch messages centered around a specific message
  1. SDKs
  2. Chat

Message History

Fetch messages using ALO's fetchHistory and fetchHistoryAround methods.

Fetch messages in reverse chronological order

You can use the fetchHistory method to fetch messages in reverse chronological order (from newest to oldest). fetchHistory also makes it easy to paginate through history in the direction of your choice.

chat.fetchHistory({
    channelId: "alpha",
    limit: 20
}).then(({ status, response }) => {
    // status = { error: (true|false), errorData: { statusCode<Integer>, message<String> } }
    if (status.error) {
        console.log(`Fetch History Failed:
            Reason: ${status.errorData.message}
            (Status Code: ${status.errorData.statusCode})
        `);
        return;
    }
    // response = { messages: [Message], newerPageToken: string, olderPageToken: string }

    // Now let's fetch the next 20 (older) messages:
    chat.fetchHistory({
        channelId: "alpha",
        limit: 20,
        olderPageToken: response.olderPageToken
    });
});

fetchHistory({ channelId: string, ... })

Name

Type

Required

Description

channelId

string

yes

The channel to fetch messages from.

limit

integer

no

The maximum number of messages to fetch (defaults to 100).

olderPageToken

string

no

The olderPageToken will be populated in the response offetchHistory if there exist messages sent before the current batch of retrieved messages (older messages).

newerPageToken

string

no

The newerPageToken will be populated in the response of fetchHistory if there exist messages sent after the current batch of retrieved messages (newer messages).

Fetch messages centered around a specific message

The fetchHistoryAround method gives you the ability to jump back into history to a specific message and retrieve the messages that were sent immediately before and after it.

chat.fetchHistoryAround({
   channelId: "alpha",
   messageId: "31570e17-0459-4fcb-bb57-a793f35c6689",
   limit: 10 
}).then((res) => {
   const { status, response } = res;
   // status = { error: (true|false), errorData: { statusCode<Integer>, message<String> } }
   if (status.error) {
      console.log(`Fetch History Failed:
         Reason: ${status.errorData.message}
         (Status Code: ${status.errorData.statusCode})
      `);
      return;
   }   
   const { messages, newerPageToken, olderPageToken } = response; 
});

fetchHistoryAround({ channelId: string, messageId: string, ... })

Name

Type

Required

Description

channelId

string

yes

The id of the channel for which you want to fetch history.

messageId

string

yes

The message for which you want to fetch history around.

limit

integer

no

The number of messages in both directions you want to fetch. For example, if you set limit to 5, you will receive a maximum of 11 messages: 5 messages before, the messageId message, and 5 message after. Defaults to 100.

PreviousUpload FilesNextMessage Actions

Last updated 8 months ago