Merge branch 'master' of https://github.com/krasaee/n8n
This commit is contained in:
@@ -176,7 +176,7 @@ export class Start extends Command {
|
||||
Start.openBrowser();
|
||||
}
|
||||
this.log(`\nPress "o" to open in Browser.`);
|
||||
process.stdin.on("data", (key) => {
|
||||
process.stdin.on("data", (key: string) => {
|
||||
if (key === 'o') {
|
||||
Start.openBrowser();
|
||||
inputText = '';
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
"index.ts",
|
||||
"src"
|
||||
],
|
||||
"exec": "npm start",
|
||||
"exec": "npm run build && npm start",
|
||||
"ext": "ts"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "n8n",
|
||||
"version": "0.44.0",
|
||||
"version": "0.45.0",
|
||||
"description": "n8n Workflow Automation Tool",
|
||||
"license": "SEE LICENSE IN LICENSE.md",
|
||||
"homepage": "https://n8n.io",
|
||||
@@ -78,9 +78,11 @@
|
||||
"basic-auth": "^2.0.1",
|
||||
"body-parser": "^1.18.3",
|
||||
"body-parser-xml": "^1.1.0",
|
||||
"client-oauth2": "^4.2.5",
|
||||
"compression": "^1.7.4",
|
||||
"connect-history-api-fallback": "^1.6.0",
|
||||
"convict": "^5.0.0",
|
||||
"csrf": "^3.1.0",
|
||||
"dotenv": "^8.0.0",
|
||||
"express": "^4.16.4",
|
||||
"flatted": "^2.0.0",
|
||||
@@ -93,8 +95,8 @@
|
||||
"lodash.get": "^4.4.2",
|
||||
"mongodb": "^3.2.3",
|
||||
"n8n-core": "~0.20.0",
|
||||
"n8n-editor-ui": "~0.31.0",
|
||||
"n8n-nodes-base": "~0.39.0",
|
||||
"n8n-editor-ui": "~0.32.0",
|
||||
"n8n-nodes-base": "~0.40.0",
|
||||
"n8n-workflow": "~0.20.0",
|
||||
"open": "^7.0.0",
|
||||
"pg": "^7.11.0",
|
||||
|
||||
@@ -10,6 +10,9 @@ import * as bodyParser from 'body-parser';
|
||||
require('body-parser-xml')(bodyParser);
|
||||
import * as history from 'connect-history-api-fallback';
|
||||
import * as requestPromise from 'request-promise-native';
|
||||
import * as _ from 'lodash';
|
||||
import * as clientOAuth2 from 'client-oauth2';
|
||||
import * as csrf from 'csrf';
|
||||
|
||||
import {
|
||||
ActiveExecutions,
|
||||
@@ -654,6 +657,10 @@ class App {
|
||||
throw new Error('No encryption key got found to encrypt the credentials!');
|
||||
}
|
||||
|
||||
if (incomingData.name === '') {
|
||||
throw new Error('Credentials have to have a name set!');
|
||||
}
|
||||
|
||||
// Check if credentials with the same name and type exist already
|
||||
const findQuery = {
|
||||
where: {
|
||||
@@ -693,6 +700,10 @@ class App {
|
||||
|
||||
const id = req.params.id;
|
||||
|
||||
if (incomingData.name === '') {
|
||||
throw new Error('Credentials have to have a name set!');
|
||||
}
|
||||
|
||||
// Add the date for newly added node access permissions
|
||||
for (const nodeAccess of incomingData.nodesAccess) {
|
||||
if (!nodeAccess.date) {
|
||||
@@ -721,6 +732,8 @@ class App {
|
||||
|
||||
// Encrypt the data
|
||||
const credentials = new Credentials(incomingData.name, incomingData.type, incomingData.nodesAccess);
|
||||
_.unset(incomingData.data, 'csrfSecret');
|
||||
_.unset(incomingData.data, 'oauthTokenData');
|
||||
credentials.setData(incomingData.data, encryptionKey);
|
||||
const newCredentialsData = credentials.getDataToSave() as unknown as ICredentialsDb;
|
||||
|
||||
@@ -840,8 +853,138 @@ class App {
|
||||
return returnData;
|
||||
}));
|
||||
|
||||
// ----------------------------------------
|
||||
// OAuth2-Credential/Auth
|
||||
// ----------------------------------------
|
||||
|
||||
|
||||
// Returns all the credential types which are defined in the loaded n8n-modules
|
||||
this.app.get('/rest/oauth2-credential/auth', ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<string> => {
|
||||
if (req.query.id === undefined) {
|
||||
throw new Error('Required credential id is missing!');
|
||||
}
|
||||
|
||||
const result = await Db.collections.Credentials!.findOne(req.query.id);
|
||||
if (result === undefined) {
|
||||
res.status(404).send('The credential is not known.');
|
||||
return '';
|
||||
}
|
||||
|
||||
let encryptionKey = undefined;
|
||||
encryptionKey = await UserSettings.getEncryptionKey();
|
||||
if (encryptionKey === undefined) {
|
||||
throw new Error('No encryption key got found to decrypt the credentials!');
|
||||
}
|
||||
|
||||
const credentials = new Credentials(result.name, result.type, result.nodesAccess, result.data);
|
||||
(result as ICredentialsDecryptedDb).data = credentials.getData(encryptionKey!);
|
||||
(result as ICredentialsDecryptedResponse).id = result.id.toString();
|
||||
|
||||
const oauthCredentials = (result as ICredentialsDecryptedDb).data;
|
||||
if (oauthCredentials === undefined) {
|
||||
throw new Error('Unable to read OAuth credentials');
|
||||
}
|
||||
|
||||
let token = new csrf();
|
||||
// Generate a CSRF prevention token and send it as a OAuth2 state stringma/ERR
|
||||
oauthCredentials.csrfSecret = token.secretSync();
|
||||
const state = {
|
||||
'token': token.create(oauthCredentials.csrfSecret),
|
||||
'cid': req.query.id
|
||||
}
|
||||
const stateEncodedStr = Buffer.from(JSON.stringify(state)).toString('base64') as string;
|
||||
|
||||
const oAuthObj = new clientOAuth2({
|
||||
clientId: _.get(oauthCredentials, 'clientId') as string,
|
||||
clientSecret: _.get(oauthCredentials, 'clientSecret', '') as string,
|
||||
accessTokenUri: _.get(oauthCredentials, 'accessTokenUrl', '') as string,
|
||||
authorizationUri: _.get(oauthCredentials, 'authUrl', '') as string,
|
||||
redirectUri: _.get(oauthCredentials, 'callbackUrl', WebhookHelpers.getWebhookBaseUrl()) as string,
|
||||
scopes: _.split(_.get(oauthCredentials, 'scope', 'openid,') as string, ','),
|
||||
state: stateEncodedStr
|
||||
});
|
||||
|
||||
credentials.setData(oauthCredentials, encryptionKey);
|
||||
const newCredentialsData = credentials.getDataToSave() as unknown as ICredentialsDb;
|
||||
|
||||
// Add special database related data
|
||||
newCredentialsData.updatedAt = this.getCurrentDate();
|
||||
|
||||
// Update the credentials in DB
|
||||
await Db.collections.Credentials!.update(req.query.id, newCredentialsData);
|
||||
|
||||
return oAuthObj.code.getUri();
|
||||
}));
|
||||
|
||||
// ----------------------------------------
|
||||
// OAuth2-Credential/Callback
|
||||
// ----------------------------------------
|
||||
|
||||
// Verify and store app code. Generate access tokens and store for respective credential.
|
||||
this.app.get('/rest/oauth2-credential/callback', ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<string> => {
|
||||
const {code, state: stateEncoded} = req.query;
|
||||
if (code === undefined || stateEncoded === undefined) {
|
||||
throw new Error('Insufficient parameters for OAuth2 callback')
|
||||
}
|
||||
|
||||
let state;
|
||||
try {
|
||||
state = JSON.parse(Buffer.from(stateEncoded, 'base64').toString());
|
||||
} catch (error) {
|
||||
throw new Error('Invalid state format returned');
|
||||
}
|
||||
|
||||
const result = await Db.collections.Credentials!.findOne(state.cid);
|
||||
if (result === undefined) {
|
||||
res.status(404).send('The credential is not known.');
|
||||
return '';
|
||||
}
|
||||
|
||||
let encryptionKey = undefined;
|
||||
encryptionKey = await UserSettings.getEncryptionKey();
|
||||
if (encryptionKey === undefined) {
|
||||
throw new Error('No encryption key got found to decrypt the credentials!');
|
||||
}
|
||||
|
||||
const credentials = new Credentials(result.name, result.type, result.nodesAccess, result.data);
|
||||
(result as ICredentialsDecryptedDb).data = credentials.getData(encryptionKey!);
|
||||
const oauthCredentials = (result as ICredentialsDecryptedDb).data;
|
||||
if (oauthCredentials === undefined) {
|
||||
throw new Error('Unable to read OAuth credentials');
|
||||
}
|
||||
|
||||
let token = new csrf();
|
||||
if (oauthCredentials.csrfSecret === undefined || !token.verify(oauthCredentials.csrfSecret as string, state.token)) {
|
||||
res.status(404).send('The OAuth2 callback state is invalid.');
|
||||
return '';
|
||||
}
|
||||
|
||||
const oAuthObj = new clientOAuth2({
|
||||
clientId: _.get(oauthCredentials, 'clientId') as string,
|
||||
clientSecret: _.get(oauthCredentials, 'clientSecret', '') as string,
|
||||
accessTokenUri: _.get(oauthCredentials, 'accessTokenUrl', '') as string,
|
||||
authorizationUri: _.get(oauthCredentials, 'authUrl', '') as string,
|
||||
redirectUri: _.get(oauthCredentials, 'callbackUrl', WebhookHelpers.getWebhookBaseUrl()) as string,
|
||||
scopes: _.split(_.get(oauthCredentials, 'scope', 'openid,') as string, ',')
|
||||
});
|
||||
|
||||
const oauthToken = await oAuthObj.code.getToken(req.originalUrl);
|
||||
if (oauthToken === undefined) {
|
||||
throw new Error('Unable to get access tokens');
|
||||
}
|
||||
|
||||
oauthCredentials.oauthTokenData = JSON.stringify(oauthToken.data);
|
||||
_.unset(oauthCredentials, 'csrfSecret');
|
||||
credentials.setData(oauthCredentials, encryptionKey);
|
||||
const newCredentialsData = credentials.getDataToSave() as unknown as ICredentialsDb;
|
||||
// Add special database related data
|
||||
newCredentialsData.updatedAt = this.getCurrentDate();
|
||||
// Save the credentials in DB
|
||||
await Db.collections.Credentials!.update(state.cid, newCredentialsData);
|
||||
|
||||
return 'Success!';
|
||||
}));
|
||||
|
||||
// ----------------------------------------
|
||||
// Executions
|
||||
// ----------------------------------------
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "n8n-editor-ui",
|
||||
"version": "0.31.0",
|
||||
"version": "0.32.0",
|
||||
"description": "Workflow Editor UI for n8n",
|
||||
"license": "SEE LICENSE IN LICENSE.md",
|
||||
"homepage": "https://n8n.io",
|
||||
|
||||
@@ -145,6 +145,8 @@ export interface IRestApi {
|
||||
deleteExecutions(sendData: IExecutionDeleteFilter): Promise<void>;
|
||||
retryExecution(id: string, loadWorkflow?: boolean): Promise<boolean>;
|
||||
getTimezones(): Promise<IDataObject>;
|
||||
OAuth2CredentialAuthorize(sendData: ICredentialsResponse): Promise<string>;
|
||||
OAuth2Callback(code: string, state: string): Promise<string>;
|
||||
}
|
||||
|
||||
export interface IBinaryDisplayData {
|
||||
|
||||
88
packages/editor-ui/src/components/About.vue
Normal file
88
packages/editor-ui/src/components/About.vue
Normal file
@@ -0,0 +1,88 @@
|
||||
<template>
|
||||
<span>
|
||||
<el-dialog class="n8n-about" :visible="dialogVisible" append-to-body width="50%" title="About n8n" :before-close="closeDialog">
|
||||
<div>
|
||||
<el-row>
|
||||
<el-col :span="8" class="info-name">
|
||||
n8n Version:
|
||||
</el-col>
|
||||
<el-col :span="16">
|
||||
{{versionCli}}
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="8" class="info-name">
|
||||
Source Code:
|
||||
</el-col>
|
||||
<el-col :span="16">
|
||||
<a href="https://github.com/n8n-io/n8n" target="_blank">https://github.com/n8n-io/n8n</a>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="8" class="info-name">
|
||||
License:
|
||||
</el-col>
|
||||
<el-col :span="16">
|
||||
<a href="https://github.com/n8n-io/n8n/blob/master/packages/cli/LICENSE.md" target="_blank">Apache 2.0 with Commons Clause</a>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<div class="action-buttons">
|
||||
<el-button type="success" @click="closeDialog">
|
||||
Close
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from 'vue';
|
||||
|
||||
import { genericHelpers } from '@/components/mixins/genericHelpers';
|
||||
import { showMessage } from '@/components/mixins/showMessage';
|
||||
|
||||
import mixins from 'vue-typed-mixins';
|
||||
|
||||
export default mixins(
|
||||
genericHelpers,
|
||||
showMessage,
|
||||
).extend({
|
||||
name: 'About',
|
||||
props: [
|
||||
'dialogVisible',
|
||||
],
|
||||
computed: {
|
||||
versionCli (): string {
|
||||
return this.$store.getters.versionCli;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
closeDialog () {
|
||||
// Handle the close externally as the visible parameter is an external prop
|
||||
// and is so not allowed to be changed here.
|
||||
this.$emit('closeDialog');
|
||||
return false;
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.n8n-about {
|
||||
.el-row {
|
||||
padding: 0.25em 0;
|
||||
}
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
margin-top: 1em;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.info-name {
|
||||
line-height: 32px;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -25,10 +25,12 @@
|
||||
<el-table-column property="updatedAt" label="Updated" class-name="clickable" sortable></el-table-column>
|
||||
<el-table-column
|
||||
label="Operations"
|
||||
width="120">
|
||||
width="180">
|
||||
<template slot-scope="scope">
|
||||
<el-button title="Edit Credentials" @click.stop="editCredential(scope.row)" icon="el-icon-edit" circle></el-button>
|
||||
<el-button title="Delete Credentials" @click.stop="deleteCredential(scope.row)" type="danger" icon="el-icon-delete" circle></el-button>
|
||||
<!-- Would be nice to have this button switch from connect to disconnect based on the credential status -->
|
||||
<el-button title="Connect OAuth Credentials" @click.stop="OAuth2CredentialAuthorize(scope.row)" icon="el-icon-caret-right" v-if="scope.row.type == 'OAuth2Api'" circle></el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -91,6 +93,20 @@ export default mixins(
|
||||
this.editCredentials = null;
|
||||
this.credentialEditDialogVisible = true;
|
||||
},
|
||||
async OAuth2CredentialAuthorize (credential: ICredentialsResponse) {
|
||||
let url;
|
||||
try {
|
||||
url = await this.restApi().OAuth2CredentialAuthorize(credential) as string;
|
||||
} catch (error) {
|
||||
this.$showError(error, 'OAuth Authorization Error', 'Error generating authorization URL:');
|
||||
return;
|
||||
}
|
||||
|
||||
const params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=0,height=0,left=-1000,top=-1000`;
|
||||
const oauthPopup = window.open(url, 'OAuth2 Authorization', params);
|
||||
|
||||
console.log(oauthPopup);
|
||||
},
|
||||
editCredential (credential: ICredentialsResponse) {
|
||||
const editCredentials = {
|
||||
id: credential.id,
|
||||
@@ -124,7 +140,7 @@ export default mixins(
|
||||
try {
|
||||
this.credentials = JSON.parse(JSON.stringify(this.$store.getters.allCredentials));
|
||||
} catch (error) {
|
||||
this.$showError(error, 'Proble loading credentials', 'There was a problem loading the credentials:');
|
||||
this.$showError(error, 'Problem loading credentials', 'There was a problem loading the credentials:');
|
||||
this.isDataLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<div id="side-menu">
|
||||
<about :dialogVisible="aboutDialogVisible" @closeDialog="closeAboutDialog"></about>
|
||||
<executions-list :dialogVisible="executionsListDialogVisible" @closeDialog="closeExecutionsListOpenDialog"></executions-list>
|
||||
<credentials-list :dialogVisible="credentialOpenDialogVisible" @closeDialog="closeCredentialOpenDialog"></credentials-list>
|
||||
<credentials-edit :dialogVisible="credentialNewDialogVisible" @closeDialog="closeCredentialNewDialog"></credentials-edit>
|
||||
@@ -14,15 +15,9 @@
|
||||
<el-menu default-active="workflow" @select="handleSelect" :collapse="isCollapsed">
|
||||
|
||||
<el-menu-item index="logo" class="logo-item">
|
||||
<el-tooltip placement="top" effect="light">
|
||||
<div slot="content">
|
||||
n8n.io - Currently installed version {{versionCli}}
|
||||
</div>
|
||||
<a href="https://n8n.io" target="_blank" class="logo">
|
||||
<img src="/n8n-icon-small.png" class="icon" alt="n8n.io"/>
|
||||
|
||||
</el-tooltip>
|
||||
<a href="https://n8n.io" class="logo-text" target="_blank" slot="title">
|
||||
n8n.io
|
||||
<span class="logo-text" slot="title">n8n.io</span>
|
||||
</a>
|
||||
</el-menu-item>
|
||||
|
||||
@@ -149,6 +144,12 @@
|
||||
</a>
|
||||
</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="help-about">
|
||||
<template slot="title">
|
||||
<font-awesome-icon class="about-icon" icon="info"/>
|
||||
<span slot="title" class="item-title">About n8n</span>
|
||||
</template>
|
||||
</el-menu-item>
|
||||
</el-submenu>
|
||||
|
||||
</el-menu>
|
||||
@@ -168,6 +169,7 @@ import {
|
||||
IWorkflowDataUpdate,
|
||||
} from '../Interface';
|
||||
|
||||
import About from '@/components/About.vue';
|
||||
import CredentialsEdit from '@/components/CredentialsEdit.vue';
|
||||
import CredentialsList from '@/components/CredentialsList.vue';
|
||||
import ExecutionsList from '@/components/ExecutionsList.vue';
|
||||
@@ -196,6 +198,7 @@ export default mixins(
|
||||
.extend({
|
||||
name: 'MainHeader',
|
||||
components: {
|
||||
About,
|
||||
CredentialsEdit,
|
||||
CredentialsList,
|
||||
ExecutionsList,
|
||||
@@ -204,6 +207,7 @@ export default mixins(
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
aboutDialogVisible: false,
|
||||
isCollapsed: true,
|
||||
credentialNewDialogVisible: false,
|
||||
credentialOpenDialogVisible: false,
|
||||
@@ -251,9 +255,6 @@ export default mixins(
|
||||
currentWorkflow (): string {
|
||||
return this.$route.params.name;
|
||||
},
|
||||
versionCli (): string {
|
||||
return this.$store.getters.versionCli;
|
||||
},
|
||||
workflowExecution (): IExecutionResponse | null {
|
||||
return this.$store.getters.getWorkflowExecution;
|
||||
},
|
||||
@@ -269,6 +270,9 @@ export default mixins(
|
||||
this.$store.commit('setWorkflowExecutionData', null);
|
||||
this.updateNodesExecutionIssues();
|
||||
},
|
||||
closeAboutDialog () {
|
||||
this.aboutDialogVisible = false;
|
||||
},
|
||||
closeWorkflowOpenDialog () {
|
||||
this.workflowOpenDialogVisible = false;
|
||||
},
|
||||
@@ -434,6 +438,8 @@ export default mixins(
|
||||
this.saveCurrentWorkflow();
|
||||
} else if (key === 'workflow-save-as') {
|
||||
this.saveCurrentWorkflow(true);
|
||||
} else if (key === 'help-about') {
|
||||
this.aboutDialogVisible = true;
|
||||
} else if (key === 'workflow-settings') {
|
||||
this.workflowSettingsDialogVisible = true;
|
||||
} else if (key === 'workflow-new') {
|
||||
@@ -466,6 +472,9 @@ export default mixins(
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.about-icon {
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
#collapse-change-button {
|
||||
position: absolute;
|
||||
@@ -520,7 +529,11 @@ export default mixins(
|
||||
}
|
||||
}
|
||||
|
||||
a.logo-text {
|
||||
a.logo {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.logo-text {
|
||||
position: relative;
|
||||
top: -3px;
|
||||
left: 5px;
|
||||
|
||||
@@ -47,6 +47,9 @@ export default Vue.extend({
|
||||
return false;
|
||||
},
|
||||
},
|
||||
mounted () {
|
||||
this.tempValue = this.value as string;
|
||||
},
|
||||
watch: {
|
||||
dialogVisible () {
|
||||
if (this.dialogVisible === true) {
|
||||
|
||||
@@ -252,6 +252,21 @@ export const restApi = Vue.extend({
|
||||
return self.restApi().makeRestApiRequest('GET', `/credential-types`);
|
||||
},
|
||||
|
||||
// Get OAuth2 Authorization URL using the stored credentials
|
||||
OAuth2CredentialAuthorize: (sendData: ICredentialsResponse): Promise<string> => {
|
||||
return self.restApi().makeRestApiRequest('GET', `/oauth2-credential/auth`, sendData);
|
||||
},
|
||||
|
||||
// Verify OAuth2 provider callback and kick off token generation
|
||||
OAuth2Callback: (code: string, state: string): Promise<string> => {
|
||||
const sendData = {
|
||||
'code': code,
|
||||
'state': state,
|
||||
};
|
||||
|
||||
return self.restApi().makeRestApiRequest('POST', `/oauth2-credential/callback`, sendData);
|
||||
},
|
||||
|
||||
// Returns the execution with the given name
|
||||
getExecution: async (id: string): Promise<IExecutionResponse> => {
|
||||
const response = await self.restApi().makeRestApiRequest('GET', `/executions/${id}`);
|
||||
|
||||
@@ -19,6 +19,12 @@ export default new Router({
|
||||
sidebar: MainSidebar,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/oauth2/callback',
|
||||
name: 'OAuth2Callback',
|
||||
components: {
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/workflow',
|
||||
name: 'NodeViewNew',
|
||||
|
||||
@@ -12,6 +12,7 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
configureWebpack: {
|
||||
devtool: 'source-map',
|
||||
plugins: [
|
||||
new GoogleFontsPlugin({
|
||||
fonts: [
|
||||
|
||||
19
packages/nodes-base/credentials/Msg91Api.credentials.ts
Normal file
19
packages/nodes-base/credentials/Msg91Api.credentials.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
ICredentialType,
|
||||
NodePropertyTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
|
||||
export class Msg91Api implements ICredentialType {
|
||||
name = 'msg91Api';
|
||||
displayName = 'Msg91 Api';
|
||||
properties = [
|
||||
// User authentication key
|
||||
{
|
||||
displayName: 'Authentication Key',
|
||||
name: 'authkey',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
},
|
||||
];
|
||||
}
|
||||
56
packages/nodes-base/credentials/OAuth2Api.credentials.ts
Normal file
56
packages/nodes-base/credentials/OAuth2Api.credentials.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
ICredentialType,
|
||||
NodePropertyTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
|
||||
export class OAuth2Api implements ICredentialType {
|
||||
name = 'OAuth2Api';
|
||||
displayName = 'OAuth2 API';
|
||||
properties = [
|
||||
{
|
||||
displayName: 'Authorization URL',
|
||||
name: 'authUrl',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Access Token URL',
|
||||
name: 'accessTokenUrl',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Callback URL',
|
||||
name: 'callbackUrl',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Client ID',
|
||||
name: 'clientId',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Client Secret',
|
||||
name: 'clientSecret',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
typeOptions: {
|
||||
password: true,
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Scope',
|
||||
name: 'scope',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
},
|
||||
];
|
||||
}
|
||||
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: '',
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -85,6 +85,16 @@ export class Mattermost implements INodeType {
|
||||
value: 'create',
|
||||
description: 'Create a new channel',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Soft-deletes a channel',
|
||||
},
|
||||
{
|
||||
name: 'Restore',
|
||||
value: 'restore',
|
||||
description: 'Restores a soft-deleted channel',
|
||||
},
|
||||
{
|
||||
name: 'Statistics',
|
||||
value: 'statistics',
|
||||
@@ -219,6 +229,56 @@ export class Mattermost implements INodeType {
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// channel:delete
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Channel ID',
|
||||
name: 'channelId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getChannels',
|
||||
},
|
||||
options: [],
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'delete'
|
||||
],
|
||||
resource: [
|
||||
'channel',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The ID of the channel to soft-delete.',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// channel:restore
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Channel ID',
|
||||
name: 'channelId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'restore'
|
||||
],
|
||||
resource: [
|
||||
'channel',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The ID of the channel to restore.',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// channel:addUser
|
||||
// ----------------------------------
|
||||
@@ -266,6 +326,8 @@ export class Mattermost implements INodeType {
|
||||
},
|
||||
description: 'The ID of the user to invite into channel.',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// channel:statistics
|
||||
// ----------------------------------
|
||||
@@ -629,8 +691,7 @@ export class Mattermost implements INodeType {
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
// Get all the available workspaces to display them to user so that he can
|
||||
// select them easily
|
||||
// Get all the available channels
|
||||
async getChannels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const endpoint = 'channels';
|
||||
const responseData = await apiRequest.call(this, 'GET', endpoint, {});
|
||||
@@ -754,6 +815,24 @@ export class Mattermost implements INodeType {
|
||||
const type = this.getNodeParameter('type', i) as string;
|
||||
body.type = type === 'public' ? 'O' : 'P';
|
||||
|
||||
} else if (operation === 'delete') {
|
||||
// ----------------------------------
|
||||
// channel:delete
|
||||
// ----------------------------------
|
||||
|
||||
requestMethod = 'DELETE';
|
||||
const channelId = this.getNodeParameter('channelId', i) as string;
|
||||
endpoint = `channels/${channelId}`;
|
||||
|
||||
} else if (operation === 'restore') {
|
||||
// ----------------------------------
|
||||
// channel:restore
|
||||
// ----------------------------------
|
||||
|
||||
requestMethod = 'POST';
|
||||
const channelId = this.getNodeParameter('channelId', i) as string;
|
||||
endpoint = `channels/${channelId}/restore`;
|
||||
|
||||
} else if (operation === 'addUser') {
|
||||
// ----------------------------------
|
||||
// channel:addUser
|
||||
|
||||
60
packages/nodes-base/nodes/Msg91/GenericFunctions.ts
Normal file
60
packages/nodes-base/nodes/Msg91/GenericFunctions.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
/**
|
||||
* Make an API request to MSG91
|
||||
*
|
||||
* @param {IHookFunctions} this
|
||||
* @param {string} method
|
||||
* @param {string} url
|
||||
* @param {object} body
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export async function msg91ApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('msg91Api');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
if (query === undefined) {
|
||||
query = {};
|
||||
}
|
||||
|
||||
query.authkey = credentials.authkey as string;
|
||||
|
||||
const options = {
|
||||
method,
|
||||
form: body,
|
||||
qs: query,
|
||||
uri: `https://api.msg91.com/api${endpoint}`,
|
||||
json: true
|
||||
};
|
||||
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
if (error.statusCode === 401) {
|
||||
// Return a clear error
|
||||
throw new Error('The MSG91 credentials are not valid!');
|
||||
}
|
||||
|
||||
if (error.response && error.response.body && error.response.body.message) {
|
||||
// Try to return the error prettier
|
||||
let errorMessage = `MSG91 error response [${error.statusCode}]: ${error.response.body.message}`;
|
||||
if (error.response.body.more_info) {
|
||||
errorMessage = `errorMessage (${error.response.body.more_info})`;
|
||||
}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
// If that data does not exist for some reason return the actual error
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
184
packages/nodes-base/nodes/Msg91/Msg91.node.ts
Normal file
184
packages/nodes-base/nodes/Msg91/Msg91.node.ts
Normal file
@@ -0,0 +1,184 @@
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
msg91ApiRequest,
|
||||
} from './GenericFunctions';
|
||||
|
||||
|
||||
export class Msg91 implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Msg91',
|
||||
name: 'msg91',
|
||||
icon: 'file:msg91.png',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Send Transactional SMS',
|
||||
defaults: {
|
||||
name: 'Msg91',
|
||||
color: '#0000ff',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'msg91Api',
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'SMS',
|
||||
value: 'sms',
|
||||
},
|
||||
],
|
||||
default: 'sms',
|
||||
description: 'The resource to operate on.',
|
||||
},
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'sms',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Send',
|
||||
value: 'send',
|
||||
description: 'Send SMS',
|
||||
},
|
||||
],
|
||||
default: 'send',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
{
|
||||
displayName: 'From',
|
||||
name: 'from',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '4155238886',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'send',
|
||||
],
|
||||
resource: [
|
||||
'sms',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The number from which to send the message.',
|
||||
},
|
||||
{
|
||||
displayName: 'To',
|
||||
name: 'to',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '+14155238886',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'send',
|
||||
],
|
||||
resource: [
|
||||
'sms',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The number, with coutry code, to which to send the message.',
|
||||
},
|
||||
{
|
||||
displayName: 'Message',
|
||||
name: 'message',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'send',
|
||||
],
|
||||
resource: [
|
||||
'sms',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The message to send',
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let operation: string;
|
||||
let resource: string;
|
||||
|
||||
// For Post
|
||||
let body: IDataObject;
|
||||
// For Query string
|
||||
let qs: IDataObject;
|
||||
|
||||
let requestMethod: string;
|
||||
let endpoint: string;
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
endpoint = '';
|
||||
body = {};
|
||||
qs = {};
|
||||
|
||||
resource = this.getNodeParameter('resource', i) as string;
|
||||
operation = this.getNodeParameter('operation', i) as string;
|
||||
|
||||
if (resource === 'sms') {
|
||||
if (operation === 'send') {
|
||||
// ----------------------------------
|
||||
// sms:send
|
||||
// ----------------------------------
|
||||
|
||||
requestMethod = 'GET';
|
||||
endpoint = '/sendhttp.php';
|
||||
|
||||
qs.route = 4;
|
||||
qs.country = 0;
|
||||
qs.sender = this.getNodeParameter('from', i) as string;
|
||||
qs.mobiles = this.getNodeParameter('to', i) as string;
|
||||
qs.message = this.getNodeParameter('message', i) as string;
|
||||
|
||||
} else {
|
||||
throw new Error(`The operation "${operation}" is not known!`);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`The resource "${resource}" is not known!`);
|
||||
}
|
||||
|
||||
const responseData = await msg91ApiRequest.call(this, requestMethod, endpoint, body, qs);
|
||||
|
||||
returnData.push({ requestId: responseData });
|
||||
}
|
||||
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
|
||||
}
|
||||
}
|
||||
BIN
packages/nodes-base/nodes/Msg91/msg91.png
Normal file
BIN
packages/nodes-base/nodes/Msg91/msg91.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
104
packages/nodes-base/nodes/OAuth.node.ts
Normal file
104
packages/nodes-base/nodes/OAuth.node.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
GenericValue,
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { set } from 'lodash';
|
||||
|
||||
import * as util from 'util';
|
||||
import { connectionFields } from './ActiveCampaign/ConnectionDescription';
|
||||
|
||||
export class OAuth implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'OAuth',
|
||||
name: 'oauth',
|
||||
icon: 'fa:code-branch',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
description: 'Gets, sends data to Oauth API Endpoint and receives generic information.',
|
||||
defaults: {
|
||||
name: 'OAuth',
|
||||
color: '#0033AA',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'OAuth2Api',
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Returns the value of a key from oauth.',
|
||||
},
|
||||
],
|
||||
default: 'get',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// get
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'propertyName',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'get'
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 'propertyName',
|
||||
required: true,
|
||||
description: 'Name of the property to write received data to.<br />Supports dot-notation.<br />Example: "data.person[0].name"',
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const credentials = this.getCredentials('OAuth2Api');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
if (credentials.oauthTokenData === undefined) {
|
||||
throw new Error('OAuth credentials not connected');
|
||||
}
|
||||
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
if (operation === 'get') {
|
||||
const items = this.getInputData();
|
||||
const returnItems: INodeExecutionData[] = [];
|
||||
|
||||
let item: INodeExecutionData;
|
||||
|
||||
// credentials.oauthTokenData has the refreshToken and accessToken available
|
||||
// it would be nice to have credentials.getOAuthToken() which returns the accessToken
|
||||
// and also handles an error case where if the token is to be refreshed, it does so
|
||||
// without knowledge of the node.
|
||||
console.log('Got OAuth credentials!', credentials.oauthTokenData);
|
||||
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
item = { json: { itemIndex } };
|
||||
returnItems.push(item);
|
||||
}
|
||||
return [returnItems];
|
||||
} else {
|
||||
throw new Error('Unknown operation');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,6 +250,42 @@ export class Redis implements INodeType {
|
||||
default: 'automatic',
|
||||
description: 'The type of the key to set.',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'Expire',
|
||||
name: 'expire',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'set'
|
||||
],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Set a timeout on key ?',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'TTL',
|
||||
name: 'ttl',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'set'
|
||||
],
|
||||
expire: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 60,
|
||||
description: 'Number of seconds before key expiration.',
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
@@ -319,7 +355,7 @@ export class Redis implements INodeType {
|
||||
}
|
||||
|
||||
|
||||
async function setValue(client: redis.RedisClient, keyName: string, value: string | number | object | string[] | number[], type?: string) {
|
||||
async function setValue(client: redis.RedisClient, keyName: string, value: string | number | object | string[] | number[], expire: boolean, ttl: number, type?: string) {
|
||||
if (type === undefined || type === 'automatic') {
|
||||
// Request the type first
|
||||
if (typeof value === 'string') {
|
||||
@@ -335,20 +371,24 @@ export class Redis implements INodeType {
|
||||
|
||||
if (type === 'string') {
|
||||
const clientSet = util.promisify(client.set).bind(client);
|
||||
return await clientSet(keyName, value.toString());
|
||||
await clientSet(keyName, value.toString());
|
||||
} else if (type === 'hash') {
|
||||
const clientHset = util.promisify(client.hset).bind(client);
|
||||
for (const key of Object.keys(value)) {
|
||||
await clientHset(keyName, key, (value as IDataObject)[key]!.toString());
|
||||
}
|
||||
return;
|
||||
} else if (type === 'list') {
|
||||
const clientLset = util.promisify(client.lset).bind(client);
|
||||
for (let index = 0; index < (value as string[]).length; index++) {
|
||||
await clientLset(keyName, index, (value as IDataObject)[index]!.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (expire === true) {
|
||||
const clientExpire = util.promisify(client.expire).bind(client);
|
||||
await clientExpire(keyName, ttl);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -434,8 +474,10 @@ export class Redis implements INodeType {
|
||||
const keySet = this.getNodeParameter('key', itemIndex) as string;
|
||||
const value = this.getNodeParameter('value', itemIndex) as string;
|
||||
const keyType = this.getNodeParameter('keyType', itemIndex) as string;
|
||||
const expire = this.getNodeParameter('expire', itemIndex, false) as boolean;
|
||||
const ttl = this.getNodeParameter('ttl', itemIndex, -1) as number;
|
||||
|
||||
await setValue(client, keySet, value, keyType);
|
||||
await setValue(client, keySet, value, expire, ttl, keyType);
|
||||
returnItems.push(items[itemIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,12 @@ export async function rocketchatApiRequest(this: IHookFunctions | IExecuteFuncti
|
||||
headers: headerWithAuthentication,
|
||||
method,
|
||||
body,
|
||||
uri: `${credentials.domain}${resource}.${operation}`,
|
||||
uri: `${credentials.domain}/api/v1${resource}.${operation}`,
|
||||
json: true
|
||||
};
|
||||
|
||||
if (Object.keys(options.body).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
|
||||
334
packages/nodes-base/nodes/Zendesk/ConditionDescription.ts
Normal file
334
packages/nodes-base/nodes/Zendesk/ConditionDescription.ts
Normal file
@@ -0,0 +1,334 @@
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const conditionFields = [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Ticket',
|
||||
value: 'ticket',
|
||||
},
|
||||
],
|
||||
default: 'ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Field',
|
||||
name: 'field',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'resource': [
|
||||
'ticket'
|
||||
]
|
||||
}
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Status',
|
||||
value: 'status',
|
||||
},
|
||||
{
|
||||
name: 'Type',
|
||||
value: 'type',
|
||||
},
|
||||
{
|
||||
name: 'Priority',
|
||||
value: 'priority',
|
||||
},
|
||||
{
|
||||
name: 'Group',
|
||||
value: 'group',
|
||||
},
|
||||
{
|
||||
name: 'Assignee',
|
||||
value: 'assignee',
|
||||
},
|
||||
],
|
||||
default: 'status',
|
||||
},
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Is',
|
||||
value: 'is',
|
||||
},
|
||||
{
|
||||
name: 'Is Not',
|
||||
value: 'is_not',
|
||||
},
|
||||
{
|
||||
name: 'Less Than',
|
||||
value: 'less_than',
|
||||
},
|
||||
{
|
||||
name: 'Greater Than',
|
||||
value: 'greater_than',
|
||||
},
|
||||
{
|
||||
name: 'Changed',
|
||||
value: 'changed',
|
||||
},
|
||||
{
|
||||
name: 'Changed To',
|
||||
value: 'value',
|
||||
},
|
||||
{
|
||||
name: 'Changed From',
|
||||
value: 'value_previous',
|
||||
},
|
||||
{
|
||||
name: 'Not Changed',
|
||||
value: 'not_changed',
|
||||
},
|
||||
{
|
||||
name: 'Not Changed To',
|
||||
value: 'not_value',
|
||||
},
|
||||
{
|
||||
name: 'Not Changed From',
|
||||
value: 'not_value_previous',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
hide: {
|
||||
field: [
|
||||
'assignee',
|
||||
]
|
||||
}
|
||||
},
|
||||
default: 'is',
|
||||
},
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Is',
|
||||
value: 'is',
|
||||
},
|
||||
{
|
||||
name: 'Is Not',
|
||||
value: 'is_not',
|
||||
},
|
||||
{
|
||||
name: 'Changed',
|
||||
value: 'changed',
|
||||
},
|
||||
{
|
||||
name: 'Changed To',
|
||||
value: 'value',
|
||||
},
|
||||
{
|
||||
name: 'Changed From',
|
||||
value: 'value_previous',
|
||||
},
|
||||
{
|
||||
name: 'Not Changed',
|
||||
value: 'not_changed',
|
||||
},
|
||||
{
|
||||
name: 'Not Changed To',
|
||||
value: 'not_value',
|
||||
},
|
||||
{
|
||||
name: 'Not Changed From',
|
||||
value: 'not_value_previous',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
field: [
|
||||
'assignee',
|
||||
]
|
||||
}
|
||||
},
|
||||
default: 'is',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
field: [
|
||||
'status'
|
||||
],
|
||||
},
|
||||
hide: {
|
||||
operation:[
|
||||
'changed',
|
||||
'not_changed',
|
||||
],
|
||||
field: [
|
||||
'assignee',
|
||||
'group',
|
||||
'priority',
|
||||
'type',
|
||||
],
|
||||
}
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Open',
|
||||
value: 'open',
|
||||
},
|
||||
{
|
||||
name: 'New',
|
||||
value: 'new',
|
||||
},
|
||||
{
|
||||
name: 'Pending',
|
||||
value: 'pending',
|
||||
},
|
||||
{
|
||||
name: 'Solved',
|
||||
value: 'solved',
|
||||
},
|
||||
{
|
||||
name: 'Closed',
|
||||
value: 'closed',
|
||||
},
|
||||
],
|
||||
default: 'open',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
field: [
|
||||
'type'
|
||||
],
|
||||
},
|
||||
hide: {
|
||||
operation:[
|
||||
'changed',
|
||||
'not_changed',
|
||||
],
|
||||
field: [
|
||||
'assignee',
|
||||
'group',
|
||||
'priority',
|
||||
'status',
|
||||
],
|
||||
}
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Question',
|
||||
value: 'question',
|
||||
},
|
||||
{
|
||||
name: 'Incident',
|
||||
value: 'incident',
|
||||
},
|
||||
{
|
||||
name: 'Problem',
|
||||
value: 'problem',
|
||||
},
|
||||
{
|
||||
name: 'Task',
|
||||
value: 'task',
|
||||
},
|
||||
],
|
||||
default: 'question',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
field: [
|
||||
'priority'
|
||||
],
|
||||
},
|
||||
hide: {
|
||||
operation:[
|
||||
'changed',
|
||||
'not_changed',
|
||||
],
|
||||
field: [
|
||||
'assignee',
|
||||
'group',
|
||||
'type',
|
||||
'status',
|
||||
],
|
||||
}
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Low',
|
||||
value: 'low',
|
||||
},
|
||||
{
|
||||
name: 'Normal',
|
||||
value: 'normal',
|
||||
},
|
||||
{
|
||||
name: 'High',
|
||||
value: 'high',
|
||||
},
|
||||
{
|
||||
name: 'Urgent',
|
||||
value: 'urgent',
|
||||
},
|
||||
],
|
||||
default: 'low',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getGroups',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
field: [
|
||||
'group'
|
||||
],
|
||||
},
|
||||
hide: {
|
||||
field: [
|
||||
'assignee',
|
||||
'priority',
|
||||
'type',
|
||||
'status',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getUsers',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
field: [
|
||||
'assignee'
|
||||
],
|
||||
},
|
||||
hide: {
|
||||
field: [
|
||||
'group',
|
||||
'priority',
|
||||
'type',
|
||||
'status',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
57
packages/nodes-base/nodes/Zendesk/GenericFunctions.ts
Normal file
57
packages/nodes-base/nodes/Zendesk/GenericFunctions.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { OptionsWithUri } from 'request';
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} 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.url}/api/v2${resource}.json`,
|
||||
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 (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
uri = responseData.next_page;
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
} while (
|
||||
responseData.next_page !== undefined &&
|
||||
responseData.next_page !== null
|
||||
);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
503
packages/nodes-base/nodes/Zendesk/TicketDescription.ts
Normal file
503
packages/nodes-base/nodes/Zendesk/TicketDescription.ts
Normal file
@@ -0,0 +1,503 @@
|
||||
import { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const ticketOperations = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a ticket',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a ticket',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a ticket',
|
||||
},
|
||||
{
|
||||
name: 'Get All',
|
||||
value: 'getAll',
|
||||
description: 'Get all tickets',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a ticket',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
description: 'The operation to perform.',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
||||
export const ticketFields = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ticket:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Description',
|
||||
name: 'description',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'The first comment on the ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'External ID',
|
||||
name: 'externalId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'An id you can use to link Zendesk Support tickets to local records',
|
||||
},
|
||||
{
|
||||
displayName: 'Subject',
|
||||
name: 'subject',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The value of the subject field for this ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Recipient',
|
||||
name: 'recipient',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The original recipient e-mail address of the ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Group',
|
||||
name: 'group',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getGroups',
|
||||
},
|
||||
default: '',
|
||||
description: 'The group this ticket is assigned to',
|
||||
},
|
||||
{
|
||||
displayName: 'Tags',
|
||||
name: 'tags',
|
||||
type: 'multiOptions',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTags',
|
||||
},
|
||||
default: [],
|
||||
description: 'The array of tags applied to this ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Question',
|
||||
value: 'question',
|
||||
},
|
||||
{
|
||||
name: 'Incident',
|
||||
value: 'incident',
|
||||
},
|
||||
{
|
||||
name: 'Problem',
|
||||
value: 'problem',
|
||||
},
|
||||
{
|
||||
name: 'Task',
|
||||
value: 'task',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
description: 'The type of this ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Status',
|
||||
name: 'status',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Open',
|
||||
value: 'open',
|
||||
},
|
||||
{
|
||||
name: 'New',
|
||||
value: 'new',
|
||||
},
|
||||
{
|
||||
name: 'Pending',
|
||||
value: 'pending',
|
||||
},
|
||||
{
|
||||
name: 'Solved',
|
||||
value: 'solved',
|
||||
},
|
||||
{
|
||||
name: 'Closed',
|
||||
value: 'closed',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
description: 'The state of the ticket',
|
||||
}
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ticket:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'Ticket ID',
|
||||
},
|
||||
{
|
||||
displayName: 'Update Fields',
|
||||
name: 'updateFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'External ID',
|
||||
name: 'externalId',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'An id you can use to link Zendesk Support tickets to local records',
|
||||
},
|
||||
{
|
||||
displayName: 'Subject',
|
||||
name: 'subject',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The value of the subject field for this ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Recipient',
|
||||
name: 'recipient',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The original recipient e-mail address of the ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Group',
|
||||
name: 'group',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getGroups',
|
||||
},
|
||||
default: '',
|
||||
description: 'The group this ticket is assigned to',
|
||||
},
|
||||
{
|
||||
displayName: 'Tags',
|
||||
name: 'tags',
|
||||
type: 'multiOptions',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getTags',
|
||||
},
|
||||
default: [],
|
||||
description: 'The array of tags applied to this ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Question',
|
||||
value: 'question',
|
||||
},
|
||||
{
|
||||
name: 'Incident',
|
||||
value: 'incident',
|
||||
},
|
||||
{
|
||||
name: 'Problem',
|
||||
value: 'problem',
|
||||
},
|
||||
{
|
||||
name: 'Task',
|
||||
value: 'task',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
description: 'The type of this ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Status',
|
||||
name: 'status',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Open',
|
||||
value: 'open',
|
||||
},
|
||||
{
|
||||
name: 'New',
|
||||
value: 'new',
|
||||
},
|
||||
{
|
||||
name: 'Pending',
|
||||
value: 'pending',
|
||||
},
|
||||
{
|
||||
name: 'Solved',
|
||||
value: 'solved',
|
||||
},
|
||||
{
|
||||
name: 'Closed',
|
||||
value: 'closed',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
description: 'The state of the ticket',
|
||||
}
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ticket:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'Ticket ID',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ticket:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'If all results should be returned or only up to a given limit.',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 100,
|
||||
},
|
||||
default: 100,
|
||||
description: 'How many results to return.',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Status',
|
||||
name: 'status',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Open',
|
||||
value: 'open',
|
||||
},
|
||||
{
|
||||
name: 'New',
|
||||
value: 'new',
|
||||
},
|
||||
{
|
||||
name: 'Pending',
|
||||
value: 'pending',
|
||||
},
|
||||
{
|
||||
name: 'Solved',
|
||||
value: 'solved',
|
||||
},
|
||||
{
|
||||
name: 'Closed',
|
||||
value: 'closed',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
description: 'The state of the ticket',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort By',
|
||||
name: 'sortBy',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Updated At',
|
||||
value: 'updated_at',
|
||||
},
|
||||
{
|
||||
name: 'Created At',
|
||||
value: 'created_at',
|
||||
},
|
||||
{
|
||||
name: 'Priority',
|
||||
value: 'priority',
|
||||
},
|
||||
{
|
||||
name: 'Status',
|
||||
value: 'status',
|
||||
},
|
||||
{
|
||||
name: 'Ticket Type',
|
||||
value: 'ticket_type',
|
||||
},
|
||||
],
|
||||
default: 'updated_at',
|
||||
description: 'Defaults to sorting by relevance',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort Order',
|
||||
name: 'sortOrder',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Asc',
|
||||
value: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'Desc',
|
||||
value: 'desc',
|
||||
},
|
||||
],
|
||||
default: 'desc',
|
||||
description: 'Sort order',
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ticket:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'ticket',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'Ticket ID',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
14
packages/nodes-base/nodes/Zendesk/TicketInterface.ts
Normal file
14
packages/nodes-base/nodes/Zendesk/TicketInterface.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export interface ITicket {
|
||||
subject?: string;
|
||||
comment?: IComment;
|
||||
type?: string;
|
||||
group?: string;
|
||||
external_id?: string;
|
||||
tags?: string[];
|
||||
status?: string;
|
||||
recipient?: string;
|
||||
}
|
||||
|
||||
export interface IComment {
|
||||
body?: string;
|
||||
}
|
||||
238
packages/nodes-base/nodes/Zendesk/Zendesk.node.ts
Normal file
238
packages/nodes-base/nodes/Zendesk/Zendesk.node.ts
Normal file
@@ -0,0 +1,238 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import {
|
||||
IDataObject,
|
||||
INodeTypeDescription,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
ILoadOptionsFunctions,
|
||||
INodePropertyOptions,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
zendeskApiRequest,
|
||||
zendeskApiRequestAllItems,
|
||||
} from './GenericFunctions';
|
||||
import {
|
||||
ticketFields,
|
||||
ticketOperations
|
||||
} from './TicketDescription';
|
||||
import {
|
||||
ITicket,
|
||||
IComment,
|
||||
} from './TicketInterface';
|
||||
|
||||
export class Zendesk implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Zendesk',
|
||||
name: 'zendesk',
|
||||
icon: 'file:zendesk.png',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Zendesk API',
|
||||
defaults: {
|
||||
name: 'Zendesk',
|
||||
color: '#13353c',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'zendeskApi',
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Ticket',
|
||||
value: 'ticket',
|
||||
description: 'Tickets are the means through which your end users (customers) communicate with agents in Zendesk Support.',
|
||||
},
|
||||
],
|
||||
default: 'ticket',
|
||||
description: 'Resource to consume.',
|
||||
},
|
||||
...ticketOperations,
|
||||
...ticketFields,
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
// Get all the groups to display them to user so that he can
|
||||
// select them easily
|
||||
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const groups = await zendeskApiRequestAllItems.call(this, 'groups', 'GET', '/groups');
|
||||
for (const group of groups) {
|
||||
const groupName = group.name;
|
||||
const groupId = group.id;
|
||||
returnData.push({
|
||||
name: groupName,
|
||||
value: groupId,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the tags to display them to user so that he can
|
||||
// select them easily
|
||||
async getTags(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const tags = await zendeskApiRequestAllItems.call(this, 'tags', 'GET', '/tags');
|
||||
for (const tag of tags) {
|
||||
const tagName = tag.name;
|
||||
const tagId = tag.name;
|
||||
returnData.push({
|
||||
name: tagName,
|
||||
value: tagId,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length as unknown as number;
|
||||
const qs: IDataObject = {};
|
||||
let responseData;
|
||||
for (let i = 0; i < length; i++) {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
//https://developer.zendesk.com/rest_api/docs/support/introduction
|
||||
if (resource === 'ticket') {
|
||||
//https://developer.zendesk.com/rest_api/docs/support/tickets
|
||||
if (operation === 'create') {
|
||||
const description = this.getNodeParameter('description', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
const comment: IComment = {
|
||||
body: description,
|
||||
};
|
||||
const body: ITicket = {
|
||||
comment,
|
||||
};
|
||||
if (additionalFields.type) {
|
||||
body.type = additionalFields.type as string;
|
||||
}
|
||||
if (additionalFields.externalId) {
|
||||
body.external_id = additionalFields.externalId as string;
|
||||
}
|
||||
if (additionalFields.subject) {
|
||||
body.subject = additionalFields.subject as string;
|
||||
}
|
||||
if (additionalFields.status) {
|
||||
body.status = additionalFields.status as string;
|
||||
}
|
||||
if (additionalFields.recipient) {
|
||||
body.recipient = additionalFields.recipient as string;
|
||||
}
|
||||
if (additionalFields.group) {
|
||||
body.group = additionalFields.group as string;
|
||||
}
|
||||
if (additionalFields.tags) {
|
||||
body.tags = additionalFields.tags as string[];
|
||||
}
|
||||
try {
|
||||
responseData = await zendeskApiRequest.call(this, 'POST', '/tickets', { ticket: body });
|
||||
responseData = responseData.ticket;
|
||||
} catch (err) {
|
||||
throw new Error(`Zendesk Error: ${err}`);
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/tickets#update-ticket
|
||||
if (operation === 'update') {
|
||||
const ticketId = this.getNodeParameter('id', i) as string;
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
const body: ITicket = {};
|
||||
if (updateFields.type) {
|
||||
body.type = updateFields.type as string;
|
||||
}
|
||||
if (updateFields.externalId) {
|
||||
body.external_id = updateFields.externalId as string;
|
||||
}
|
||||
if (updateFields.subject) {
|
||||
body.subject = updateFields.subject as string;
|
||||
}
|
||||
if (updateFields.status) {
|
||||
body.status = updateFields.status as string;
|
||||
}
|
||||
if (updateFields.recipient) {
|
||||
body.recipient = updateFields.recipient as string;
|
||||
}
|
||||
if (updateFields.group) {
|
||||
body.group = updateFields.group as string;
|
||||
}
|
||||
if (updateFields.tags) {
|
||||
body.tags = updateFields.tags as string[];
|
||||
}
|
||||
try {
|
||||
responseData = await zendeskApiRequest.call(this, 'PUT', `/tickets/${ticketId}`, { ticket: body });
|
||||
responseData = responseData.ticket;
|
||||
} catch (err) {
|
||||
throw new Error(`Zendesk Error: ${err}`);
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/tickets#show-ticket
|
||||
if (operation === 'get') {
|
||||
const ticketId = this.getNodeParameter('id', i) as string;
|
||||
try {
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/tickets/${ticketId}`, {});
|
||||
responseData = responseData.ticket;
|
||||
} catch (err) {
|
||||
throw new Error(`Zendesk Error: ${err}`);
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/search#list-search-results
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
qs.query = 'type:ticket';
|
||||
if (options.status) {
|
||||
qs.query += ` status:${options.status}`;
|
||||
}
|
||||
if (options.sortBy) {
|
||||
qs.sort_by = options.sortBy;
|
||||
}
|
||||
if (options.sortOrder) {
|
||||
qs.sort_order = options.sortOrder;
|
||||
}
|
||||
try {
|
||||
if (returnAll) {
|
||||
responseData = await zendeskApiRequestAllItems.call(this, 'results', 'GET', `/search`, {}, qs);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
qs.per_page = limit;
|
||||
responseData = await zendeskApiRequest.call(this, 'GET', `/search`, {}, qs);
|
||||
responseData = responseData.results;
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`Zendesk Error: ${err}`);
|
||||
}
|
||||
}
|
||||
//https://developer.zendesk.com/rest_api/docs/support/tickets#delete-ticket
|
||||
if (operation === 'delete') {
|
||||
const ticketId = this.getNodeParameter('id', i) as string;
|
||||
try {
|
||||
responseData = await zendeskApiRequest.call(this, 'DELETE', `/tickets/${ticketId}`, {});
|
||||
} catch (err) {
|
||||
throw new Error(`Zendesk Error: ${err}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
}
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
523
packages/nodes-base/nodes/Zendesk/ZendeskTrigger.node.ts
Normal file
523
packages/nodes-base/nodes/Zendesk/ZendeskTrigger.node.ts
Normal file
@@ -0,0 +1,523 @@
|
||||
import {
|
||||
parse as urlParse,
|
||||
} from 'url';
|
||||
|
||||
import {
|
||||
IHookFunctions,
|
||||
IWebhookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
INodeTypeDescription,
|
||||
INodeType,
|
||||
IWebhookResponseData,
|
||||
IDataObject,
|
||||
INodePropertyOptions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
zendeskApiRequest,
|
||||
zendeskApiRequestAllItems,
|
||||
} from './GenericFunctions';
|
||||
import {
|
||||
conditionFields
|
||||
} from './ConditionDescription';
|
||||
|
||||
export class ZendeskTrigger implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Zendesk Trigger',
|
||||
name: 'zendeskTrigger',
|
||||
icon: 'file:zendesk.png',
|
||||
group: ['trigger'],
|
||||
version: 1,
|
||||
description: 'Handle Zendesk events via webhooks',
|
||||
defaults: {
|
||||
name: 'Zendesk Trigger',
|
||||
color: '#13353c',
|
||||
},
|
||||
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: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
service: [
|
||||
'support'
|
||||
],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Fields',
|
||||
name: 'fields',
|
||||
description: 'The fields to return the values of.',
|
||||
type: 'multiOptions',
|
||||
default: [],
|
||||
options: [
|
||||
{
|
||||
name: 'Title',
|
||||
value: 'ticket.title',
|
||||
description: `Ticket's subject`,
|
||||
},
|
||||
{
|
||||
name: 'Description',
|
||||
value: 'ticket.description',
|
||||
description: `Ticket's description`,
|
||||
},
|
||||
{
|
||||
name: 'URL',
|
||||
value: 'ticket.url',
|
||||
description: `Ticket's URL`,
|
||||
},
|
||||
{
|
||||
name: 'ID',
|
||||
value: 'ticket.id',
|
||||
description: `Ticket's ID`,
|
||||
},
|
||||
{
|
||||
name: 'External ID',
|
||||
value: 'ticket.external_id',
|
||||
description: `Ticket's external ID`,
|
||||
},
|
||||
{
|
||||
name: 'Via',
|
||||
value: 'ticket.via',
|
||||
description: `Ticket's source`
|
||||
},
|
||||
{
|
||||
name: 'Status',
|
||||
value: 'ticket.status',
|
||||
description: `Ticket's status`,
|
||||
},
|
||||
{
|
||||
name: 'Priority',
|
||||
value: 'ticket.priority',
|
||||
description: `Ticket's priority`,
|
||||
},
|
||||
{
|
||||
name: 'Type',
|
||||
value: 'ticket.ticket_type',
|
||||
description: `Ticket's type`,
|
||||
},
|
||||
{
|
||||
name: 'Group Name',
|
||||
value: 'ticket.group.name',
|
||||
description: `Ticket's assigned group`,
|
||||
},
|
||||
{
|
||||
name: 'Brand Name',
|
||||
value: 'ticket.brand.name',
|
||||
description: `Ticket's brand`,
|
||||
},
|
||||
{
|
||||
name: 'Due Date',
|
||||
value: 'ticket.due_date',
|
||||
description: `Ticket's due date (relevant for tickets of type Task)`,
|
||||
},
|
||||
{
|
||||
name: 'Account',
|
||||
value: 'ticket.account',
|
||||
description: `This Zendesk Support's account name`,
|
||||
},
|
||||
{
|
||||
name: 'Assignee Email',
|
||||
value: 'ticket.assignee.email',
|
||||
description: `Ticket assignee email (if any)`,
|
||||
},
|
||||
{
|
||||
name: 'Assignee Name',
|
||||
value: 'ticket.assignee.name',
|
||||
description: `Assignee's full name`,
|
||||
},
|
||||
{
|
||||
name: 'Assignee First Name',
|
||||
value: 'ticket.assignee.first_name',
|
||||
description: `Assignee's first name`,
|
||||
},
|
||||
{
|
||||
name: 'Assignee Last Name',
|
||||
value: 'ticket.assignee.last_name',
|
||||
description: `Assignee's last name`,
|
||||
},
|
||||
{
|
||||
name: 'Requester Full Name',
|
||||
value: 'ticket.requester.name',
|
||||
description: `Requester's full name`,
|
||||
},
|
||||
{
|
||||
name: 'Requester First Name',
|
||||
value: 'ticket.requester.first_name',
|
||||
description: `Requester's first name`,
|
||||
},
|
||||
{
|
||||
name: 'Requester Last Name',
|
||||
value: 'ticket.requester.last_name',
|
||||
description: `Requester's last name`,
|
||||
},
|
||||
{
|
||||
name: 'Requester Email',
|
||||
value: 'ticket.requester.email',
|
||||
description: `Requester's email`,
|
||||
},
|
||||
{
|
||||
name: 'Requester Language',
|
||||
value: 'ticket.requester.language',
|
||||
description: `Requester's language`,
|
||||
},
|
||||
{
|
||||
name: 'Requester Phone',
|
||||
value: 'ticket.requester.phone',
|
||||
description: `Requester's phone number`,
|
||||
},
|
||||
{
|
||||
name: 'Requester External ID',
|
||||
value: 'ticket.requester.external_id',
|
||||
description: `Requester's external ID`,
|
||||
},
|
||||
{
|
||||
name: 'Requester Field',
|
||||
value: 'ticket.requester.requester_field',
|
||||
description: `Name or email`,
|
||||
},
|
||||
{
|
||||
name: 'Requester Details',
|
||||
value: 'ticket.requester.details',
|
||||
description: `Detailed information about the ticket's requester`,
|
||||
},
|
||||
{
|
||||
name: 'Requester Organization',
|
||||
value: 'ticket.organization.name',
|
||||
description: `Requester's organization`,
|
||||
},
|
||||
{
|
||||
name: `Ticket's Organization External ID`,
|
||||
value: 'ticket.organization.external_id',
|
||||
description: `Ticket's organization external ID`,
|
||||
},
|
||||
{
|
||||
name: `Organization details`,
|
||||
value: 'ticket.organization.details',
|
||||
description: `The details about the organization of the ticket's requester`,
|
||||
},
|
||||
{
|
||||
name: `Organization Note`,
|
||||
value: 'ticket.organization.notes',
|
||||
description: `The notes about the organization of the ticket's requester`,
|
||||
},
|
||||
{
|
||||
name: `Ticket's CCs`,
|
||||
value: 'ticket.ccs',
|
||||
description: `Ticket's CCs`,
|
||||
},
|
||||
{
|
||||
name: `Ticket's CCs names`,
|
||||
value: 'ticket.cc_names',
|
||||
description: `Ticket's CCs names`,
|
||||
},
|
||||
{
|
||||
name: `Ticket's tags`,
|
||||
value: 'ticket.tags',
|
||||
description: `Ticket's tags`,
|
||||
},
|
||||
{
|
||||
name: `Current Holiday Name`,
|
||||
value: 'ticket.current_holiday_name',
|
||||
description: `Displays the name of the current holiday on the ticket's schedule`,
|
||||
},
|
||||
{
|
||||
name: `Current User Name `,
|
||||
value: 'current_user.name',
|
||||
description: `Your full name`,
|
||||
},
|
||||
{
|
||||
name: `Current User First Name `,
|
||||
value: 'current_user.first_name',
|
||||
description: 'Your first name',
|
||||
},
|
||||
{
|
||||
name: `Current User Email `,
|
||||
value: 'current_user.email',
|
||||
description: 'Your primary email',
|
||||
},
|
||||
{
|
||||
name: `Current User Organization Name `,
|
||||
value: 'current_user.organization.name',
|
||||
description: 'Your default organization',
|
||||
},
|
||||
{
|
||||
name: `Current User Organization Details `,
|
||||
value: 'current_user.organization.details',
|
||||
description: `Your default organization's details`,
|
||||
},
|
||||
{
|
||||
name: `Current User Organization Notes `,
|
||||
value: 'current_user.organization.notes',
|
||||
description: `Your default organization's note`,
|
||||
},
|
||||
{
|
||||
name: `Current User Language `,
|
||||
value: 'current_user.language',
|
||||
description: `Your chosen language`,
|
||||
},
|
||||
{
|
||||
name: `Current User External ID `,
|
||||
value: 'current_user.external_id',
|
||||
description: 'Your external ID',
|
||||
},
|
||||
{
|
||||
name: `Current User Notes `,
|
||||
value: 'current_user.notes',
|
||||
description: 'Your notes, stored in your profile',
|
||||
},
|
||||
{
|
||||
name: `Satisfation Current Rating `,
|
||||
value: 'satisfaction.current_rating',
|
||||
description: 'The text of the current satisfaction rating',
|
||||
},
|
||||
{
|
||||
name: `Satisfation Current Comment `,
|
||||
value: 'satisfaction.current_comment',
|
||||
description: 'The text of the current satisfaction rating comment``',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
placeholder: 'Add Option',
|
||||
},
|
||||
{
|
||||
displayName: 'Conditions',
|
||||
name: 'conditions',
|
||||
placeholder: 'Add Condition',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
service: [
|
||||
'support'
|
||||
],
|
||||
}
|
||||
},
|
||||
description: 'The condition to set.',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'all',
|
||||
displayName: 'All',
|
||||
values: [
|
||||
...conditionFields,
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'any',
|
||||
displayName: 'Any',
|
||||
values: [
|
||||
...conditionFields,
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
};
|
||||
methods = {
|
||||
loadOptions: {
|
||||
// Get all the groups to display them to user so that he can
|
||||
// select them easily
|
||||
async getGroups(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const groups = await zendeskApiRequestAllItems.call(this, 'groups', 'GET', '/groups');
|
||||
for (const group of groups) {
|
||||
const groupName = group.name;
|
||||
const groupId = group.id;
|
||||
returnData.push({
|
||||
name: groupName,
|
||||
value: groupId,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
// Get all the users to display them to user so that he can
|
||||
// select them easily
|
||||
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const users = await zendeskApiRequestAllItems.call(this, 'users', 'GET', '/users');
|
||||
for (const user of users) {
|
||||
const userName = user.name;
|
||||
const userId = user.id;
|
||||
returnData.push({
|
||||
name: userName,
|
||||
value: userId,
|
||||
});
|
||||
}
|
||||
returnData.push({
|
||||
name: 'Current User',
|
||||
value: 'current_user',
|
||||
});
|
||||
returnData.push({
|
||||
name: 'Requester',
|
||||
value: 'requester_id',
|
||||
});
|
||||
return returnData;
|
||||
},
|
||||
}
|
||||
};
|
||||
// @ts-ignore
|
||||
webhookMethods = {
|
||||
default: {
|
||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
if (webhookData.webhookId === undefined) {
|
||||
return false;
|
||||
}
|
||||
const endpoint = `/triggers/${webhookData.webhookId}`;
|
||||
try {
|
||||
await zendeskApiRequest.call(this, 'GET', endpoint);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
async create(this: IHookFunctions): Promise<boolean> {
|
||||
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 conditions = this.getNodeParameter('conditions') as IDataObject;
|
||||
const options = this.getNodeParameter('options') as IDataObject;
|
||||
if (Object.keys(conditions).length === 0) {
|
||||
throw new Error('You must have at least one condition');
|
||||
}
|
||||
if (options.fields) {
|
||||
// @ts-ignore
|
||||
for (const field of options.fields) {
|
||||
// @ts-ignore
|
||||
message[field] = `{{${field}}}`;
|
||||
}
|
||||
} else {
|
||||
message['ticket.id'] = '{{ticket.id}}';
|
||||
}
|
||||
const conditionsAll = conditions.all as [IDataObject];
|
||||
if (conditionsAll) {
|
||||
for (const conditionAll of conditionsAll) {
|
||||
aux.field = conditionAll.field;
|
||||
aux.operator = conditionAll.operation;
|
||||
if (conditionAll.operation !== 'changed'
|
||||
&& conditionAll.operation !== 'not_changed') {
|
||||
aux.value = conditionAll.value;
|
||||
} else {
|
||||
aux.value = null;
|
||||
}
|
||||
resultAll.push(aux);
|
||||
}
|
||||
}
|
||||
const conditionsAny = conditions.any as [IDataObject];
|
||||
if (conditionsAny) {
|
||||
for (const conditionAny of conditionsAny) {
|
||||
aux.field = conditionAny.field;
|
||||
aux.operator = conditionAny.operation;
|
||||
if (conditionAny.operation !== 'changed'
|
||||
&& conditionAny.operation !== 'not_changed') {
|
||||
aux.value = conditionAny.value;
|
||||
} else {
|
||||
aux.value = null;
|
||||
}
|
||||
resultAny.push(aux);
|
||||
}
|
||||
}
|
||||
const urlParts = urlParse(webhookUrl);
|
||||
const bodyTrigger: IDataObject = {
|
||||
trigger: {
|
||||
title: `n8n-webhook:${urlParts.path}`,
|
||||
conditions: {
|
||||
all: resultAll,
|
||||
any: resultAny,
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
field: 'notification_target',
|
||||
value: [],
|
||||
}
|
||||
]
|
||||
},
|
||||
};
|
||||
const bodyTarget: IDataObject = {
|
||||
target: {
|
||||
title: 'n8n webhook',
|
||||
type: 'http_target',
|
||||
target_url: webhookUrl,
|
||||
method: 'POST',
|
||||
active: true,
|
||||
content_type: 'application/json',
|
||||
},
|
||||
};
|
||||
const { target } = await zendeskApiRequest.call(this, 'POST', '/targets', bodyTarget);
|
||||
// @ts-ignore
|
||||
bodyTrigger.trigger.actions[0].value = [target.id, JSON.stringify(message)];
|
||||
const { trigger } = await zendeskApiRequest.call(this, 'POST', '/triggers', bodyTrigger);
|
||||
webhookData.webhookId = trigger.id;
|
||||
webhookData.targetId = target.id;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
async delete(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
try {
|
||||
await zendeskApiRequest.call(this, 'DELETE', `/triggers/${webhookData.webhookId}`);
|
||||
await zendeskApiRequest.call(this, 'DELETE', `/targets/${webhookData.targetId}`);
|
||||
} catch(error) {
|
||||
return false;
|
||||
}
|
||||
delete webhookData.webhookId;
|
||||
delete webhookData.targetId;
|
||||
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 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "n8n-nodes-base",
|
||||
"version": "0.39.0",
|
||||
"version": "0.40.0",
|
||||
"description": "Base nodes of n8n",
|
||||
"license": "SEE LICENSE IN LICENSE.md",
|
||||
"homepage": "https://n8n.io",
|
||||
@@ -58,6 +58,7 @@
|
||||
"dist/credentials/MySql.credentials.js",
|
||||
"dist/credentials/NextCloudApi.credentials.js",
|
||||
"dist/credentials/OpenWeatherMapApi.credentials.js",
|
||||
"dist/credentials/OAuth2Api.credentials.js",
|
||||
"dist/credentials/PipedriveApi.credentials.js",
|
||||
"dist/credentials/Postgres.credentials.js",
|
||||
"dist/credentials/PayPalApi.credentials.js",
|
||||
@@ -71,13 +72,15 @@
|
||||
"dist/credentials/TodoistApi.credentials.js",
|
||||
"dist/credentials/TrelloApi.credentials.js",
|
||||
"dist/credentials/TwilioApi.credentials.js",
|
||||
"dist/credentials/Msg91Api.credentials.js",
|
||||
"dist/credentials/TypeformApi.credentials.js",
|
||||
"dist/credentials/MandrillApi.credentials.js",
|
||||
"dist/credentials/TodoistApi.credentials.js",
|
||||
"dist/credentials/TypeformApi.credentials.js",
|
||||
"dist/credentials/TogglApi.credentials.js",
|
||||
"dist/credentials/VeroApi.credentials.js",
|
||||
"dist/credentials/WordpressApi.credentials.js"
|
||||
"dist/credentials/WordpressApi.credentials.js",
|
||||
"dist/credentials/ZendeskApi.credentials.js"
|
||||
],
|
||||
"nodes": [
|
||||
"dist/nodes/ActiveCampaign/ActiveCampaign.node.js",
|
||||
@@ -132,10 +135,11 @@
|
||||
"dist/nodes/MoveBinaryData.node.js",
|
||||
"dist/nodes/MongoDb/MongoDb.node.js",
|
||||
"dist/nodes/MySql/MySql.node.js",
|
||||
"dist/nodes/NextCloud/NextCloud.node.js",
|
||||
"dist/nodes/Mandrill/Mandrill.node.js",
|
||||
"dist/nodes/NextCloud/NextCloud.node.js",
|
||||
"dist/nodes/Mandrill/Mandrill.node.js",
|
||||
"dist/nodes/NoOp.node.js",
|
||||
"dist/nodes/OpenWeatherMap.node.js",
|
||||
"dist/nodes/OAuth.node.js",
|
||||
"dist/nodes/Pipedrive/Pipedrive.node.js",
|
||||
"dist/nodes/Pipedrive/PipedriveTrigger.node.js",
|
||||
"dist/nodes/Postgres/Postgres.node.js",
|
||||
@@ -163,13 +167,16 @@
|
||||
"dist/nodes/Trello/Trello.node.js",
|
||||
"dist/nodes/Trello/TrelloTrigger.node.js",
|
||||
"dist/nodes/Twilio/Twilio.node.js",
|
||||
"dist/nodes/Msg91/Msg91.node.js",
|
||||
"dist/nodes/Typeform/TypeformTrigger.node.js",
|
||||
"dist/nodes/Toggl/TogglTrigger.node.js",
|
||||
"dist/nodes/Vero/Vero.node.js",
|
||||
"dist/nodes/WriteBinaryFile.node.js",
|
||||
"dist/nodes/Webhook.node.js",
|
||||
"dist/nodes/Wordpress/Wordpress.node.js",
|
||||
"dist/nodes/Xml.node.js"
|
||||
"dist/nodes/Webhook.node.js",
|
||||
"dist/nodes/Wordpress/Wordpress.node.js",
|
||||
"dist/nodes/Xml.node.js",
|
||||
"dist/nodes/Zendesk/ZendeskTrigger.node.js",
|
||||
"dist/nodes/Zendesk/Zendesk.node.js"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user