@connectorx/n8n-nodes-cortex 0.1.24 → 0.1.26
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 +74 -26
- 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,23 +239,24 @@ class Cortex {
|
|
|
241
239
|
msg_type: ['template'],
|
|
242
240
|
},
|
|
243
241
|
},
|
|
244
|
-
default: {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
242
|
+
default: {
|
|
243
|
+
mappingMode: 'defineBelow',
|
|
244
|
+
value: null,
|
|
245
|
+
},
|
|
246
|
+
typeOptions: {
|
|
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
258
|
},
|
|
259
|
-
|
|
260
|
-
description: 'Fill in the template variable values in the same order as shown in the template dropdown (e.g. "Vars: nome, email" → 1st value = nome, 2nd value = email)',
|
|
259
|
+
},
|
|
261
260
|
},
|
|
262
261
|
{
|
|
263
262
|
displayName: 'Sender ID',
|
|
@@ -509,7 +508,7 @@ class Cortex {
|
|
|
509
508
|
const label = `${t.name} (${t.language || 'pt_BR'})${varNames ? ' — Vars: ' + varNames : ''}`;
|
|
510
509
|
return {
|
|
511
510
|
name: label,
|
|
512
|
-
value: JSON.stringify({ id: t.id, name: t.name, language: t.language, variables: t.variables }),
|
|
511
|
+
value: JSON.stringify({ id: t.id, name: t.name, language: t.language, variables: t.variables, components: t.components }),
|
|
513
512
|
};
|
|
514
513
|
});
|
|
515
514
|
}
|
|
@@ -518,6 +517,43 @@ class Cortex {
|
|
|
518
517
|
}
|
|
519
518
|
},
|
|
520
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
|
+
const fields = vars.map((v) => ({
|
|
529
|
+
id: v.name,
|
|
530
|
+
displayName: v.name.toUpperCase(),
|
|
531
|
+
required: true,
|
|
532
|
+
defaultMatch: false,
|
|
533
|
+
display: true,
|
|
534
|
+
type: 'string',
|
|
535
|
+
canBeUsedToMatch: false,
|
|
536
|
+
}));
|
|
537
|
+
const components = (templateData.components || []);
|
|
538
|
+
const headerComp = components.find((c) => c.type === 'HEADER');
|
|
539
|
+
if (headerComp && ['IMAGE', 'VIDEO', 'DOCUMENT'].includes(headerComp.format)) {
|
|
540
|
+
fields.unshift({
|
|
541
|
+
id: 'header_media_url',
|
|
542
|
+
displayName: `HEADER (${headerComp.format}) URL`,
|
|
543
|
+
required: true,
|
|
544
|
+
defaultMatch: false,
|
|
545
|
+
display: true,
|
|
546
|
+
type: 'string',
|
|
547
|
+
canBeUsedToMatch: false,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
return { fields };
|
|
551
|
+
}
|
|
552
|
+
catch (e) {
|
|
553
|
+
return { fields: [] };
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
},
|
|
521
557
|
};
|
|
522
558
|
}
|
|
523
559
|
async execute() {
|
|
@@ -576,22 +612,21 @@ class Cortex {
|
|
|
576
612
|
catch (e) {
|
|
577
613
|
throw new Error('Invalid template selection');
|
|
578
614
|
}
|
|
579
|
-
const
|
|
615
|
+
const varsData = (() => { try {
|
|
580
616
|
return this.getNodeParameter('template_variables', i, {});
|
|
581
617
|
}
|
|
582
618
|
catch (_e) {
|
|
583
619
|
return {};
|
|
584
620
|
} })();
|
|
585
|
-
const userValues = (
|
|
621
|
+
const userValues = (varsData === null || varsData === void 0 ? void 0 : varsData.value) || {};
|
|
586
622
|
const templateVars = templateData.variables || [];
|
|
587
623
|
const components = [];
|
|
588
624
|
const headerVars = templateVars.filter((v) => v.component === 'header');
|
|
589
625
|
const bodyVars = templateVars.filter((v) => v.component === 'body');
|
|
590
|
-
let valueIdx = 0;
|
|
591
626
|
if (headerVars.length > 0) {
|
|
592
627
|
const params = headerVars.map((tv) => {
|
|
593
628
|
const isPositional = /^Variável \d+$/.test(tv.name);
|
|
594
|
-
const param = { type: 'text', text: userValues[
|
|
629
|
+
const param = { type: 'text', text: userValues[tv.name] || '' };
|
|
595
630
|
if (!isPositional)
|
|
596
631
|
param.parameter_name = tv.name;
|
|
597
632
|
return param;
|
|
@@ -601,13 +636,26 @@ class Cortex {
|
|
|
601
636
|
if (bodyVars.length > 0) {
|
|
602
637
|
const params = bodyVars.map((tv) => {
|
|
603
638
|
const isPositional = /^Variável \d+$/.test(tv.name);
|
|
604
|
-
const param = { type: 'text', text: userValues[
|
|
639
|
+
const param = { type: 'text', text: userValues[tv.name] || '' };
|
|
605
640
|
if (!isPositional)
|
|
606
641
|
param.parameter_name = tv.name;
|
|
607
642
|
return param;
|
|
608
643
|
});
|
|
609
644
|
components.push({ type: 'body', parameters: params });
|
|
610
645
|
}
|
|
646
|
+
const headerComp = (templateData.components || []).find((c) => c.type === 'HEADER');
|
|
647
|
+
if (headerComp && ['IMAGE', 'VIDEO', 'DOCUMENT'].includes(headerComp.format)) {
|
|
648
|
+
const mediaUrl = userValues['header_media_url'];
|
|
649
|
+
if (mediaUrl) {
|
|
650
|
+
const mediaType = headerComp.format.toLowerCase();
|
|
651
|
+
const mediaParam = { type: mediaType };
|
|
652
|
+
mediaParam[mediaType] = { link: mediaUrl };
|
|
653
|
+
components.unshift({
|
|
654
|
+
type: 'header',
|
|
655
|
+
parameters: [mediaParam]
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
}
|
|
611
659
|
content = {
|
|
612
660
|
name: templateData.name,
|
|
613
661
|
language: templateData.language || 'pt_BR',
|