n8n-nodes-chatwoot
Version:
This is an n8n community node. It lets you use ChatWoot in your n8n workflows.
200 lines • 7.95 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatWoot = void 0;
const descriptions_1 = require("./descriptions");
const methods_1 = require("./methods");
const GenericFunctions_1 = require("./GenericFunctions");
class ChatWoot {
constructor() {
this.description = {
displayName: 'ChatWoot',
name: 'chatwoot',
icon: 'file:chatwoot.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume ChatWoot API',
defaults: {
name: 'ChatWoot',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'chatWootTokenApi',
testedBy: 'chatWootTokenTest',
required: true,
displayOptions: {
show: {
authentication: [
'predefinedCredentialType',
],
},
},
},
],
properties: [
{
displayName: 'Authentication',
name: 'authentication',
noDataExpression: true,
type: 'options',
required: true,
options: [
{
name: 'Parameters',
value: 'parametersCredentialType',
},
{
name: 'Predefined Chatwoot Credentials',
value: 'predefinedCredentialType',
description: 'BaseUrl + Token',
},
],
default: 'parametersCredentialType',
},
{
displayName: 'BaseUrl',
name: 'baseUrl',
type: 'string',
default: '',
required: true,
description: 'Base URL',
placeholder: 'https://chatwoot.org',
displayOptions: {
show: {
authentication: [
'parametersCredentialType',
],
},
},
},
{
displayName: 'Access Token',
name: 'accessToken',
type: 'string',
default: '',
required: true,
description: 'Token of chatwoot, override credentials',
placeholder: '00000000-0000-0000-0000-000000000000',
displayOptions: {
show: {
authentication: [
'parametersCredentialType',
],
resource: ['account', 'contact'],
},
},
},
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Account',
value: 'account',
},
{
name: 'Contact',
value: 'contact',
},
{
name: 'Public',
value: 'public',
},
],
default: 'public',
required: true,
},
{
displayName: 'Account ID',
name: 'accountId',
type: 'string',
displayOptions: {
show: {
resource: ['account', 'contact'],
operation: ['accountInformation', 'contactDetails', 'contactSearch', 'contactUpdate', 'contactCreate'],
},
},
default: '',
description: '(Optional) Account ID reference, this settings will override credentials',
},
{
displayName: 'Source ID',
name: 'sourceId',
type: 'string',
displayOptions: {
show: {
resource: ['public', 'contact'],
operation: ['messageCreate', 'messages', 'contact', 'contactCreate', 'contactUpdate', 'publicContactCreate'],
},
},
default: '',
description: 'Internal Source Contact Identifier, used for search, URL escaped or HEX',
},
...descriptions_1.accountDescription,
...descriptions_1.contactDescription,
...descriptions_1.publicDescription,
],
};
this.methods = {
credentialTest: {
async chatWootTokenTest(credential) {
const credentials = credential.data;
const options = (0, GenericFunctions_1.requestAccountOptions)(credentials);
try {
await this.helpers.request(options);
return {
status: 'OK',
message: 'Authentication successful',
};
}
catch (error) {
return {
status: 'Error',
message: error.message,
};
}
},
},
};
}
async execute() {
const items = this.getInputData();
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
const returnData = [];
for (let i = 0; i < items.length; i++) {
let responseData;
try {
if (resource === 'account') {
responseData = await methods_1.resourceAccount.call(this, operation, items, i);
}
else if (resource === 'contact') {
responseData = await methods_1.resourceContact.call(this, operation, items, i);
}
else if (resource === 'public') {
responseData = await methods_1.resourcePublic.call(this, operation, items, i);
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData);
}
else if (responseData !== undefined) {
returnData.push(responseData);
}
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });
continue;
}
throw error;
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}
exports.ChatWoot = ChatWoot;
//# sourceMappingURL=ChatWoot.node.js.map
;