From 6b3110264c56cedeb2f4c91e1e97cccac8644ef4 Mon Sep 17 00:00:00 2001 From: Stanislas Polu Date: Fri, 13 Dec 2024 14:04:59 +0100 Subject: [PATCH] connectors[slack]: update content-nodes to use new itnernalIds (#9324) * connectors[slack]: update content-nodes to use new itnernalIds * nit --- connectors/src/connectors/slack/index.ts | 36 ++++++++++++------- connectors/src/connectors/slack/lib/utils.ts | 10 ++++++ .../connectors/slack/temporal/activities.ts | 11 +++--- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/connectors/src/connectors/slack/index.ts b/connectors/src/connectors/slack/index.ts index bbb564af428d..9dcf78e46e00 100644 --- a/connectors/src/connectors/slack/index.ts +++ b/connectors/src/connectors/slack/index.ts @@ -23,6 +23,10 @@ import { getSlackAccessToken, getSlackClient, } from "@connectors/connectors/slack/lib/slack_client"; +import { + internalIdFromSlackChannelId, + slackChannelIdFromInternalId, +} from "@connectors/connectors/slack/lib/utils"; import { launchSlackSyncWorkflow } from "@connectors/connectors/slack/temporal/client.js"; import { ExternalOAuthTokenError, @@ -377,7 +381,7 @@ export class SlackConnectorManager extends BaseConnectorManager ({ provider: "slack", - internalId: ch.slackChannelId, + internalId: internalIdFromSlackChannelId(ch.slackChannelId), parentInternalId: null, type: "channel", title: `#${ch.slackChannelName}`, @@ -440,7 +444,9 @@ export class SlackConnectorManager extends BaseConnectorManager + slackChannelIdFromInternalId(k) + ), }, }) ).reduce( @@ -455,18 +461,19 @@ export class SlackConnectorManager extends BaseConnectorManager> { + const slackChannelIds = internalIds.map((id) => + slackChannelIdFromInternalId(id) + ); const slackConfig = await SlackConfigurationResource.fetchByConnectorId( this.connectorId ); @@ -580,13 +590,13 @@ export class SlackConnectorManager extends BaseConnectorManager ({ provider: "slack", - internalId: ch.slackChannelId, + internalId: internalIdFromSlackChannelId(ch.slackChannelId), parentInternalId: null, type: "channel", title: `#${ch.slackChannelName}`, @@ -607,6 +617,8 @@ export class SlackConnectorManager extends BaseConnectorManager> { + // We only ever return permissions at the slack channel level so the parents are always the + // internalId itself. return new Ok([internalId]); } diff --git a/connectors/src/connectors/slack/lib/utils.ts b/connectors/src/connectors/slack/lib/utils.ts index 623da92958ba..3134a2c1d020 100644 --- a/connectors/src/connectors/slack/lib/utils.ts +++ b/connectors/src/connectors/slack/lib/utils.ts @@ -1,3 +1,5 @@ +import _ from "lodash"; + export function getWeekStart(date: Date): Date { const dateCopy = new Date(date); @@ -48,3 +50,11 @@ export const timeAgoFrom = (millisSinceEpoch: number) => { } return seconds + "s"; }; + +export function internalIdFromSlackChannelId(channel: string) { + return `slack-channel-${_.last(channel.split("slack-channel-"))!}`; +} + +export function slackChannelIdFromInternalId(nodeId: string) { + return _.last(nodeId.split("slack-channel-"))!; +} diff --git a/connectors/src/connectors/slack/temporal/activities.ts b/connectors/src/connectors/slack/temporal/activities.ts index d5f17e42c604..5ed59ca82401 100644 --- a/connectors/src/connectors/slack/temporal/activities.ts +++ b/connectors/src/connectors/slack/temporal/activities.ts @@ -24,6 +24,11 @@ import { import { isSlackWebAPIPlatformError } from "@connectors/connectors/slack/lib/errors"; import { getSlackClient } from "@connectors/connectors/slack/lib/slack_client"; import { getRepliesFromThread } from "@connectors/connectors/slack/lib/thread"; +import { + getWeekEnd, + getWeekStart, + internalIdFromSlackChannelId, +} from "@connectors/connectors/slack/lib/utils"; import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config"; import { cacheGet, cacheSet } from "@connectors/lib/cache"; import { @@ -43,8 +48,6 @@ import { ConnectorResource } from "@connectors/resources/connector_resource"; import { SlackConfigurationResource } from "@connectors/resources/slack_configuration_resource"; import type { DataSourceConfig } from "@connectors/types/data_source_config"; -import { getWeekEnd, getWeekStart } from "../lib/utils"; - const logger = mainLogger.child({ provider: "slack" }); // This controls the maximum number of concurrent calls to syncThread and syncNonThreaded. @@ -602,7 +605,7 @@ export async function syncNonThreaded( documentUrl: sourceUrl, timestampMs: updatedAt, tags, - parents: [documentId, channelId, `slack-channel-${channelId}`], + parents: [documentId, channelId, internalIdFromSlackChannelId(channelId)], upsertContext: { sync_type: isBatchSync ? "batch" : "incremental", }, @@ -812,7 +815,7 @@ export async function syncThread( documentUrl: sourceUrl, timestampMs: updatedAt, tags, - parents: [documentId, channelId, `slack-channel-${channelId}`], + parents: [documentId, channelId, internalIdFromSlackChannelId(channelId)], upsertContext: { sync_type: isBatchSync ? "batch" : "incremental", },