From b4d36f8272600557397d8b4d720c99af36151aa9 Mon Sep 17 00:00:00 2001 From: Aubin Date: Thu, 12 Dec 2024 16:02:35 +0100 Subject: [PATCH] add CLI command to resync tickets only (there was no path previously to not forceResync) --- connectors/src/connectors/zendesk/lib/cli.ts | 22 ++++++++++++++++++- .../src/connectors/zendesk/temporal/client.ts | 21 ++++++++++++++++++ types/src/connectors/admin/cli.ts | 14 +++++++++++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/connectors/src/connectors/zendesk/lib/cli.ts b/connectors/src/connectors/zendesk/lib/cli.ts index 598be646ef2d..984410d32ca9 100644 --- a/connectors/src/connectors/zendesk/lib/cli.ts +++ b/connectors/src/connectors/zendesk/lib/cli.ts @@ -3,6 +3,7 @@ import type { ZendeskCommandType, ZendeskCountTicketsResponseType, } from "@dust-tt/types"; +import type { ZendeskResyncTicketsResponseType } from "@dust-tt/types/src"; import { getZendeskSubdomainAndAccessToken } from "@connectors/connectors/zendesk/lib/zendesk_access_token"; import { @@ -10,6 +11,7 @@ import { fetchZendeskTicketCount, getZendeskBrandSubdomain, } from "@connectors/connectors/zendesk/lib/zendesk_api"; +import { launchZendeskTicketReSyncWorkflow } from "@connectors/connectors/zendesk/temporal/client"; import { default as topLogger } from "@connectors/logger/logger"; import { ConnectorResource } from "@connectors/resources/connector_resource"; import { ZendeskConfigurationResource } from "@connectors/resources/zendesk_resources"; @@ -18,7 +20,9 @@ export const zendesk = async ({ command, args, }: ZendeskCommandType): Promise< - ZendeskCheckIsAdminResponseType | ZendeskCountTicketsResponseType + | ZendeskCheckIsAdminResponseType + | ZendeskCountTicketsResponseType + | ZendeskResyncTicketsResponseType > => { const logger = topLogger.child({ majorCommand: "zendesk", command, args }); @@ -81,5 +85,21 @@ export const zendesk = async ({ ); return { ticketCount }; } + case "resync-tickets": { + if (!connector) { + throw new Error(`Connector ${connectorId} not found`); + } + const result = await launchZendeskTicketReSyncWorkflow(connector, { + forceResync: args.forceResync || false, + }); + if (result.isErr()) { + logger.error( + { error: result.error }, + "Error launching the sync workflow." + ); + throw result.error; + } + return { success: true }; + } } }; diff --git a/connectors/src/connectors/zendesk/temporal/client.ts b/connectors/src/connectors/zendesk/temporal/client.ts index 6ca5277b3398..0f5abc38c0a1 100644 --- a/connectors/src/connectors/zendesk/temporal/client.ts +++ b/connectors/src/connectors/zendesk/temporal/client.ts @@ -199,3 +199,24 @@ export async function launchZendeskGarbageCollectionWorkflow( return new Ok(undefined); } + +/** + * Launches a Zendesk workflow that will resync the tickets. + * + * It recreates the signals necessary to resync every brand whose tickets are selected by the user. + */ +export async function launchZendeskTicketReSyncWorkflow( + connector: ConnectorResource, + { forceResync = false }: { forceResync?: boolean } = {} +): Promise> { + const brandIds = await ZendeskBrandResource.fetchTicketsAllowedBrandIds( + connector.id + ); + + const result = await launchZendeskSyncWorkflow(connector, { + brandIds, + forceResync, + }); + + return result.isErr() ? result : new Ok(connector.id.toString()); +} diff --git a/types/src/connectors/admin/cli.ts b/types/src/connectors/admin/cli.ts index ffe5fb69c84a..23c7c401d702 100644 --- a/types/src/connectors/admin/cli.ts +++ b/types/src/connectors/admin/cli.ts @@ -219,11 +219,16 @@ export type IntercomForceResyncArticlesResponseType = t.TypeOf< */ export const ZendeskCommandSchema = t.type({ majorCommand: t.literal("zendesk"), - command: t.union([t.literal("check-is-admin"), t.literal("count-tickets")]), + command: t.union([ + t.literal("check-is-admin"), + t.literal("count-tickets"), + t.literal("resync-tickets"), + ]), args: t.type({ connectorId: t.union([t.number, t.undefined]), brandId: t.union([t.number, t.undefined]), query: t.union([t.string, t.undefined]), + forceResync: t.boolean, }), }); export type ZendeskCommandType = t.TypeOf; @@ -243,6 +248,13 @@ export const ZendeskCountTicketsResponseSchema = t.type({ export type ZendeskCountTicketsResponseType = t.TypeOf< typeof ZendeskCountTicketsResponseSchema >; + +export const ZendeskResyncTicketsResponseSchema = t.type({ + success: t.literal(true), +}); +export type ZendeskResyncTicketsResponseType = t.TypeOf< + typeof ZendeskResyncTicketsResponseSchema +>; /** * */