@digitalstories/n8n-nodes-infomaniak
Version:
n8n nodes to interact with Infomaniak services (Kchat)
98 lines • 3.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Infomaniak = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const KchatDescription_1 = require("./services/Kchat/KchatDescription");
const KchatService_1 = require("./services/Kchat/KchatService");
const KchatNodeOperations_1 = require("./services/Kchat/KchatNodeOperations");
class Infomaniak {
constructor() {
this.description = {
displayName: 'Infomaniak',
name: 'infomaniak',
icon: 'file:infomaniak.svg',
group: ['transform'],
version: 1,
description: "Interact with Infomaniak services",
defaults: {
name: 'Infomaniak',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'infomaniakApi',
required: true,
},
],
properties: [
{
displayName: 'Service',
name: 'service',
type: 'options',
options: [
{
name: 'Kchat',
value: 'kchat',
},
],
default: 'kchat',
description: 'Infomaniak service to use',
noDataExpression: true,
},
...KchatDescription_1.kchatServiceProperties,
],
};
this.methods = {
loadOptions: {
async getChannels() {
const credentials = await this.getCredentials('infomaniakApi');
const service = new KchatService_1.KchatService(this, credentials);
const response = await service.getChannels();
if (!response || !Array.isArray(response)) {
throw new n8n_workflow_1.NodeOperationError(null, 'Error retrieving channels');
}
return response.map((channel) => ({
name: channel.display_name,
value: channel.id,
}));
},
},
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
const length = items.length;
const credentials = await this.getCredentials('infomaniakApi');
const service = this.getNodeParameter('service', 0);
let nodeOperations;
switch (service) {
case 'kchat':
nodeOperations = new KchatNodeOperations_1.KchatNodeOperations(this, credentials);
break;
default:
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Service ${service} is not supported`);
}
for (let i = 0; i < length; i++) {
const resource = this.getNodeParameter('resource', i);
const operation = this.getNodeParameter('operation', i);
const response = await nodeOperations.executeOperation(resource, operation, i);
if (Array.isArray(response)) {
returnData.push(...response);
}
else {
returnData.push(response);
}
}
const outputItems = [];
for (const item of returnData) {
outputItems.push({
json: item,
});
}
return [outputItems];
}
}
exports.Infomaniak = Infomaniak;
//# sourceMappingURL=Infomaniak.node.js.map