igdm-cli icon indicating copy to clipboard operation
igdm-cli copied to clipboard

feature request: view older messages

Open realies opened this issue 3 years ago • 2 comments

realies avatar Feb 24 '23 21:02 realies

Providing additional information here:

It's been a long time I didn't use the API, but I can't remember if it's paginated or not. As a reminder, the API used is not official so I'm not sure if it's documented or even usable.

noook avatar Feb 28 '23 09:02 noook

It's possible to specify an offset which is referred to as cursor. For example:

(async () => {
  const recentInbox = await ig.direct.getInbox();
  let nextCursor = recentInbox.oldest_cursor;

  while (nextCursor) {
    const olderInbox = await ig.direct.getInbox({ cursor: nextCursor });

    // Iterate through conversations and access messages
    for (const thread of olderInbox) {
      for (const item of thread.items) {
        // Process the message item
        console.log(item.text);
      }
    }

    nextCursor = olderInbox.oldest_cursor;
  }
})();

realies avatar May 17 '23 01:05 realies