From ed0a657fdd3263997d9f37ee0ae7f911b466614b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daphn=C3=A9=20Popin?= Date: Fri, 23 Feb 2024 12:16:23 +0100 Subject: [PATCH] Intercom: Full resync action (#3910) --- connectors/src/connectors/index.ts | 4 +-- connectors/src/connectors/intercom/index.ts | 37 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/connectors/src/connectors/index.ts b/connectors/src/connectors/index.ts index a720d4fe3fa8..2a2fcb7a9bb7 100644 --- a/connectors/src/connectors/index.ts +++ b/connectors/src/connectors/index.ts @@ -41,6 +41,7 @@ import { launchGoogleDriveFullSyncWorkflow } from "@connectors/connectors/google import { cleanupIntercomConnector, createIntercomConnector, + fullResyncIntercomSyncWorkflow, resumeIntercomConnector, retrieveIntercomConnectorPermissions, retrieveIntercomNodesTitles, @@ -49,7 +50,6 @@ import { stopIntercomConnector, updateIntercomConnector, } from "@connectors/connectors/intercom"; -import { launchIntercomSyncWorkflow } from "@connectors/connectors/intercom/temporal/client"; import type { ConnectorBatchResourceTitleRetriever, ConnectorCleaner, @@ -188,7 +188,7 @@ export const SYNC_CONNECTOR_BY_TYPE: Record = notion: fullResyncNotionConnector, github: fullResyncGithubConnector, google_drive: launchGoogleDriveFullSyncWorkflow, - intercom: launchIntercomSyncWorkflow, + intercom: fullResyncIntercomSyncWorkflow, webcrawler: launchCrawlWebsiteWorkflow, }; diff --git a/connectors/src/connectors/intercom/index.ts b/connectors/src/connectors/intercom/index.ts index b7c4e80d896e..640411207fc7 100644 --- a/connectors/src/connectors/intercom/index.ts +++ b/connectors/src/connectors/intercom/index.ts @@ -312,6 +312,43 @@ export async function resumeIntercomConnector( return new Ok(undefined); } +export async function fullResyncIntercomSyncWorkflow( + connectorId: ModelId +): Promise> { + const connector = await ConnectorResource.fetchById(connectorId); + if (!connector) { + logger.error({ connectorId }, "Notion connector not found."); + return new Err(new Error("Connector not found")); + } + + const helpCentersIds = await IntercomHelpCenter.findAll({ + where: { + connectorId, + }, + attributes: ["helpCenterId"], + }); + const teamsIds = await IntercomTeam.findAll({ + where: { + connectorId, + }, + attributes: ["teamId"], + }); + + const toBeSignaledHelpCenterIds = helpCentersIds.map((hc) => hc.helpCenterId); + const toBeSignaledTeamIds = teamsIds.map((team) => team.teamId); + + const sendSignalToWorkflowResult = await launchIntercomSyncWorkflow( + connectorId, + null, + toBeSignaledHelpCenterIds, + toBeSignaledTeamIds + ); + if (sendSignalToWorkflowResult.isErr()) { + return new Err(sendSignalToWorkflowResult.error); + } + return new Ok(connector.id.toString()); +} + export async function retrieveIntercomConnectorPermissions({ connectorId, parentInternalId,