mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
⚡ Small fixes and improvements on Zendesk-Node
This commit is contained in:
parent
150c32e349
commit
97cc3af4c3
|
@ -12,7 +12,6 @@ export const conditionFields = [
|
|||
},
|
||||
],
|
||||
default: 'ticket',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Field',
|
||||
|
@ -48,7 +47,6 @@ export const conditionFields = [
|
|||
},
|
||||
],
|
||||
default: 'status',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Operation',
|
||||
|
@ -104,7 +102,6 @@ export const conditionFields = [
|
|||
}
|
||||
},
|
||||
default: 'is',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Operation',
|
||||
|
@ -152,7 +149,6 @@ export const conditionFields = [
|
|||
}
|
||||
},
|
||||
default: 'is',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
|
@ -200,7 +196,6 @@ export const conditionFields = [
|
|||
},
|
||||
],
|
||||
default: 'open',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
|
@ -244,7 +239,6 @@ export const conditionFields = [
|
|||
},
|
||||
],
|
||||
default: 'question',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
|
@ -288,7 +282,6 @@ export const conditionFields = [
|
|||
},
|
||||
],
|
||||
default: 'low',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
|
@ -313,7 +306,6 @@ export const conditionFields = [
|
|||
},
|
||||
},
|
||||
default: '',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
|
@ -338,6 +330,5 @@ export const conditionFields = [
|
|||
},
|
||||
},
|
||||
default: '',
|
||||
description: '',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { OptionsWithUri } from 'request';
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IDataObject } from 'n8n-workflow';
|
||||
|
||||
|
@ -12,7 +12,7 @@ export async function zendeskApiRequest(this: IHookFunctions | IExecuteFunctions
|
|||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
const base64Key = Buffer.from(`${credentials.email}/token:${credentials.apiToken}`).toString('base64')
|
||||
const base64Key = Buffer.from(`${credentials.email}/token:${credentials.apiToken}`).toString('base64');
|
||||
let options: OptionsWithUri = {
|
||||
headers: { 'Authorization': `Basic ${base64Key}`},
|
||||
method,
|
||||
|
@ -46,7 +46,7 @@ export async function zendeskApiRequestAllItems(this: IHookFunctions | IExecuteF
|
|||
|
||||
do {
|
||||
responseData = await zendeskApiRequest.call(this, method, resource, body, query, uri);
|
||||
uri = responseData.next_page
|
||||
uri = responseData.next_page;
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
} while (
|
||||
responseData.next_page !== undefined &&
|
||||
|
|
|
@ -21,22 +21,22 @@ export const ticketOperations = [
|
|||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a ticket'
|
||||
description: 'Update a ticket',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a ticket'
|
||||
description: 'Get a ticket',
|
||||
},
|
||||
{
|
||||
name: 'Get All',
|
||||
value: 'getAll',
|
||||
description: 'Get all tickets'
|
||||
description: 'Get all tickets',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a ticket'
|
||||
description: 'Delete a ticket',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { IDataObject } from "n8n-workflow";
|
||||
|
||||
export interface ITicket {
|
||||
subject?: string;
|
||||
comment?: IComment;
|
||||
|
|
|
@ -102,7 +102,7 @@ export class Zendesk implements INodeType {
|
|||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length as unknown as number;
|
||||
let qs: IDataObject = {};
|
||||
const qs: IDataObject = {};
|
||||
let responseData;
|
||||
for (let i = 0; i < length; i++) {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
|
@ -194,9 +194,9 @@ export class Zendesk implements INodeType {
|
|||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
qs.query = 'type:ticket'
|
||||
qs.query = 'type:ticket';
|
||||
if (options.status) {
|
||||
qs.query += ` status:${options.status}`
|
||||
qs.query += ` status:${options.status}`;
|
||||
}
|
||||
if (options.sortBy) {
|
||||
qs.sort_by = options.sortBy;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
import {
|
||||
parse as urlParse,
|
||||
} from 'url';
|
||||
|
||||
import {
|
||||
IHookFunctions,
|
||||
IWebhookFunctions,
|
||||
|
@ -23,7 +27,7 @@ import {
|
|||
export class ZendeskTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Zendesk Trigger',
|
||||
name: 'zendesk',
|
||||
name: 'zendeskTrigger',
|
||||
icon: 'file:zendesk.png',
|
||||
group: ['trigger'],
|
||||
version: 1,
|
||||
|
@ -63,21 +67,6 @@ export class ZendeskTrigger implements INodeType {
|
|||
default: 'support',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'title',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
service: [
|
||||
'support'
|
||||
]
|
||||
}
|
||||
},
|
||||
required: true,
|
||||
default: '',
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
|
@ -94,6 +83,7 @@ export class ZendeskTrigger implements INodeType {
|
|||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fields',
|
||||
description: 'The fields to return the values of.',
|
||||
type: 'multiOptions',
|
||||
default: [],
|
||||
options: [
|
||||
|
@ -397,11 +387,11 @@ export class ZendeskTrigger implements INodeType {
|
|||
returnData.push({
|
||||
name: 'Current User',
|
||||
value: 'current_user',
|
||||
})
|
||||
});
|
||||
returnData.push({
|
||||
name: 'Requester',
|
||||
value: 'requester_id',
|
||||
})
|
||||
});
|
||||
return returnData;
|
||||
},
|
||||
}
|
||||
|
@ -423,14 +413,13 @@ export class ZendeskTrigger implements INodeType {
|
|||
return true;
|
||||
},
|
||||
async create(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
const webhookUrl = this.getNodeWebhookUrl('default') as string;
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
const service = this.getNodeParameter('service') as string;
|
||||
if (service === 'support') {
|
||||
const aux: IDataObject = {};
|
||||
const message: IDataObject = {};
|
||||
const resultAll = [], resultAny = [];
|
||||
const title = this.getNodeParameter('title') as string;
|
||||
const conditions = this.getNodeParameter('conditions') as IDataObject;
|
||||
const options = this.getNodeParameter('options') as IDataObject;
|
||||
if (Object.keys(conditions).length === 0) {
|
||||
|
@ -438,16 +427,16 @@ export class ZendeskTrigger implements INodeType {
|
|||
}
|
||||
if (options.fields) {
|
||||
// @ts-ignore
|
||||
for (let field of options.fields) {
|
||||
for (const field of options.fields) {
|
||||
// @ts-ignore
|
||||
message[field] = `{{${field}}}`;
|
||||
}
|
||||
} else {
|
||||
message['ticket.id'] = '{{ticket.id}}'
|
||||
message['ticket.id'] = '{{ticket.id}}';
|
||||
}
|
||||
const conditionsAll = conditions.all as [IDataObject];
|
||||
if (conditionsAll) {
|
||||
for (let conditionAll of conditionsAll) {
|
||||
for (const conditionAll of conditionsAll) {
|
||||
aux.field = conditionAll.field;
|
||||
aux.operator = conditionAll.operation;
|
||||
if (conditionAll.operation !== 'changed'
|
||||
|
@ -456,12 +445,12 @@ export class ZendeskTrigger implements INodeType {
|
|||
} else {
|
||||
aux.value = null;
|
||||
}
|
||||
resultAll.push(aux)
|
||||
resultAll.push(aux);
|
||||
}
|
||||
}
|
||||
const conditionsAny = conditions.any as [IDataObject];
|
||||
if (conditionsAny) {
|
||||
for (let conditionAny of conditionsAny) {
|
||||
for (const conditionAny of conditionsAny) {
|
||||
aux.field = conditionAny.field;
|
||||
aux.operator = conditionAny.operation;
|
||||
if (conditionAny.operation !== 'changed'
|
||||
|
@ -470,12 +459,13 @@ export class ZendeskTrigger implements INodeType {
|
|||
} else {
|
||||
aux.value = null;
|
||||
}
|
||||
resultAny.push(aux)
|
||||
resultAny.push(aux);
|
||||
}
|
||||
}
|
||||
const urlParts = urlParse(webhookUrl);
|
||||
const bodyTrigger: IDataObject = {
|
||||
trigger: {
|
||||
title,
|
||||
title: `n8n-webhook:${urlParts.path}`,
|
||||
conditions: {
|
||||
all: resultAll,
|
||||
any: resultAny,
|
||||
|
@ -487,10 +477,10 @@ export class ZendeskTrigger implements INodeType {
|
|||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
};
|
||||
const bodyTarget: IDataObject = {
|
||||
target: {
|
||||
title: 'N8N webhook',
|
||||
title: 'n8n webhook',
|
||||
type: 'http_target',
|
||||
target_url: webhookUrl,
|
||||
method: 'POST',
|
||||
|
@ -516,7 +506,7 @@ export class ZendeskTrigger implements INodeType {
|
|||
return false;
|
||||
}
|
||||
delete webhookData.webhookId;
|
||||
delete webhookData.targetId
|
||||
delete webhookData.targetId;
|
||||
return true;
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue