From c3defdaa926a940bbbe3ed289fc0b07bfb014e49 Mon Sep 17 00:00:00 2001 From: Aric Lasry Date: Wed, 6 Sep 2023 17:42:28 +0200 Subject: [PATCH] Use last message timestamp when upserting Slack Messages --- .../src/connectors/slack/temporal/activities.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/connectors/src/connectors/slack/temporal/activities.ts b/connectors/src/connectors/slack/temporal/activities.ts index 33a0b93db87e..c0406a56cdec 100644 --- a/connectors/src/connectors/slack/temporal/activities.ts +++ b/connectors/src/connectors/slack/temporal/activities.ts @@ -385,9 +385,7 @@ export async function syncNonThreaded( const documentId = `slack-${channelId}-messages-${startDateStr}-${endDateStr}`; const firstMessage = messages[0]; let sourceUrl: string | undefined = undefined; - const createdAt = firstMessage?.ts - ? parseInt(firstMessage.ts, 10) * 1000 - : undefined; + if (firstMessage && firstMessage.ts) { const linkRes = await client.chat.getPermalink({ channel: channelId, @@ -397,6 +395,10 @@ export async function syncNonThreaded( sourceUrl = linkRes.permalink; } } + const lastMessage = messages[messages.length - 1]; + const createdAt = lastMessage?.ts + ? parseInt(lastMessage.ts, 10) * 1000 + : undefined; const tags = getTagsForPage(documentId, channelId, channelName); await SlackMessages.upsert({ @@ -531,9 +533,7 @@ export async function syncThread( const firstMessage = allMessages[0]; let sourceUrl: string | undefined = undefined; - const createdAt = firstMessage?.ts - ? parseInt(firstMessage.ts, 10) * 1000 - : undefined; + if (firstMessage && firstMessage.ts) { const linkRes = await client.chat.getPermalink({ channel: channelId, @@ -543,6 +543,10 @@ export async function syncThread( sourceUrl = linkRes.permalink; } } + const lastMessage = allMessages[allMessages.length - 1]; + const createdAt = lastMessage?.ts + ? parseInt(lastMessage.ts, 10) * 1000 + : undefined; const tags = getTagsForPage(documentId, channelId, channelName, threadTs);