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, ... })

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, ... })

Last updated

Logo

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