Skip to content

Commit

Permalink
Use last message timestamp when upserting Slack Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lasryaric committed Sep 6, 2023
1 parent 59aae41 commit c3defda
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions connectors/src/connectors/slack/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down

0 comments on commit c3defda

Please sign in to comment.