@growsalesai/n8n-nodes-datacrazy 2.0.0 → 2.0.1
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 +31 -17
- 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;AAY/D,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,iBAAiB,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,EACpB,CAAC,EAAE,MAAM,GACR,OAAO,CAAC,GAAG,CAAC,CAoEd"}
|
|
@@ -5,18 +5,10 @@ const request_1 = require("../../utils/request");
|
|
|
5
5
|
const BASE_PATH = '/api/messaging/whatsapp-cloud/templates';
|
|
6
6
|
function extractBodyText(template) {
|
|
7
7
|
var _a, _b, _c, _d, _e;
|
|
8
|
-
// tenta body.text, depois components[type=BODY].text
|
|
9
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 : '');
|
|
10
9
|
}
|
|
11
|
-
function substituteVariables(text, values) {
|
|
12
|
-
let result = text;
|
|
13
|
-
values.forEach((val, idx) => {
|
|
14
|
-
result = result.replace(new RegExp(`\\{\\{${idx + 1}\\}\\}`, 'g'), val);
|
|
15
|
-
});
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
10
|
async function executeWhatsappTemplate(operation, baseUrl, i) {
|
|
19
|
-
var _a, _b, _c;
|
|
11
|
+
var _a, _b, _c, _d, _e, _f;
|
|
20
12
|
if (operation === 'listTemplates') {
|
|
21
13
|
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true });
|
|
22
14
|
const take = this.getNodeParameter('take', i, 100);
|
|
@@ -35,9 +27,21 @@ async function executeWhatsappTemplate(operation, baseUrl, i) {
|
|
|
35
27
|
if (!template) {
|
|
36
28
|
throw new Error(`Template "${templateId}" não encontrado no canal "${channelId}". Verifique o Canal selecionado.`);
|
|
37
29
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
30
|
+
const bodyText = extractBodyText(template);
|
|
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
|
+
});
|
|
41
45
|
const templatePayload = {
|
|
42
46
|
id: template.id,
|
|
43
47
|
name: template.name,
|
|
@@ -45,13 +49,23 @@ async function executeWhatsappTemplate(operation, baseUrl, i) {
|
|
|
45
49
|
status: template.status,
|
|
46
50
|
templateId: template.templateId,
|
|
47
51
|
category: template.category,
|
|
52
|
+
parameter_format: (_f = template.parameter_format) !== null && _f !== void 0 ? _f : 'positional',
|
|
48
53
|
};
|
|
49
|
-
//
|
|
50
|
-
if (
|
|
51
|
-
templatePayload.body = {
|
|
54
|
+
// inclui body apenas se tiver texto — texto vazio faz o WhatsApp rejeitar
|
|
55
|
+
if (bodyText) {
|
|
56
|
+
templatePayload.body = {
|
|
57
|
+
text: bodyText, // texto original com {{1}}, {{2}} — Datacrazy substitui server-side
|
|
58
|
+
parameters,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// inclui botões do template se existirem
|
|
62
|
+
if (template.buttons && template.buttons.length > 0) {
|
|
63
|
+
templatePayload.buttons = template.buttons;
|
|
52
64
|
}
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
return request_1.makeRequest.call(this, baseUrl, 'POST', `${BASE_PATH}/send`, {
|
|
66
|
+
conversationId,
|
|
67
|
+
template: templatePayload,
|
|
68
|
+
});
|
|
55
69
|
}
|
|
56
70
|
}
|
|
57
71
|
//# sourceMappingURL=whatsappTemplate.handler.js.map
|
|
@@ -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":";;AAaA,0DAyEC;AArFD,iDAA+D;AAE/D,MAAM,SAAS,GAAG,yCAAyC,CAAC;AAE5D,SAAS,eAAe,CAAC,QAAa;;IACpC,OAAO,CACL,MAAA,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,0CAAE,IAAI,mCACpB,MAAA,MAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAoB,0CAAE,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,0CAAE,IAAI,mCAC1E,EAAE,CACH,CAAC;AACJ,CAAC;AAEM,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;QAC7D,OAAO,qBAAW,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,SAAS,IAAI,SAAS,EAAE,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IAClG,CAAC;IAED,IAAI,SAAS,KAAK,cAAc,EAAE,CAAC;QACjC,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAW,C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