Skip to content

Commit

Permalink
feat: add page upsertion to the CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Dec 13, 2024
1 parent 157fe74 commit 1c4ff28
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions connectors/src/connectors/confluence/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion types/src/connectors/admin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof ConfluenceCommandSchema>;
Expand Down

0 comments on commit 1c4ff28

Please sign in to comment.