Skip to content

Commit e17b63c

Browse files
committed
Reduce the number of conversations fetched per search API call pages
1 parent bf979d8 commit e17b63c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

integrations/intercom-conversations/src/conversations.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ export async function ingestLastClosedIntercomConversations(context: IntercomRun
2020
const intercomClient = await getIntercomClient(context);
2121

2222
let pageIndex = 0;
23-
const perPage = 100;
24-
const maxPages = 7; // Keep under ~1000 subrequest limit. Calc: 7 pages * 100 items ≈ 700 detail calls + 7 search page calls ≈ ~707 Intercom calls (+7 GitBook ingests ≈ ~714 total).
23+
const perPage = 50;
24+
const maxPages = 14; // 14 pages * 50 items ≈ 14 search page calls.
2525
let totalConvsToIngest = 0;
2626

27+
logger.info(
28+
`Conversation ingestion started. A maximum of ${maxPages * perPage} conversations will be processed.`,
29+
);
30+
2731
let page = await intercomClient.conversations.search(
2832
{
2933
query: {
@@ -44,9 +48,7 @@ export async function ingestLastClosedIntercomConversations(context: IntercomRun
4448
},
4549
);
4650

47-
logger.info(
48-
`Conversation ingestion started. A maximum of ${maxPages * perPage} conversations will be processed.`,
49-
);
51+
logger.info(`First page of conversation fetched.`);
5052

5153
const tasks: Array<IntercomIntegrationTask> = [];
5254
while (pageIndex < maxPages) {
@@ -67,9 +69,12 @@ export async function ingestLastClosedIntercomConversations(context: IntercomRun
6769
break;
6870
}
6971

72+
logger.info(`Fetching next page ${pageIndex + 1}.`);
7073
page = await page.getNextPage();
7174
}
7275

76+
logger.info(`Queuing ${tasks.length} tasks to ingest intercom closed conversations...`);
77+
7378
await pMap(tasks, async (task) => queueIntercomIntegrationTask(context, task), {
7479
concurrency: 3,
7580
});

0 commit comments

Comments
 (0)