n8n-nodes-zohoteaminbox
Version:
This is an n8n community node. It lets you use Zoho TeamInbox in your n8n workflows.
136 lines • 6.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZohoTeamInbox = void 0;
const descriptions_1 = require("./descriptions");
const GenericFunctions_1 = require("./GenericFunctions");
class ZohoTeamInbox {
constructor() {
this.description = {
displayName: 'Zoho TeamInbox',
name: 'zohoTeamInbox',
icon: 'file:ZohoTeamInbox.png',
group: ['transform'],
subtitle: '={{$parameter["operation"]}}',
version: 1,
description: 'Consume Zoho TeamInbox API',
defaults: {
name: 'Zoho TeamInbox',
},
usableAsTool: true,
inputs: ["main"],
outputs: ["main"],
credentials: [
{
name: 'zohoTeamInboxOAuth2Api',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
required: true,
options: [
{
name: 'Message',
value: 'message',
},
{
name: 'Contact',
value: 'contact'
},
],
default: 'message',
},
...descriptions_1.messageOperations,
...descriptions_1.messageActionFields,
...descriptions_1.contactOperations,
...descriptions_1.contactActionFields
],
};
this.methods = {
loadOptions: {
async getListWorkspace() {
return await GenericFunctions_1.getPicklistWorkspaceOptions.call(this);
},
async getListTeam() {
const workspace = this.getCurrentNodeParameter('workspaceid');
return await GenericFunctions_1.getPicklistTeamOptions.call(this, workspace.toString());
},
async getListInbox() {
const workspace = this.getCurrentNodeParameter('workspaceid');
const team = this.getCurrentNodeParameter('teamid');
return await GenericFunctions_1.getPicklistInboxOptions.call(this, workspace.toString(), team.toString());
},
async getListFrom() {
const workspace = this.getCurrentNodeParameter('workspaceid');
return await GenericFunctions_1.getPicklistFromOptions.call(this, workspace.toString());
},
}
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
let responseData;
for (let i = 0; i < items.length; i++) {
try {
if (resource === 'message') {
if (operation === 'sendemail') {
const body = {
fromAddress: this.getNodeParameter('formaddress', i),
toAddress: this.getNodeParameter('toaddress', i),
subject: this.getNodeParameter('subject', i),
entity_type: "1",
encoding: "UTF-8",
mailFormat: "2",
archive: false
};
if (this.getNodeParameter('content', i) !== '' && this.getNodeParameter('content', i) !== undefined && this.getNodeParameter('content', i) !== null) {
body.text = this.getNodeParameter('content', i);
}
if (this.getNodeParameter('ccaddress', i) !== '' && this.getNodeParameter('ccaddress', i) !== undefined && this.getNodeParameter('ccaddress', i) !== null) {
body.ccAddress = this.getNodeParameter('ccaddress', i);
}
if (this.getNodeParameter('bccaddress', i) !== '' && this.getNodeParameter('bccaddress', i) !== undefined && this.getNodeParameter('bccaddress', i) !== null) {
body.bccAddress = this.getNodeParameter('bccaddress', i);
}
responseData = await GenericFunctions_1.zohoteaminboxApiRequest.call(this, 'POST', `api/v1/workspaces/${this.getNodeParameter('workspaceid', i)}/teams/${this.getNodeParameter('teamid', i)}/channels/${this.getNodeParameter('channelid', i)}/compose/mail`, body, {});
responseData = responseData.data;
}
}
else if (resource === 'contact') {
if (operation === 'createcontact') {
const body = {
name: this.getNodeParameter('contactname', i),
email_id: this.getNodeParameter('emailaddress', i),
};
if (this.getNodeParameter('description', i) !== '' && this.getNodeParameter('description', i) !== undefined && this.getNodeParameter('description', i) !== null) {
body.description = this.getNodeParameter('description', i);
}
if (this.getNodeParameter('mobilenumber', i) !== '' && this.getNodeParameter('mobilenumber', i) !== undefined && this.getNodeParameter('mobilenumber', i) !== null) {
body.mobile = this.getNodeParameter('mobilenumber', i);
}
responseData = await GenericFunctions_1.zohoteaminboxApiRequest.call(this, 'POST', `api/workspaces/${this.getNodeParameter('workspaceid', i)}/teams/${this.getNodeParameter('teamid', i)}/contacts`, body, {});
responseData = responseData.data;
}
}
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.error_description, json: {} });
continue;
}
throw error;
}
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
returnData.push(...executionData);
}
return [returnData];
}
}
exports.ZohoTeamInbox = ZohoTeamInbox;
//# sourceMappingURL=ZohoTeamInbox.node.js.map