@growsalesai/n8n-nodes-datacrazy 2.0.0 → 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 +28 -22
- 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,20 +3,8 @@ 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
|
-
// tenta body.text, depois components[type=BODY].text
|
|
9
|
-
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
|
-
}
|
|
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
6
|
async function executeWhatsappTemplate(operation, baseUrl, i) {
|
|
19
|
-
var _a, _b, _c;
|
|
7
|
+
var _a, _b, _c, _d, _e, _f;
|
|
20
8
|
if (operation === 'listTemplates') {
|
|
21
9
|
const channelId = this.getNodeParameter('channelId', i, '', { extractValue: true });
|
|
22
10
|
const take = this.getNodeParameter('take', i, 100);
|
|
@@ -28,16 +16,14 @@ async function executeWhatsappTemplate(operation, baseUrl, i) {
|
|
|
28
16
|
const templateId = this.getNodeParameter('templateSelector', i, '', { extractValue: true });
|
|
29
17
|
const variablesCollection = this.getNodeParameter('variables', i, { items: [] });
|
|
30
18
|
const variableValues = ((_a = variablesCollection === null || variablesCollection === void 0 ? void 0 : variablesCollection.items) !== null && _a !== void 0 ? _a : []).map((item) => item.value);
|
|
31
|
-
// busca
|
|
19
|
+
// busca o template completo (com body.text, body.parameters, buttons, etc.)
|
|
32
20
|
const listRes = await request_1.makeRequest.call(this, baseUrl, 'GET', `${BASE_PATH}/${channelId}`, undefined, { take: 200 });
|
|
33
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 : []);
|
|
34
22
|
const template = templates.find((t) => { var _a; return String((_a = t.id) !== null && _a !== void 0 ? _a : '') === templateId; });
|
|
35
23
|
if (!template) {
|
|
36
24
|
throw new Error(`Template "${templateId}" não encontrado no canal "${channelId}". Verifique o Canal selecionado.`);
|
|
37
25
|
}
|
|
38
|
-
//
|
|
39
|
-
const rawBodyText = extractBodyText(template);
|
|
40
|
-
const resolvedBodyText = rawBodyText ? substituteVariables(rawBodyText, variableValues) : '';
|
|
26
|
+
// monta os campos do template exatamente no formato esperado pela API
|
|
41
27
|
const templatePayload = {
|
|
42
28
|
id: template.id,
|
|
43
29
|
name: template.name,
|
|
@@ -45,13 +31,33 @@ async function executeWhatsappTemplate(operation, baseUrl, i) {
|
|
|
45
31
|
status: template.status,
|
|
46
32
|
templateId: template.templateId,
|
|
47
33
|
category: template.category,
|
|
34
|
+
parameter_format: (_d = template.parameter_format) !== null && _d !== void 0 ? _d : 'positional',
|
|
48
35
|
};
|
|
49
|
-
//
|
|
50
|
-
if (
|
|
51
|
-
|
|
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 : []);
|
|
39
|
+
templatePayload.body = {
|
|
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
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// botões: exatamente como vêm do template
|
|
54
|
+
if (Array.isArray(template.buttons) && template.buttons.length > 0) {
|
|
55
|
+
templatePayload.buttons = template.buttons;
|
|
52
56
|
}
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
return request_1.makeRequest.call(this, baseUrl, 'POST', `${BASE_PATH}/send`, {
|
|
58
|
+
conversationId,
|
|
59
|
+
template: templatePayload,
|
|
60
|
+
});
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
//# 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":";;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;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,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