diff --git a/service/src/config.ts b/service/src/config.ts index eba1781..9c1a6f2 100644 --- a/service/src/config.ts +++ b/service/src/config.ts @@ -82,6 +82,13 @@ export const { config } = await libConfig({ }, }, syncTicket: { + enable: { + doc: 'Enable the syncTicket service to find new work within Zendesk', + format: Boolean, + default: true, + env: 'SERVICE_SYNC_TICKET_ENABLE', + arg: 'service-sync-ticket-enable', + }, timeout: { doc: 'Time limit for processing a ticket archive', format: Number, diff --git a/service/src/index.ts b/service/src/index.ts index e9799d9..f5e11e8 100644 --- a/service/src/index.ts +++ b/service/src/index.ts @@ -59,12 +59,16 @@ async function run() { concurrency: config.get('zendesk.concurrency'), }); - log.info('Initialize `archiveTicket` service'); - service.on( - 'syncTicket', - config.get('service.syncTicket.timeout'), - syncTicketService, - ); + if (config.get('service.syncTicket.enable')) { + log.info('Initialize `syncTicket` service'); + service.on( + 'syncTicket', + config.get('service.syncTicket.timeout'), + syncTicketService, + ); + } else { + log.info('syncTicket service disabled.'); + } log.info('Start @oada/jobs based services'); await service.start(); diff --git a/service/src/services/poller.ts b/service/src/services/poller.ts index ddaed06..2ec778b 100644 --- a/service/src/services/poller.ts +++ b/service/src/services/poller.ts @@ -85,8 +85,10 @@ export function pollerService(logOrig: Logger, oada: OADAClient): CronJob { // Update Zendesk with the new state, but only if changed. Otherwise, Zendesk tickets are flodded with "useless" updates if ( - currentState !== nextState.state || - currentStatus !== nextState.status + (nextState.state !== undefined && + currentState !== nextState.state) || + (nextState.status !== undefined && + currentStatus !== nextState.status) ) { await setTrellisState(log, ticket, nextState); } @@ -119,13 +121,15 @@ async function computeNextState( const currentState = getTicketFieldValue(ticket, config.get('zendesk.fields.state')) ?? ''; + log.trace({ currentState }, 'Lookup ticket currentState'); + if (currentState !== '' && currentState !== STATE_PENDING) { log.trace( { currentState }, `Poller found a ticket already post ${STATE_PENDING}. Keeping current state.`, ); - return { state: currentState, status: undefined }; + return { state: undefined, status: undefined }; } // **Should** always have a customer ID if ZenDesk is configured correctly (i.e., a trigger that requires it to "solve") diff --git a/service/src/zd/utils.ts b/service/src/zd/utils.ts index 71f9416..f319ea8 100644 --- a/service/src/zd/utils.ts +++ b/service/src/zd/utils.ts @@ -39,8 +39,6 @@ export async function callTypedApi( key: string, cnf?: AxiosRequestConfig, ): Promise { - log.trace(`Making credentialed API request: ${url}`); - const data = await makeCredentialedGetRequest>( log, url, @@ -110,9 +108,9 @@ export async function makeCredentialedGetRequest( return { buffer: r.data, } as T; - } else { - return r.data as T; } + + return r.data as T; } export async function makeCredentialedPutRequest( @@ -152,7 +150,7 @@ export function indexById( // TYPES export interface TrellisState { - state: string; + state: string | undefined; status: string | undefined; } diff --git a/service/src/zd/zendesk.ts b/service/src/zd/zendesk.ts index 61544ca..a18564d 100644 --- a/service/src/zd/zendesk.ts +++ b/service/src/zd/zendesk.ts @@ -368,12 +368,14 @@ export async function setTrellisState( return; } - const updates = [ - { + const updates: Array<{ id: string | number; value: string | number }> = []; + + if (state.state) { + updates.push({ id: config.get('zendesk.fields.state'), value: state.state, - }, - ]; + }); + } if (state.status) { updates.push({ @@ -382,7 +384,11 @@ export async function setTrellisState( }); } - await setCustomField(log, ticket, updates); + if (updates.length) { + await setCustomField(log, ticket, updates); + } else { + log.debug('No state change to update'); + } } export async function setTicketStatus(