MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / getFullChannelHistory

Function getFullChannelHistory

server/src/slack/client.ts:1274–1314  ·  view source on GitHub ↗
(
  channelId: string,
  options: {
    oldest?: string;  // Unix timestamp - only messages after this time
    latest?: string;  // Unix timestamp - only messages before this time
    maxMessages?: number;  // Stop after this many messages (default: no limit)
    onProgress?: (count: number) => void;  // Callback for progress updates
  } = {}
)

Source from the content-addressed store, hash-verified

1272 * @returns Array of all messages in the time range
1273 */
1274export async function getFullChannelHistory(
1275 channelId: string,
1276 options: {
1277 oldest?: string; // Unix timestamp - only messages after this time
1278 latest?: string; // Unix timestamp - only messages before this time
1279 maxMessages?: number; // Stop after this many messages (default: no limit)
1280 onProgress?: (count: number) => void; // Callback for progress updates
1281 } = {}
1282): Promise<SlackHistoryMessage[]> {
1283 const allMessages: SlackHistoryMessage[] = [];
1284 let cursor: string | undefined;
1285 const maxMessages = options.maxMessages ?? Infinity;
1286
1287 do {
1288 const result = await getChannelHistory(channelId, {
1289 oldest: options.oldest,
1290 latest: options.latest,
1291 limit: 200, // Fetch in larger batches for efficiency
1292 cursor,
1293 });
1294
1295 allMessages.push(...result.messages);
1296
1297 if (options.onProgress) {
1298 options.onProgress(allMessages.length);
1299 }
1300
1301 if (allMessages.length >= maxMessages) {
1302 break;
1303 }
1304
1305 cursor = result.nextCursor;
1306
1307 if (cursor) {
1308 await sleep(RATE_LIMIT_DELAY_MS);
1309 }
1310 } while (cursor);
1311
1312 logger.debug({ channelId, messageCount: allMessages.length }, 'Fetched full channel history');
1313 return allMessages.slice(0, maxMessages);
1314}

Callers 1

runSlackHistoryBackfillFunction · 0.85

Calls 2

getChannelHistoryFunction · 0.85
sleepFunction · 0.70

Tested by

no test coverage detected