diff --git a/connectors/src/connectors/confluence/lib/cli.ts b/connectors/src/connectors/confluence/lib/cli.ts index 48b4ab1f8e64..fb93e9a85858 100644 --- a/connectors/src/connectors/confluence/lib/cli.ts +++ b/connectors/src/connectors/confluence/lib/cli.ts @@ -4,7 +4,14 @@ import type { ConfluenceUpsertPageResponseType, } from "@dust-tt/types"; +import { + fetchConfluenceConfigurationActivity, + getConfluenceClient, + upsertConfluencePageToDataSource, +} from "@connectors/connectors/confluence/temporal/activities"; +import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config"; import { default as topLogger } from "@connectors/logger/logger"; +import { ConnectorResource } from "@connectors/resources/connector_resource"; export const confluence = async ({ command, @@ -21,6 +28,51 @@ export const confluence = async ({ if (!args.pageId) { throw new Error("Missing --pageId argument"); } + const connectorId = args.connectorId; + const pageId = args.pageId; + + const connector = await ConnectorResource.fetchById(connectorId); + if (!connector) { + throw new Error("Connector not found."); + } + const dataSourceConfig = dataSourceConfigFromConnector(connector); + const confluenceConfig = + await fetchConfluenceConfigurationActivity(connectorId); + + const loggerArgs = { + connectorId, + dataSourceId: dataSourceConfig.dataSourceId, + pageId, + workspaceId: dataSourceConfig.workspaceId, + }; + const localLogger = logger.child(loggerArgs); + + const client = await getConfluenceClient( + { cloudId: confluenceConfig?.cloudId }, + connector + ); + + const page = await client.getPageById(pageId); + if (!page) { + localLogger.info("Confluence page not found."); + return false; + } + const space = await client.getSpaceById(page.spaceId); + if (!space) { + localLogger.info("Confluence space not found."); + return false; + } + + localLogger.info("Upserting Confluence page."); + await upsertConfluencePageToDataSource( + page, + space.name, + confluenceConfig, + "batch", + dataSourceConfig, + loggerArgs + ); + break; } diff --git a/types/src/connectors/admin/cli.ts b/types/src/connectors/admin/cli.ts index 2cac6ea2e6d2..136aaeb222aa 100644 --- a/types/src/connectors/admin/cli.ts +++ b/types/src/connectors/admin/cli.ts @@ -31,7 +31,7 @@ export const ConfluenceCommandSchema = t.type({ command: t.literal("upsert-page"), args: t.type({ connectorId: t.union([t.number, t.undefined]), - pageId: t.union([t.number, t.undefined]), + pageId: t.union([t.string, t.undefined]), }), }); export type ConfluenceCommandType = t.TypeOf;