mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
done
This commit is contained in:
parent
9c196416cd
commit
7d2e857613
29
packages/nodes-base/credentials/ZendeskApi.credentials.ts
Normal file
29
packages/nodes-base/credentials/ZendeskApi.credentials.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export class ZendeskApi implements ICredentialType {
|
||||||
|
name = 'zendeskApi';
|
||||||
|
displayName = 'Zendesk API';
|
||||||
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'URL',
|
||||||
|
name: 'url',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Email',
|
||||||
|
name: 'email',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'API Token',
|
||||||
|
name: 'apiToken',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
64
packages/nodes-base/nodes/Zendesk/GenericFunctions.ts
Normal file
64
packages/nodes-base/nodes/Zendesk/GenericFunctions.ts
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import { OptionsWithUri } from 'request';
|
||||||
|
import {
|
||||||
|
IExecuteFunctions,
|
||||||
|
IHookFunctions,
|
||||||
|
ILoadOptionsFunctions,
|
||||||
|
IExecuteSingleFunctions,
|
||||||
|
} from 'n8n-core';
|
||||||
|
import { IDataObject } from 'n8n-workflow';
|
||||||
|
|
||||||
|
export async function zendeskApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
const credentials = this.getCredentials('zendeskApi');
|
||||||
|
if (credentials === undefined) {
|
||||||
|
throw new Error('No credentials got returned!');
|
||||||
|
}
|
||||||
|
const base64Key = Buffer.from(`${credentials.email}/token:${credentials.apiToken}`).toString('base64')
|
||||||
|
let options: OptionsWithUri = {
|
||||||
|
headers: { 'Authorization': `Basic ${base64Key}`},
|
||||||
|
method,
|
||||||
|
qs,
|
||||||
|
body,
|
||||||
|
uri: uri ||`${credentials.domain}/api/v2${resource}`,
|
||||||
|
json: true
|
||||||
|
};
|
||||||
|
options = Object.assign({}, options, option);
|
||||||
|
if (Object.keys(options.body).length === 0) {
|
||||||
|
delete options.body;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await this.helpers.request!(options);
|
||||||
|
} catch (error) {
|
||||||
|
let errorMessage = error.message;
|
||||||
|
if (error.response.body) {
|
||||||
|
errorMessage = error.response.body.message || error.response.body.Message || error.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make an API request to paginated flow endpoint
|
||||||
|
* and return all results
|
||||||
|
*/
|
||||||
|
export async function zendeskApiRequestAllItems(this: IHookFunctions | IExecuteFunctions| ILoadOptionsFunctions, propertyName: string, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
|
const returnData: IDataObject[] = [];
|
||||||
|
|
||||||
|
let responseData;
|
||||||
|
|
||||||
|
let uri: string | undefined;
|
||||||
|
|
||||||
|
do {
|
||||||
|
responseData = await zendeskApiRequest.call(this, method, resource, body, query, uri);
|
||||||
|
query.continuation = responseData.pagination.continuation;
|
||||||
|
returnData.push.apply(returnData, responseData[propertyName]);
|
||||||
|
} while (
|
||||||
|
responseData.pagination !== undefined &&
|
||||||
|
responseData.pagination.has_more_items !== undefined &&
|
||||||
|
responseData.pagination.has_more_items !== false
|
||||||
|
);
|
||||||
|
|
||||||
|
return returnData;
|
||||||
|
}
|
149
packages/nodes-base/nodes/Zendesk/ZendeskTrigger.node.ts
Normal file
149
packages/nodes-base/nodes/Zendesk/ZendeskTrigger.node.ts
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
import {
|
||||||
|
IHookFunctions,
|
||||||
|
IWebhookFunctions,
|
||||||
|
} from 'n8n-core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
INodeTypeDescription,
|
||||||
|
INodeType,
|
||||||
|
IWebhookResponseData,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
import {
|
||||||
|
zendeskApiRequest,
|
||||||
|
} from './GenericFunctions';
|
||||||
|
|
||||||
|
export class ZendeskTrigger implements INodeType {
|
||||||
|
description: INodeTypeDescription = {
|
||||||
|
displayName: 'Zendesk Trigger',
|
||||||
|
name: 'zendesk',
|
||||||
|
icon: 'file:zendesk.png',
|
||||||
|
group: ['trigger'],
|
||||||
|
version: 1,
|
||||||
|
description: 'Handle Zendesk events via webhooks',
|
||||||
|
defaults: {
|
||||||
|
name: 'Zendesk Trigger',
|
||||||
|
color: '#559922',
|
||||||
|
},
|
||||||
|
inputs: [],
|
||||||
|
outputs: ['main'],
|
||||||
|
credentials: [
|
||||||
|
{
|
||||||
|
name: 'zendeskApi',
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
webhooks: [
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
httpMethod: 'POST',
|
||||||
|
responseMode: 'onReceived',
|
||||||
|
path: 'webhook',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Service',
|
||||||
|
name: 'service',
|
||||||
|
type: 'options',
|
||||||
|
required: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Support',
|
||||||
|
value: 'support',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
default: 'support',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Events',
|
||||||
|
name: 'events',
|
||||||
|
type: 'multiOptions',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
service: [
|
||||||
|
'support'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'ticket.status.open',
|
||||||
|
value: 'ticket.status.open'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
required: true,
|
||||||
|
default: [],
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
};
|
||||||
|
// @ts-ignore
|
||||||
|
webhookMethods = {
|
||||||
|
default: {
|
||||||
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||||
|
let webhooks;
|
||||||
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
if (webhookData.webhookId === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const endpoint = `/webhooks/${webhookData.webhookId}/`;
|
||||||
|
try {
|
||||||
|
webhooks = await zendeskApiRequest.call(this, 'GET', endpoint);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
async create(this: IHookFunctions): Promise<boolean> {
|
||||||
|
let body, responseData;
|
||||||
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||||
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
const event = this.getNodeParameter('event') as string;
|
||||||
|
const actions = this.getNodeParameter('actions') as string[];
|
||||||
|
const endpoint = `/webhooks/`;
|
||||||
|
// @ts-ignore
|
||||||
|
body = {
|
||||||
|
endpoint_url: webhookUrl,
|
||||||
|
actions: actions.join(','),
|
||||||
|
event_id: event,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
responseData = await zendeskApiRequest.call(this, 'POST', endpoint, body);
|
||||||
|
} catch(error) {
|
||||||
|
console.log(error)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
webhookData.webhookId = responseData.id;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
async delete(this: IHookFunctions): Promise<boolean> {
|
||||||
|
let responseData;
|
||||||
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
const endpoint = `/webhooks/${webhookData.webhookId}/`;
|
||||||
|
try {
|
||||||
|
responseData = await zendeskApiRequest.call(this, 'DELETE', endpoint);
|
||||||
|
} catch(error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!responseData.success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
delete webhookData.webhookId;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||||
|
const req = this.getRequestObject();
|
||||||
|
return {
|
||||||
|
workflowData: [
|
||||||
|
this.helpers.returnJsonArray(req.body)
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
BIN
packages/nodes-base/nodes/Zendesk/zendesk.png
Normal file
BIN
packages/nodes-base/nodes/Zendesk/zendesk.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
|
@ -75,7 +75,8 @@
|
||||||
"dist/credentials/TypeformApi.credentials.js",
|
"dist/credentials/TypeformApi.credentials.js",
|
||||||
"dist/credentials/TogglApi.credentials.js",
|
"dist/credentials/TogglApi.credentials.js",
|
||||||
"dist/credentials/VeroApi.credentials.js",
|
"dist/credentials/VeroApi.credentials.js",
|
||||||
"dist/credentials/WordpressApi.credentials.js"
|
"dist/credentials/WordpressApi.credentials.js",
|
||||||
|
"dist/credentials/ZendeskApi.credentials.js"
|
||||||
],
|
],
|
||||||
"nodes": [
|
"nodes": [
|
||||||
"dist/nodes/ActiveCampaign/ActiveCampaign.node.js",
|
"dist/nodes/ActiveCampaign/ActiveCampaign.node.js",
|
||||||
|
@ -165,7 +166,8 @@
|
||||||
"dist/nodes/WriteBinaryFile.node.js",
|
"dist/nodes/WriteBinaryFile.node.js",
|
||||||
"dist/nodes/Webhook.node.js",
|
"dist/nodes/Webhook.node.js",
|
||||||
"dist/nodes/Wordpress/Wordpress.node.js",
|
"dist/nodes/Wordpress/Wordpress.node.js",
|
||||||
"dist/nodes/Xml.node.js"
|
"dist/nodes/Xml.node.js",
|
||||||
|
"dist/nodes/Zendesk/ZendeskTrigger.node.js"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
Loading…
Reference in a new issue