@growsalesai/n8n-nodes-datacrazy 2.0.1 → 2.0.2
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/Datacrazy/resources/whatsappTemplates/whatsappTemplate.handler.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/resources/whatsappTemplates/whatsappTemplate.handler.js +19 -27
- package/dist/nodes/Datacrazy/resources/whatsappTemplates/whatsappTemplate.handler.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whatsappTemplate.handler.d.ts","sourceRoot":"","sources":["../../../../../nodes/Datacrazy/resources/whatsappTemplates/whatsappTemplate.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAe,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"whatsappTemplate.handler.d.ts","sourceRoot":"","sources":["../../../../../nodes/Datacrazy/resources/whatsappTemplates/whatsappTemplate.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAe,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAI/D,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,iBAAiB,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,EACpB,CAAC,EAAE,MAAM,GACR,OAAO,CAAC,GAAG,CAAC,CA2Dd"}
|
|
@@ -3,10 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.executeWhatsappTemplate = executeWhatsappTemplate;
|
|
4
4
|
const request_1 = require("../../utils/request");
|
|
5
5
|
const BASE_PATH = '/api/messaging/whatsapp-cloud/templates';
|
|
6
|
-
function extractBodyText(template) {
|
|
7
|
-
var _a, _b, _c, _d, _e;
|
|
8
|
-
return ((_e = (_b = (_a = template === null || template === void 0 ? void 0 : template.body) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : (_d = (_c = template === null || template === void 0 ? void 0 : template.components) === null || _c === void 0 ? void 0 : _c.find((c) => c.type === 'BODY')) === null || _d === void 0 ? void 0 : _d.text) !== null && _e !== void 0 ? _e : '');
|
|
9
|
-
}
|
|
10
6
|
async function executeWhatsappTemplate(operation, baseUrl, i) {
|
|
11
7
|
var _a, _b, _c, _d, _e, _f;
|
|
12
8
|
if (operation === 'listTemplates') {
|
|
@@ -20,28 +16,14 @@ async function executeWhatsappTemplate(operation, baseUrl, i) {
|
|
|
20
16
|
const templateId = this.getNodeParameter('templateSelector', i, '', { extractValue: true });
|
|
21
17
|
const variablesCollection = this.getNodeParameter('variables', i, { items: [] });
|
|
22
18
|
const variableValues = ((_a = variablesCollection === null || variablesCollection === void 0 ? void 0 : variablesCollection.items) !== null && _a !== void 0 ? _a : []).map((item) => item.value);
|
|
23
|
-
// busca
|
|
19
|
+
// busca o template completo (com body.text, body.parameters, buttons, etc.)
|
|
24
20
|
const listRes = await request_1.makeRequest.call(this, baseUrl, 'GET', `${BASE_PATH}/${channelId}`, undefined, { take: 200 });
|
|
25
21
|
const templates = ((_c = (_b = listRes === null || listRes === void 0 ? void 0 : listRes.data) !== null && _b !== void 0 ? _b : listRes) !== null && _c !== void 0 ? _c : []);
|
|
26
22
|
const template = templates.find((t) => { var _a; return String((_a = t.id) !== null && _a !== void 0 ? _a : '') === templateId; });
|
|
27
23
|
if (!template) {
|
|
28
24
|
throw new Error(`Template "${templateId}" não encontrado no canal "${channelId}". Verifique o Canal selecionado.`);
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
// definições de parâmetros que vêm do template (com name/example de cada variável)
|
|
32
|
-
const templateParamDefs = ((_e = (_d = template === null || template === void 0 ? void 0 : template.body) === null || _d === void 0 ? void 0 : _d.parameters) !== null && _e !== void 0 ? _e : []);
|
|
33
|
-
// monta cada parâmetro mesclando a definição do template com o valor fornecido pelo usuário
|
|
34
|
-
const parameters = variableValues.map((val, idx) => {
|
|
35
|
-
var _a, _b, _c, _d, _e;
|
|
36
|
-
const def = templateParamDefs[idx];
|
|
37
|
-
return {
|
|
38
|
-
name: (_b = (_a = def === null || def === void 0 ? void 0 : def.name) !== null && _a !== void 0 ? _a : def === null || def === void 0 ? void 0 : def.example) !== null && _b !== void 0 ? _b : val,
|
|
39
|
-
parameter_name: (_c = def === null || def === void 0 ? void 0 : def.parameter_name) !== null && _c !== void 0 ? _c : '',
|
|
40
|
-
value: val,
|
|
41
|
-
example: (_e = (_d = def === null || def === void 0 ? void 0 : def.example) !== null && _d !== void 0 ? _d : def === null || def === void 0 ? void 0 : def.name) !== null && _e !== void 0 ? _e : val,
|
|
42
|
-
type: 'text',
|
|
43
|
-
};
|
|
44
|
-
});
|
|
26
|
+
// monta os campos do template exatamente no formato esperado pela API
|
|
45
27
|
const templatePayload = {
|
|
46
28
|
id: template.id,
|
|
47
29
|
name: template.name,
|
|
@@ -49,17 +31,27 @@ async function executeWhatsappTemplate(operation, baseUrl, i) {
|
|
|
49
31
|
status: template.status,
|
|
50
32
|
templateId: template.templateId,
|
|
51
33
|
category: template.category,
|
|
52
|
-
parameter_format: (
|
|
34
|
+
parameter_format: (_d = template.parameter_format) !== null && _d !== void 0 ? _d : 'positional',
|
|
53
35
|
};
|
|
54
|
-
//
|
|
55
|
-
if (
|
|
36
|
+
// body: usa os parâmetros definidos no template, sobrescrevendo apenas o value com o que o usuário preencheu
|
|
37
|
+
if (template.body) {
|
|
38
|
+
const paramDefs = ((_e = template.body.parameters) !== null && _e !== void 0 ? _e : []);
|
|
56
39
|
templatePayload.body = {
|
|
57
|
-
text:
|
|
58
|
-
parameters,
|
|
40
|
+
text: (_f = template.body.text) !== null && _f !== void 0 ? _f : '',
|
|
41
|
+
parameters: paramDefs.map((def, idx) => {
|
|
42
|
+
var _a, _b, _c, _d, _e, _f;
|
|
43
|
+
return ({
|
|
44
|
+
name: (_a = def.name) !== null && _a !== void 0 ? _a : '',
|
|
45
|
+
parameter_name: (_b = def.parameter_name) !== null && _b !== void 0 ? _b : '',
|
|
46
|
+
value: (_c = variableValues[idx]) !== null && _c !== void 0 ? _c : '',
|
|
47
|
+
example: (_e = (_d = def.example) !== null && _d !== void 0 ? _d : def.name) !== null && _e !== void 0 ? _e : '',
|
|
48
|
+
type: (_f = def.type) !== null && _f !== void 0 ? _f : 'text',
|
|
49
|
+
});
|
|
50
|
+
}),
|
|
59
51
|
};
|
|
60
52
|
}
|
|
61
|
-
//
|
|
62
|
-
if (template.buttons && template.buttons.length > 0) {
|
|
53
|
+
// botões: exatamente como vêm do template
|
|
54
|
+
if (Array.isArray(template.buttons) && template.buttons.length > 0) {
|
|
63
55
|
templatePayload.buttons = template.buttons;
|
|
64
56
|
}
|
|
65
57
|
return request_1.makeRequest.call(this, baseUrl, 'POST', `${BASE_PATH}/send`, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whatsappTemplate.handler.js","sourceRoot":"","sources":["../../../../../nodes/Datacrazy/resources/whatsappTemplates/whatsappTemplate.handler.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"whatsappTemplate.handler.js","sourceRoot":"","sources":["../../../../../nodes/Datacrazy/resources/whatsappTemplates/whatsappTemplate.handler.ts"],"names":[],"mappings":";;AAKA,0DAgEC;AApED,iDAA+D;AAE/D,MAAM,SAAS,GAAG,yCAAyC,CAAC;AAErD,KAAK,UAAU,uBAAuB,CAE3C,SAAiB,EACjB,OAAoB,EACpB,CAAS;;IAET,IAAI,SAAS,KAAK,eAAe,EAAE,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAW,CAAC;QAC9F,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,CAAW,CAAC;QA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