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