@connectorx/n8n-nodes-cortex 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nodes/Cortex/Cortex.node.js +84 -107
- package/package.json +1 -1
|
@@ -230,10 +230,8 @@ class Cortex {
|
|
|
230
230
|
{
|
|
231
231
|
displayName: 'Template Variables',
|
|
232
232
|
name: 'template_variables',
|
|
233
|
-
type: '
|
|
234
|
-
|
|
235
|
-
multipleValues: true,
|
|
236
|
-
},
|
|
233
|
+
type: 'resourceMapper',
|
|
234
|
+
noDataExpression: true,
|
|
237
235
|
displayOptions: {
|
|
238
236
|
show: {
|
|
239
237
|
resource: ['message'],
|
|
@@ -241,46 +239,23 @@ class Cortex {
|
|
|
241
239
|
msg_type: ['template'],
|
|
242
240
|
},
|
|
243
241
|
},
|
|
244
|
-
default: {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
name: 'variable',
|
|
248
|
-
displayName: 'Variable',
|
|
249
|
-
values: [
|
|
250
|
-
{
|
|
251
|
-
displayName: 'Name',
|
|
252
|
-
name: 'name',
|
|
253
|
-
type: 'string',
|
|
254
|
-
default: '',
|
|
255
|
-
description: 'Variable name (e.g. "name") or positional label (e.g. "Variável 1")',
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
displayName: 'Value',
|
|
259
|
-
name: 'value',
|
|
260
|
-
type: 'string',
|
|
261
|
-
default: '',
|
|
262
|
-
description: 'Value to fill in the variable',
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
description: 'Fill in the template variables. Use the variable names shown in the template.',
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
displayName: 'Template JSON (Advanced)',
|
|
271
|
-
name: 'template_json',
|
|
272
|
-
type: 'json',
|
|
273
|
-
displayOptions: {
|
|
274
|
-
show: {
|
|
275
|
-
resource: ['message'],
|
|
276
|
-
operation: ['send'],
|
|
277
|
-
msg_type: ['template'],
|
|
278
|
-
},
|
|
242
|
+
default: {
|
|
243
|
+
mappingMode: 'defineBelow',
|
|
244
|
+
value: null,
|
|
279
245
|
},
|
|
280
|
-
default: '',
|
|
281
|
-
description: 'Optional: Override the auto-generated payload with raw JSON. Leave empty to use the template dropdown + variables above.',
|
|
282
246
|
typeOptions: {
|
|
283
|
-
|
|
247
|
+
loadOptionsDependsOn: ['template_id'],
|
|
248
|
+
resourceMapper: {
|
|
249
|
+
resourceMapperMethod: 'getTemplateVariableFields',
|
|
250
|
+
mode: 'add',
|
|
251
|
+
fieldWords: {
|
|
252
|
+
singular: 'variável',
|
|
253
|
+
plural: 'variáveis',
|
|
254
|
+
},
|
|
255
|
+
addAllFields: true,
|
|
256
|
+
noFieldsError: 'Selecione um template primeiro',
|
|
257
|
+
multiKeyMatch: false,
|
|
258
|
+
},
|
|
284
259
|
},
|
|
285
260
|
},
|
|
286
261
|
{
|
|
@@ -533,7 +508,7 @@ class Cortex {
|
|
|
533
508
|
const label = `${t.name} (${t.language || 'pt_BR'})${varNames ? ' — Vars: ' + varNames : ''}`;
|
|
534
509
|
return {
|
|
535
510
|
name: label,
|
|
536
|
-
value: JSON.stringify({ id: t.id, name: t.name, language: t.language,
|
|
511
|
+
value: JSON.stringify({ id: t.id, name: t.name, language: t.language, variables: t.variables }),
|
|
537
512
|
};
|
|
538
513
|
});
|
|
539
514
|
}
|
|
@@ -542,6 +517,31 @@ class Cortex {
|
|
|
542
517
|
}
|
|
543
518
|
},
|
|
544
519
|
},
|
|
520
|
+
resourceMapping: {
|
|
521
|
+
async getTemplateVariableFields() {
|
|
522
|
+
try {
|
|
523
|
+
const templateDataStr = this.getNodeParameter('template_id');
|
|
524
|
+
if (!templateDataStr)
|
|
525
|
+
return { fields: [] };
|
|
526
|
+
const templateData = JSON.parse(templateDataStr);
|
|
527
|
+
const vars = (templateData.variables || []);
|
|
528
|
+
return {
|
|
529
|
+
fields: vars.map((v) => ({
|
|
530
|
+
id: v.name,
|
|
531
|
+
displayName: v.name.toUpperCase(),
|
|
532
|
+
required: true,
|
|
533
|
+
defaultMatch: false,
|
|
534
|
+
display: true,
|
|
535
|
+
type: 'string',
|
|
536
|
+
canBeUsedToMatch: false,
|
|
537
|
+
})),
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
catch (e) {
|
|
541
|
+
return { fields: [] };
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
545
|
};
|
|
546
546
|
}
|
|
547
547
|
async execute() {
|
|
@@ -590,75 +590,52 @@ class Cortex {
|
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
592
|
else if (msgType === 'template') {
|
|
593
|
-
const
|
|
594
|
-
|
|
593
|
+
const templateDataStr = this.getNodeParameter('template_id', i);
|
|
594
|
+
if (!templateDataStr)
|
|
595
|
+
throw new Error('Please select a template');
|
|
596
|
+
let templateData;
|
|
597
|
+
try {
|
|
598
|
+
templateData = JSON.parse(templateDataStr);
|
|
599
|
+
}
|
|
600
|
+
catch (e) {
|
|
601
|
+
throw new Error('Invalid template selection');
|
|
602
|
+
}
|
|
603
|
+
const varsData = (() => { try {
|
|
604
|
+
return this.getNodeParameter('template_variables', i, {});
|
|
595
605
|
}
|
|
596
606
|
catch (_e) {
|
|
597
|
-
return
|
|
607
|
+
return {};
|
|
598
608
|
} })();
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
609
|
+
const userValues = (varsData === null || varsData === void 0 ? void 0 : varsData.value) || {};
|
|
610
|
+
const templateVars = templateData.variables || [];
|
|
611
|
+
const components = [];
|
|
612
|
+
const headerVars = templateVars.filter((v) => v.component === 'header');
|
|
613
|
+
const bodyVars = templateVars.filter((v) => v.component === 'body');
|
|
614
|
+
if (headerVars.length > 0) {
|
|
615
|
+
const params = headerVars.map((tv) => {
|
|
616
|
+
const isPositional = /^Variável \d+$/.test(tv.name);
|
|
617
|
+
const param = { type: 'text', text: userValues[tv.name] || '' };
|
|
618
|
+
if (!isPositional)
|
|
619
|
+
param.parameter_name = tv.name;
|
|
620
|
+
return param;
|
|
621
|
+
});
|
|
622
|
+
components.push({ type: 'header', parameters: params });
|
|
611
623
|
}
|
|
612
|
-
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
throw new Error('Invalid template selection');
|
|
622
|
-
}
|
|
623
|
-
const varsCollection = (() => { try {
|
|
624
|
-
return this.getNodeParameter('template_variables', i, {});
|
|
625
|
-
}
|
|
626
|
-
catch (_e) {
|
|
627
|
-
return {};
|
|
628
|
-
} })();
|
|
629
|
-
const userVars = (varsCollection === null || varsCollection === void 0 ? void 0 : varsCollection.variable) || [];
|
|
630
|
-
const templateVars = templateData.variables || [];
|
|
631
|
-
const components = [];
|
|
632
|
-
const headerVars = templateVars.filter((v) => v.component === 'header');
|
|
633
|
-
const bodyVars = templateVars.filter((v) => v.component === 'body');
|
|
634
|
-
if (headerVars.length > 0) {
|
|
635
|
-
const params = headerVars.map((tv) => {
|
|
636
|
-
const userVar = userVars.find(uv => uv.name === tv.name);
|
|
637
|
-
const isPositional = /^Variável \d+$/.test(tv.name);
|
|
638
|
-
const param = { type: 'text', text: (userVar === null || userVar === void 0 ? void 0 : userVar.value) || '' };
|
|
639
|
-
if (!isPositional)
|
|
640
|
-
param.parameter_name = tv.name;
|
|
641
|
-
return param;
|
|
642
|
-
});
|
|
643
|
-
components.push({ type: 'header', parameters: params });
|
|
644
|
-
}
|
|
645
|
-
if (bodyVars.length > 0) {
|
|
646
|
-
const params = bodyVars.map((tv) => {
|
|
647
|
-
const userVar = userVars.find(uv => uv.name === tv.name);
|
|
648
|
-
const isPositional = /^Variável \d+$/.test(tv.name);
|
|
649
|
-
const param = { type: 'text', text: (userVar === null || userVar === void 0 ? void 0 : userVar.value) || '' };
|
|
650
|
-
if (!isPositional)
|
|
651
|
-
param.parameter_name = tv.name;
|
|
652
|
-
return param;
|
|
653
|
-
});
|
|
654
|
-
components.push({ type: 'body', parameters: params });
|
|
655
|
-
}
|
|
656
|
-
content = {
|
|
657
|
-
name: templateData.name,
|
|
658
|
-
language: templateData.language || 'pt_BR',
|
|
659
|
-
components,
|
|
660
|
-
};
|
|
624
|
+
if (bodyVars.length > 0) {
|
|
625
|
+
const params = bodyVars.map((tv) => {
|
|
626
|
+
const isPositional = /^Variável \d+$/.test(tv.name);
|
|
627
|
+
const param = { type: 'text', text: userValues[tv.name] || '' };
|
|
628
|
+
if (!isPositional)
|
|
629
|
+
param.parameter_name = tv.name;
|
|
630
|
+
return param;
|
|
631
|
+
});
|
|
632
|
+
components.push({ type: 'body', parameters: params });
|
|
661
633
|
}
|
|
634
|
+
content = {
|
|
635
|
+
name: templateData.name,
|
|
636
|
+
language: templateData.language || 'pt_BR',
|
|
637
|
+
components,
|
|
638
|
+
};
|
|
662
639
|
}
|
|
663
640
|
const body = {
|
|
664
641
|
conversation_id: conversationId,
|