Skip to content

Commit

Permalink
Intercom: Full resync action (#3910)
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph authored Feb 23, 2024
1 parent d64f69b commit ed0a657
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions connectors/src/connectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { launchGoogleDriveFullSyncWorkflow } from "@connectors/connectors/google
import {
cleanupIntercomConnector,
createIntercomConnector,
fullResyncIntercomSyncWorkflow,
resumeIntercomConnector,
retrieveIntercomConnectorPermissions,
retrieveIntercomNodesTitles,
Expand All @@ -49,7 +50,6 @@ import {
stopIntercomConnector,
updateIntercomConnector,
} from "@connectors/connectors/intercom";
import { launchIntercomSyncWorkflow } from "@connectors/connectors/intercom/temporal/client";
import type {
ConnectorBatchResourceTitleRetriever,
ConnectorCleaner,
Expand Down Expand Up @@ -188,7 +188,7 @@ export const SYNC_CONNECTOR_BY_TYPE: Record<ConnectorProvider, SyncConnector> =
notion: fullResyncNotionConnector,
github: fullResyncGithubConnector,
google_drive: launchGoogleDriveFullSyncWorkflow,
intercom: launchIntercomSyncWorkflow,
intercom: fullResyncIntercomSyncWorkflow,
webcrawler: launchCrawlWebsiteWorkflow,
};

Expand Down
37 changes: 37 additions & 0 deletions connectors/src/connectors/intercom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,43 @@ export async function resumeIntercomConnector(
return new Ok(undefined);
}

export async function fullResyncIntercomSyncWorkflow(
connectorId: ModelId
): Promise<Result<string, Error>> {
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,
Expand Down

0 comments on commit ed0a657

Please sign in to comment.