PG→Mongo Ingest CLI - v1.0.0
    Preparing search index...

    Function readBatchByChat

    • Reads a batch of WhatsApp Evolution messages for a specific chat using cursor-based pagination.

      This function implements efficient pagination by using a cursor that tracks the last processed message position. It supports filtering by time bounds and ensures consistent ordering for reliable resumption.

      The cursor-based approach allows for:

      • Resuming interrupted imports from the exact position
      • Processing large datasets without loading everything into memory
      • Consistent results even if new messages are added during processing

      Parameters

      • chat_id: null | string

        The chat ID to read messages for (null for all chats)

      • cursor: ChatCursor

        Cursor object tracking the last processed message position

      • batchSize: number

        Number of messages to read in this batch

      • Optionalbounds: { sinceSeconds?: null | number; untilSeconds?: null | number }

        Optional time bounds for filtering messages

        • OptionalsinceSeconds?: null | number

          Start timestamp in seconds (inclusive)

        • OptionaluntilSeconds?: null | number

          End timestamp in seconds (inclusive)

      Returns Promise<EvolutionMessageRow[]>

      Promise resolving to an array of EvolutionMessageRow objects

      const cursor: ChatCursor = { last_ts_seconds: null, last_message_id: null };
      const bounds = { sinceSeconds: 1701111559, untilSeconds: 1701197959 };

      const messages = await readBatchByChat(
      "19175769740@s.whatsapp.net",
      cursor,
      100,
      bounds
      );

      // Update cursor for next batch
      if (messages.length > 0) {
      const last = messages[messages.length - 1];
      cursor.last_ts_seconds = last.messageTimestamp;
      cursor.last_message_id = last.key?.id;
      }