@connectorx/n8n-nodes-cortex 0.1.23 → 0.1.24
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 +45 -91
- package/package.json +1 -1
|
@@ -247,41 +247,17 @@ class Cortex {
|
|
|
247
247
|
name: 'variable',
|
|
248
248
|
displayName: 'Variable',
|
|
249
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
250
|
{
|
|
258
251
|
displayName: 'Value',
|
|
259
252
|
name: 'value',
|
|
260
253
|
type: 'string',
|
|
261
254
|
default: '',
|
|
262
|
-
description: '
|
|
255
|
+
description: 'Variable value — fill in the same order as shown in the template dropdown',
|
|
263
256
|
},
|
|
264
257
|
],
|
|
265
258
|
},
|
|
266
259
|
],
|
|
267
|
-
description: 'Fill 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
|
-
},
|
|
279
|
-
},
|
|
280
|
-
default: '',
|
|
281
|
-
description: 'Optional: Override the auto-generated payload with raw JSON. Leave empty to use the template dropdown + variables above.',
|
|
282
|
-
typeOptions: {
|
|
283
|
-
alwaysOpenEditWindow: true,
|
|
284
|
-
},
|
|
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)',
|
|
285
261
|
},
|
|
286
262
|
{
|
|
287
263
|
displayName: 'Sender ID',
|
|
@@ -533,7 +509,7 @@ class Cortex {
|
|
|
533
509
|
const label = `${t.name} (${t.language || 'pt_BR'})${varNames ? ' — Vars: ' + varNames : ''}`;
|
|
534
510
|
return {
|
|
535
511
|
name: label,
|
|
536
|
-
value: JSON.stringify({ id: t.id, name: t.name, language: t.language,
|
|
512
|
+
value: JSON.stringify({ id: t.id, name: t.name, language: t.language, variables: t.variables }),
|
|
537
513
|
};
|
|
538
514
|
});
|
|
539
515
|
}
|
|
@@ -590,75 +566,53 @@ class Cortex {
|
|
|
590
566
|
}
|
|
591
567
|
}
|
|
592
568
|
else if (msgType === 'template') {
|
|
593
|
-
const
|
|
594
|
-
|
|
569
|
+
const templateDataStr = this.getNodeParameter('template_id', i);
|
|
570
|
+
if (!templateDataStr)
|
|
571
|
+
throw new Error('Please select a template');
|
|
572
|
+
let templateData;
|
|
573
|
+
try {
|
|
574
|
+
templateData = JSON.parse(templateDataStr);
|
|
575
|
+
}
|
|
576
|
+
catch (e) {
|
|
577
|
+
throw new Error('Invalid template selection');
|
|
578
|
+
}
|
|
579
|
+
const varsCollection = (() => { try {
|
|
580
|
+
return this.getNodeParameter('template_variables', i, {});
|
|
595
581
|
}
|
|
596
582
|
catch (_e) {
|
|
597
|
-
return
|
|
583
|
+
return {};
|
|
598
584
|
} })();
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
585
|
+
const userValues = ((varsCollection === null || varsCollection === void 0 ? void 0 : varsCollection.variable) || []).map((v) => v.value || '');
|
|
586
|
+
const templateVars = templateData.variables || [];
|
|
587
|
+
const components = [];
|
|
588
|
+
const headerVars = templateVars.filter((v) => v.component === 'header');
|
|
589
|
+
const bodyVars = templateVars.filter((v) => v.component === 'body');
|
|
590
|
+
let valueIdx = 0;
|
|
591
|
+
if (headerVars.length > 0) {
|
|
592
|
+
const params = headerVars.map((tv) => {
|
|
593
|
+
const isPositional = /^Variável \d+$/.test(tv.name);
|
|
594
|
+
const param = { type: 'text', text: userValues[valueIdx++] || '' };
|
|
595
|
+
if (!isPositional)
|
|
596
|
+
param.parameter_name = tv.name;
|
|
597
|
+
return param;
|
|
598
|
+
});
|
|
599
|
+
components.push({ type: 'header', parameters: params });
|
|
611
600
|
}
|
|
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
|
-
};
|
|
601
|
+
if (bodyVars.length > 0) {
|
|
602
|
+
const params = bodyVars.map((tv) => {
|
|
603
|
+
const isPositional = /^Variável \d+$/.test(tv.name);
|
|
604
|
+
const param = { type: 'text', text: userValues[valueIdx++] || '' };
|
|
605
|
+
if (!isPositional)
|
|
606
|
+
param.parameter_name = tv.name;
|
|
607
|
+
return param;
|
|
608
|
+
});
|
|
609
|
+
components.push({ type: 'body', parameters: params });
|
|
661
610
|
}
|
|
611
|
+
content = {
|
|
612
|
+
name: templateData.name,
|
|
613
|
+
language: templateData.language || 'pt_BR',
|
|
614
|
+
components,
|
|
615
|
+
};
|
|
662
616
|
}
|
|
663
617
|
const body = {
|
|
664
618
|
conversation_id: conversationId,
|