@growsalesai/n8n-nodes-datacrazy 1.1.0 → 1.2.0
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/credentials/DatacrazyApi.credentials.js +2 -2
- package/dist/credentials/DatacrazyApi.credentials.js.map +1 -1
- package/dist/nodes/Datacrazy/Datacrazy.node.d.ts +4 -1
- package/dist/nodes/Datacrazy/Datacrazy.node.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/Datacrazy.node.js +82 -682
- package/dist/nodes/Datacrazy/Datacrazy.node.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/BusinessActionDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/BusinessActionDescription.js +17 -3
- package/dist/nodes/Datacrazy/descriptions/BusinessActionDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/BusinessDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/BusinessDescription.js +18 -4
- package/dist/nodes/Datacrazy/descriptions/BusinessDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/BusinessLossReasonDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/BusinessLossReasonDescription.js +17 -3
- package/dist/nodes/Datacrazy/descriptions/BusinessLossReasonDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/ConversationDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/ConversationDescription.js +17 -3
- package/dist/nodes/Datacrazy/descriptions/ConversationDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/InstanceDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/InstanceDescription.js +17 -3
- package/dist/nodes/Datacrazy/descriptions/InstanceDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/LeadDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/LeadDescription.js +17 -8
- package/dist/nodes/Datacrazy/descriptions/LeadDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/LeadSubResourceDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/LeadSubResourceDescription.js +26 -40
- package/dist/nodes/Datacrazy/descriptions/LeadSubResourceDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/ListDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/ListDescription.js +17 -3
- package/dist/nodes/Datacrazy/descriptions/ListDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/PipelineDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/PipelineDescription.js +17 -3
- package/dist/nodes/Datacrazy/descriptions/PipelineDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/ProductDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/ProductDescription.js +17 -3
- package/dist/nodes/Datacrazy/descriptions/ProductDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/TagDescription.d.ts.map +1 -1
- package/dist/nodes/Datacrazy/descriptions/TagDescription.js +17 -3
- package/dist/nodes/Datacrazy/descriptions/TagDescription.js.map +1 -1
- package/dist/nodes/Datacrazy/handlers/activity.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/activity.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/activity.handler.js +37 -0
- package/dist/nodes/Datacrazy/handlers/activity.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/attendant.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/attendant.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/attendant.handler.js +14 -0
- package/dist/nodes/Datacrazy/handlers/attendant.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/business.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/business.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/business.handler.js +37 -0
- package/dist/nodes/Datacrazy/handlers/business.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/businessAction.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/businessAction.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/businessAction.handler.js +26 -0
- package/dist/nodes/Datacrazy/handlers/businessAction.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/businessLossReason.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/businessLossReason.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/businessLossReason.handler.js +26 -0
- package/dist/nodes/Datacrazy/handlers/businessLossReason.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/conversation.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/conversation.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/conversation.handler.js +32 -0
- package/dist/nodes/Datacrazy/handlers/conversation.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/instance.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/instance.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/instance.handler.js +13 -0
- package/dist/nodes/Datacrazy/handlers/instance.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/lead.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/lead.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/lead.handler.js +89 -0
- package/dist/nodes/Datacrazy/handlers/lead.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/leadMover.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/leadMover.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/leadMover.handler.js +50 -0
- package/dist/nodes/Datacrazy/handlers/leadMover.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/leadSubResources.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/leadSubResources.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/leadSubResources.handler.js +71 -0
- package/dist/nodes/Datacrazy/handlers/leadSubResources.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/list.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/list.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/list.handler.js +28 -0
- package/dist/nodes/Datacrazy/handlers/list.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/messageContext.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/messageContext.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/messageContext.handler.js +87 -0
- package/dist/nodes/Datacrazy/handlers/messageContext.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/pipeline.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/pipeline.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/pipeline.handler.js +17 -0
- package/dist/nodes/Datacrazy/handlers/pipeline.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/product.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/product.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/product.handler.js +28 -0
- package/dist/nodes/Datacrazy/handlers/product.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/tag.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/tag.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/tag.handler.js +28 -0
- package/dist/nodes/Datacrazy/handlers/tag.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/handlers/webhookParser.handler.d.ts +3 -0
- package/dist/nodes/Datacrazy/handlers/webhookParser.handler.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/handlers/webhookParser.handler.js +106 -0
- package/dist/nodes/Datacrazy/handlers/webhookParser.handler.js.map +1 -0
- package/dist/nodes/Datacrazy/methods/loadOptions.d.ts +10 -0
- package/dist/nodes/Datacrazy/methods/loadOptions.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/methods/loadOptions.js +102 -0
- package/dist/nodes/Datacrazy/methods/loadOptions.js.map +1 -0
- package/dist/nodes/Datacrazy/utils/request.d.ts +4 -0
- package/dist/nodes/Datacrazy/utils/request.d.ts.map +1 -0
- package/dist/nodes/Datacrazy/utils/request.js +20 -0
- package/dist/nodes/Datacrazy/utils/request.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.Datacrazy = void 0;
|
|
4
37
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
@@ -18,6 +51,23 @@ const LeadSubResourceDescription_1 = require("./descriptions/LeadSubResourceDesc
|
|
|
18
51
|
const WebhookParserDescription_1 = require("./descriptions/WebhookParserDescription");
|
|
19
52
|
const MessageContextDescription_1 = require("./descriptions/MessageContextDescription");
|
|
20
53
|
const LeadMoverDescription_1 = require("./descriptions/LeadMoverDescription");
|
|
54
|
+
const lead_handler_1 = require("./handlers/lead.handler");
|
|
55
|
+
const business_handler_1 = require("./handlers/business.handler");
|
|
56
|
+
const businessAction_handler_1 = require("./handlers/businessAction.handler");
|
|
57
|
+
const businessLossReason_handler_1 = require("./handlers/businessLossReason.handler");
|
|
58
|
+
const tag_handler_1 = require("./handlers/tag.handler");
|
|
59
|
+
const list_handler_1 = require("./handlers/list.handler");
|
|
60
|
+
const product_handler_1 = require("./handlers/product.handler");
|
|
61
|
+
const activity_handler_1 = require("./handlers/activity.handler");
|
|
62
|
+
const conversation_handler_1 = require("./handlers/conversation.handler");
|
|
63
|
+
const instance_handler_1 = require("./handlers/instance.handler");
|
|
64
|
+
const attendant_handler_1 = require("./handlers/attendant.handler");
|
|
65
|
+
const pipeline_handler_1 = require("./handlers/pipeline.handler");
|
|
66
|
+
const leadSubResources_handler_1 = require("./handlers/leadSubResources.handler");
|
|
67
|
+
const webhookParser_handler_1 = require("./handlers/webhookParser.handler");
|
|
68
|
+
const messageContext_handler_1 = require("./handlers/messageContext.handler");
|
|
69
|
+
const leadMover_handler_1 = require("./handlers/leadMover.handler");
|
|
70
|
+
const loadOptions = __importStar(require("./methods/loadOptions"));
|
|
21
71
|
class Datacrazy {
|
|
22
72
|
constructor() {
|
|
23
73
|
this.description = {
|
|
@@ -31,12 +81,7 @@ class Datacrazy {
|
|
|
31
81
|
defaults: { name: 'Datacrazy' },
|
|
32
82
|
inputs: ['main'],
|
|
33
83
|
outputs: ['main'],
|
|
34
|
-
credentials: [
|
|
35
|
-
{
|
|
36
|
-
name: 'datacrazyApi',
|
|
37
|
-
required: true,
|
|
38
|
-
},
|
|
39
|
-
],
|
|
84
|
+
credentials: [{ name: 'datacrazyApi', required: true }],
|
|
40
85
|
properties: [
|
|
41
86
|
{
|
|
42
87
|
displayName: 'Recurso',
|
|
@@ -44,11 +89,9 @@ class Datacrazy {
|
|
|
44
89
|
type: 'options',
|
|
45
90
|
noDataExpression: true,
|
|
46
91
|
options: [
|
|
47
|
-
// --- Utilitários personalizados ---
|
|
48
92
|
{ name: '⚡ Analisar Webhook Datacrazy', value: 'webhookParser' },
|
|
49
93
|
{ name: '⚡ Contexto de Mensagem Referenciada', value: 'messageContext' },
|
|
50
94
|
{ name: '⚡ Mover Lead na Pipeline', value: 'leadMover' },
|
|
51
|
-
// --- API CRM ---
|
|
52
95
|
{ name: 'Leads', value: 'lead' },
|
|
53
96
|
{ name: 'Negócios do Lead', value: 'leadBusiness' },
|
|
54
97
|
{ name: 'Anexos do Lead', value: 'leadAttachment' },
|
|
@@ -70,11 +113,9 @@ class Datacrazy {
|
|
|
70
113
|
],
|
|
71
114
|
default: 'webhookParser',
|
|
72
115
|
},
|
|
73
|
-
// Operações dos utilitários personalizados
|
|
74
116
|
...WebhookParserDescription_1.webhookParserOperations,
|
|
75
117
|
...MessageContextDescription_1.messageContextOperations,
|
|
76
118
|
...LeadMoverDescription_1.leadMoverOperations,
|
|
77
|
-
// Operações da API CRM
|
|
78
119
|
...LeadDescription_1.leadOperations,
|
|
79
120
|
...LeadSubResourceDescription_1.leadBusinessOperations,
|
|
80
121
|
...LeadSubResourceDescription_1.leadAttachmentOperations,
|
|
@@ -92,11 +133,9 @@ class Datacrazy {
|
|
|
92
133
|
...InstanceDescription_1.instanceOperations,
|
|
93
134
|
...AttendantDescription_1.attendantOperations,
|
|
94
135
|
...PipelineDescription_1.pipelineOperations,
|
|
95
|
-
// Campos dos utilitários personalizados
|
|
96
136
|
...WebhookParserDescription_1.webhookParserFields,
|
|
97
137
|
...MessageContextDescription_1.messageContextFields,
|
|
98
138
|
...LeadMoverDescription_1.leadMoverFields,
|
|
99
|
-
// Campos da API CRM
|
|
100
139
|
...LeadDescription_1.leadFields,
|
|
101
140
|
...LeadSubResourceDescription_1.leadBusinessFields,
|
|
102
141
|
...LeadSubResourceDescription_1.leadAttachmentFields,
|
|
@@ -116,703 +155,76 @@ class Datacrazy {
|
|
|
116
155
|
...PipelineDescription_1.pipelineFields,
|
|
117
156
|
],
|
|
118
157
|
};
|
|
158
|
+
this.methods = {
|
|
159
|
+
listSearch: {
|
|
160
|
+
searchLeads: loadOptions.searchLeads,
|
|
161
|
+
searchPipelines: loadOptions.searchPipelines,
|
|
162
|
+
searchTags: loadOptions.searchTags,
|
|
163
|
+
searchConversations: loadOptions.searchConversations,
|
|
164
|
+
searchInstances: loadOptions.searchInstances,
|
|
165
|
+
searchLossReasons: loadOptions.searchLossReasons,
|
|
166
|
+
searchLists: loadOptions.searchLists,
|
|
167
|
+
searchProducts: loadOptions.searchProducts,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
119
170
|
}
|
|
120
171
|
async execute() {
|
|
121
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26;
|
|
122
172
|
const items = this.getInputData();
|
|
123
173
|
const returnData = [];
|
|
124
174
|
const credentials = await this.getCredentials('datacrazyApi');
|
|
125
175
|
const baseUrl = credentials.apiUrl.replace(/\/$/, '');
|
|
126
176
|
for (let i = 0; i < items.length; i++) {
|
|
127
177
|
const resource = this.getNodeParameter('resource', i);
|
|
128
|
-
const operation = this.getNodeParameter('operation', i);
|
|
178
|
+
const operation = this.getNodeParameter('operation', i, '');
|
|
129
179
|
let responseData;
|
|
130
180
|
try {
|
|
131
|
-
// ============================================================
|
|
132
|
-
// UTILITÁRIO: ANALISAR WEBHOOK DATACRAZY
|
|
133
|
-
// ============================================================
|
|
134
181
|
if (resource === 'webhookParser') {
|
|
135
|
-
|
|
136
|
-
const rawQuery = this.getNodeParameter('webhookQuery', i, '{}');
|
|
137
|
-
const providerParam = this.getNodeParameter('provider', i);
|
|
138
|
-
const payload = typeof rawPayload === 'string' ? JSON.parse(rawPayload) : rawPayload;
|
|
139
|
-
const query = typeof rawQuery === 'string' ? JSON.parse(rawQuery) : rawQuery;
|
|
140
|
-
// O webhook pode chegar como array ou objeto
|
|
141
|
-
const body = Array.isArray(payload) ? ((_b = (_a = payload[0]) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : payload[0]) : ((_c = payload.body) !== null && _c !== void 0 ? _c : payload);
|
|
142
|
-
const qParams = Array.isArray(payload) ? ((_e = (_d = payload[0]) === null || _d === void 0 ? void 0 : _d.query) !== null && _e !== void 0 ? _e : query) : ((_f = payload.query) !== null && _f !== void 0 ? _f : query);
|
|
143
|
-
// Detectar provedor automaticamente
|
|
144
|
-
let provider = providerParam;
|
|
145
|
-
if (provider === 'auto') {
|
|
146
|
-
if ((body === null || body === void 0 ? void 0 : body.from_user_id) !== undefined || (body === null || body === void 0 ? void 0 : body.context_id) !== undefined) {
|
|
147
|
-
provider = 'whatsappApi';
|
|
148
|
-
}
|
|
149
|
-
else if ((body === null || body === void 0 ? void 0 : body.sender_id) !== undefined || (body === null || body === void 0 ? void 0 : body.message_mid) !== undefined) {
|
|
150
|
-
provider = 'instagramApi';
|
|
151
|
-
}
|
|
152
|
-
else if ((body === null || body === void 0 ? void 0 : body.messageid) !== undefined || (body === null || body === void 0 ? void 0 : body.sender_pn) !== undefined) {
|
|
153
|
-
provider = 'uazap';
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
provider = 'unknown';
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
let typeMessage = 'text';
|
|
160
|
-
let textBody = '';
|
|
161
|
-
let mediaUrl = '';
|
|
162
|
-
let mediaType = '';
|
|
163
|
-
let contextId = '';
|
|
164
|
-
let isReferencia = false;
|
|
165
|
-
let isReferralAd = false;
|
|
166
|
-
if (provider === 'whatsappApi') {
|
|
167
|
-
typeMessage = ((_g = body === null || body === void 0 ? void 0 : body.type) !== null && _g !== void 0 ? _g : 'text').toLowerCase();
|
|
168
|
-
textBody = (_h = body === null || body === void 0 ? void 0 : body.text_body) !== null && _h !== void 0 ? _h : '';
|
|
169
|
-
mediaUrl = (_j = body === null || body === void 0 ? void 0 : body.media_url) !== null && _j !== void 0 ? _j : '';
|
|
170
|
-
mediaType = (_k = body === null || body === void 0 ? void 0 : body.media_mime_type) !== null && _k !== void 0 ? _k : '';
|
|
171
|
-
contextId = (_l = body === null || body === void 0 ? void 0 : body.context_id) !== null && _l !== void 0 ? _l : '';
|
|
172
|
-
isReferencia = !!contextId;
|
|
173
|
-
isReferralAd = !!(body === null || body === void 0 ? void 0 : body.referral_ctwa_clid);
|
|
174
|
-
}
|
|
175
|
-
else if (provider === 'instagramApi') {
|
|
176
|
-
const attType = (_m = body === null || body === void 0 ? void 0 : body.message_attachments_type) !== null && _m !== void 0 ? _m : '';
|
|
177
|
-
if (attType) {
|
|
178
|
-
typeMessage = attType.toLowerCase();
|
|
179
|
-
}
|
|
180
|
-
else if (body === null || body === void 0 ? void 0 : body.message_text) {
|
|
181
|
-
typeMessage = 'text';
|
|
182
|
-
}
|
|
183
|
-
textBody = (_o = body === null || body === void 0 ? void 0 : body.message_text) !== null && _o !== void 0 ? _o : '';
|
|
184
|
-
mediaUrl = (_p = body === null || body === void 0 ? void 0 : body.message_attachments_payload_url) !== null && _p !== void 0 ? _p : '';
|
|
185
|
-
contextId = (_q = body === null || body === void 0 ? void 0 : body.message_reply_to_mid) !== null && _q !== void 0 ? _q : '';
|
|
186
|
-
isReferencia = !!contextId;
|
|
187
|
-
}
|
|
188
|
-
else if (provider === 'uazap') {
|
|
189
|
-
const attType = ((_r = body === null || body === void 0 ? void 0 : body.messageData_attachments_type) !== null && _r !== void 0 ? _r : '').toUpperCase();
|
|
190
|
-
if ((body === null || body === void 0 ? void 0 : body.type) === 'text' && !attType) {
|
|
191
|
-
typeMessage = 'text';
|
|
192
|
-
}
|
|
193
|
-
else if (attType === 'IMAGE') {
|
|
194
|
-
typeMessage = 'image';
|
|
195
|
-
}
|
|
196
|
-
else if (attType === 'VIDEO') {
|
|
197
|
-
typeMessage = 'video';
|
|
198
|
-
}
|
|
199
|
-
else if (attType === 'AUDIO') {
|
|
200
|
-
typeMessage = 'audio';
|
|
201
|
-
}
|
|
202
|
-
else if (attType === 'FILE') {
|
|
203
|
-
typeMessage = 'document';
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
typeMessage = ((_s = body === null || body === void 0 ? void 0 : body.type) !== null && _s !== void 0 ? _s : 'text').toLowerCase();
|
|
207
|
-
}
|
|
208
|
-
textBody = (_u = (_t = body === null || body === void 0 ? void 0 : body.text) !== null && _t !== void 0 ? _t : body === null || body === void 0 ? void 0 : body.content_text) !== null && _u !== void 0 ? _u : '';
|
|
209
|
-
mediaUrl = (_v = body === null || body === void 0 ? void 0 : body.messageData_attachments_url) !== null && _v !== void 0 ? _v : '';
|
|
210
|
-
mediaType = (_w = body === null || body === void 0 ? void 0 : body.messageData_attachments_mimeType) !== null && _w !== void 0 ? _w : '';
|
|
211
|
-
contextId = (_x = body === null || body === void 0 ? void 0 : body.quoted) !== null && _x !== void 0 ? _x : '';
|
|
212
|
-
isReferencia = !!contextId;
|
|
213
|
-
}
|
|
214
|
-
const tokenRaw = (_y = qParams === null || qParams === void 0 ? void 0 : qParams.Token_DC) !== null && _y !== void 0 ? _y : '';
|
|
215
|
-
const token = tokenRaw.startsWith('Bearer ') ? tokenRaw : `Bearer ${tokenRaw}`;
|
|
216
|
-
responseData = {
|
|
217
|
-
provider,
|
|
218
|
-
type_message: typeMessage,
|
|
219
|
-
text_body: textBody,
|
|
220
|
-
media_url: mediaUrl,
|
|
221
|
-
media_type: mediaType,
|
|
222
|
-
context_id: contextId,
|
|
223
|
-
is_referencia: isReferencia,
|
|
224
|
-
is_referral_ad: isReferralAd,
|
|
225
|
-
referral_body: (_z = body === null || body === void 0 ? void 0 : body.referral_body) !== null && _z !== void 0 ? _z : '',
|
|
226
|
-
referral_headline: (_0 = body === null || body === void 0 ? void 0 : body.referral_headline) !== null && _0 !== void 0 ? _0 : '',
|
|
227
|
-
referral_ctwa_clid: (_1 = body === null || body === void 0 ? void 0 : body.referral_ctwa_clid) !== null && _1 !== void 0 ? _1 : '',
|
|
228
|
-
leadId: (_3 = (_2 = qParams === null || qParams === void 0 ? void 0 : qParams.LeadID) !== null && _2 !== void 0 ? _2 : body === null || body === void 0 ? void 0 : body.messageData_contact_externalId) !== null && _3 !== void 0 ? _3 : '',
|
|
229
|
-
leadName: (_5 = (_4 = qParams === null || qParams === void 0 ? void 0 : qParams.LeadName) !== null && _4 !== void 0 ? _4 : body === null || body === void 0 ? void 0 : body.messageData_contact_name) !== null && _5 !== void 0 ? _5 : '',
|
|
230
|
-
token_datacrazy: token,
|
|
231
|
-
conversationId: (_6 = body === null || body === void 0 ? void 0 : body.messageData_conversationId) !== null && _6 !== void 0 ? _6 : '',
|
|
232
|
-
contactId: (_7 = body === null || body === void 0 ? void 0 : body.messageData_contact_id) !== null && _7 !== void 0 ? _7 : '',
|
|
233
|
-
contactName: (_8 = body === null || body === void 0 ? void 0 : body.messageData_contact_name) !== null && _8 !== void 0 ? _8 : '',
|
|
234
|
-
contactPhone: (_10 = (_9 = body === null || body === void 0 ? void 0 : body.messageData_contact_phoneNumber) !== null && _9 !== void 0 ? _9 : body === null || body === void 0 ? void 0 : body.messageData_contact_contactId) !== null && _10 !== void 0 ? _10 : '',
|
|
235
|
-
contactPlatform: (_11 = body === null || body === void 0 ? void 0 : body.messageData_contact_platform) !== null && _11 !== void 0 ? _11 : '',
|
|
236
|
-
instanceId: (_12 = body === null || body === void 0 ? void 0 : body.instanceData_id) !== null && _12 !== void 0 ? _12 : '',
|
|
237
|
-
instanceName: (_13 = body === null || body === void 0 ? void 0 : body.instanceData_name) !== null && _13 !== void 0 ? _13 : '',
|
|
238
|
-
timestamp: (_15 = (_14 = body === null || body === void 0 ? void 0 : body.timestamp) !== null && _14 !== void 0 ? _14 : body === null || body === void 0 ? void 0 : body.messageTimestamp) !== null && _15 !== void 0 ? _15 : '',
|
|
239
|
-
messageId: (_17 = (_16 = body === null || body === void 0 ? void 0 : body.id) !== null && _16 !== void 0 ? _16 : body === null || body === void 0 ? void 0 : body.messageid) !== null && _17 !== void 0 ? _17 : '',
|
|
240
|
-
messageDataDate: (_18 = body === null || body === void 0 ? void 0 : body.messageData_date) !== null && _18 !== void 0 ? _18 : '',
|
|
241
|
-
hasAttachments: (body === null || body === void 0 ? void 0 : body.messageData_hasAttachments) === 'true',
|
|
242
|
-
};
|
|
182
|
+
responseData = await webhookParser_handler_1.executeWebhookParser.call(this, i);
|
|
243
183
|
}
|
|
244
|
-
// ============================================================
|
|
245
|
-
// UTILITÁRIO: CONTEXTO DE MENSAGEM REFERENCIADA
|
|
246
|
-
// ============================================================
|
|
247
184
|
else if (resource === 'messageContext') {
|
|
248
|
-
|
|
249
|
-
const contextId = this.getNodeParameter('contextId', i);
|
|
250
|
-
const typeMessage = this.getNodeParameter('typeMessage', i);
|
|
251
|
-
const messageData = this.getNodeParameter('messageData', i, '');
|
|
252
|
-
const audioTranscription = this.getNodeParameter('audioTranscription', i, '');
|
|
253
|
-
// Sem context_id → não é mensagem de referência
|
|
254
|
-
if (!contextId) {
|
|
255
|
-
let messageLead = '';
|
|
256
|
-
if (typeMessage === 'audio') {
|
|
257
|
-
messageLead = audioTranscription
|
|
258
|
-
? audioTranscription
|
|
259
|
-
: '<mensagem de áudio>';
|
|
260
|
-
}
|
|
261
|
-
else if (typeMessage === 'image') {
|
|
262
|
-
messageLead = '<o usuário enviou uma imagem. Informe que você não consegue visualizar imagens e peça para ele enviar a informação por texto ou áudio>';
|
|
263
|
-
}
|
|
264
|
-
else if (typeMessage === 'video') {
|
|
265
|
-
messageLead = '<o usuário enviou um vídeo. Informe que você não consegue assistir vídeos e peça para ele enviar a informação por texto ou áudio>';
|
|
266
|
-
}
|
|
267
|
-
else if (typeMessage === 'document') {
|
|
268
|
-
messageLead = '<o usuário enviou um documento. Informe que você não consegue analisar documentos e peça para ele enviar a informação por texto ou áudio>';
|
|
269
|
-
}
|
|
270
|
-
responseData = {
|
|
271
|
-
isReply: false,
|
|
272
|
-
MessageReferencia: null,
|
|
273
|
-
MessageLead: messageLead || null,
|
|
274
|
-
MessageCompleta: messageLead || null,
|
|
275
|
-
type_message: typeMessage,
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
// É mensagem de referência — buscar histórico da conversa
|
|
280
|
-
const historyResponse = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/conversations/${conversationId}/messages`);
|
|
281
|
-
const messages = (_20 = (_19 = historyResponse === null || historyResponse === void 0 ? void 0 : historyResponse.messages) !== null && _19 !== void 0 ? _19 : historyResponse) !== null && _20 !== void 0 ? _20 : [];
|
|
282
|
-
const dataReferencia = messageData ? new Date(messageData) : new Date();
|
|
283
|
-
// Encontrar mensagem do lead mais próxima do timestamp
|
|
284
|
-
const receivedMessages = messages.filter((m) => m.received === true);
|
|
285
|
-
receivedMessages.sort((a, b) => Math.abs(new Date(a.createdAt).getTime() - dataReferencia.getTime()) -
|
|
286
|
-
Math.abs(new Date(b.createdAt).getTime() - dataReferencia.getTime()));
|
|
287
|
-
const mensagemUsuario = (_21 = receivedMessages[0]) !== null && _21 !== void 0 ? _21 : null;
|
|
288
|
-
// Texto da mensagem do lead
|
|
289
|
-
let messageLead = ((_22 = mensagemUsuario === null || mensagemUsuario === void 0 ? void 0 : mensagemUsuario.body) !== null && _22 !== void 0 ? _22 : '').toString().trim();
|
|
290
|
-
if (typeMessage === 'audio') {
|
|
291
|
-
messageLead = audioTranscription ||
|
|
292
|
-
(messageLead ? messageLead : '<mensagem de áudio não audível>');
|
|
293
|
-
}
|
|
294
|
-
else if (typeMessage === 'image') {
|
|
295
|
-
messageLead = messageLead
|
|
296
|
-
? `<o usuário enviou uma imagem junto com um texto: "${messageLead}". Informe que você não consegue visualizar imagens, mas pode ajudar com base no texto enviado>`
|
|
297
|
-
: '<o usuário enviou uma imagem. Informe que você não consegue visualizar imagens e peça para ele enviar a informação por texto ou áudio>';
|
|
298
|
-
}
|
|
299
|
-
else if (typeMessage === 'video') {
|
|
300
|
-
messageLead = messageLead
|
|
301
|
-
? `<o usuário enviou um vídeo junto com um texto: "${messageLead}". Informe que você não consegue assistir vídeos, mas pode ajudar com base no texto enviado>`
|
|
302
|
-
: '<o usuário enviou um vídeo. Informe que você não consegue assistir vídeos e peça para ele enviar a informação por texto ou áudio>';
|
|
303
|
-
}
|
|
304
|
-
else if (typeMessage === 'document') {
|
|
305
|
-
messageLead = messageLead
|
|
306
|
-
? `<o usuário enviou um documento junto com um texto: "${messageLead}". Informe que você não consegue analisar documentos, mas pode ajudar com base no texto enviado>`
|
|
307
|
-
: '<o usuário enviou um documento. Informe que você não consegue analisar documentos e peça para ele enviar a informação por texto ou áudio>';
|
|
308
|
-
}
|
|
309
|
-
// Encontrar a mensagem da IA que foi respondida
|
|
310
|
-
const mensagemIA = (_23 = mensagemUsuario === null || mensagemUsuario === void 0 ? void 0 : mensagemUsuario.repliedMessage) !== null && _23 !== void 0 ? _23 : null;
|
|
311
|
-
let perguntaFallback = null;
|
|
312
|
-
if (!mensagemIA && mensagemUsuario) {
|
|
313
|
-
const idx = messages.findIndex((m) => m.id === mensagemUsuario.id);
|
|
314
|
-
for (let j = idx + 1; j < messages.length; j++) {
|
|
315
|
-
if (messages[j].received === false) {
|
|
316
|
-
perguntaFallback = messages[j];
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
const perguntaFinal = mensagemIA !== null && mensagemIA !== void 0 ? mensagemIA : perguntaFallback;
|
|
322
|
-
const messageReferencia = (_24 = perguntaFinal === null || perguntaFinal === void 0 ? void 0 : perguntaFinal.body) !== null && _24 !== void 0 ? _24 : null;
|
|
323
|
-
const messageCompleta = [
|
|
324
|
-
messageReferencia ? `MENSAGEM REFERENCIADA: ${messageReferencia}` : '',
|
|
325
|
-
messageLead ? `RESPOSTA DO LEAD: ${messageLead}` : '',
|
|
326
|
-
].filter(Boolean).join('\n\n');
|
|
327
|
-
responseData = {
|
|
328
|
-
isReply: !!mensagemIA,
|
|
329
|
-
MessageReferencia: messageReferencia,
|
|
330
|
-
MessageLead: messageLead,
|
|
331
|
-
MessageCompleta: messageCompleta || null,
|
|
332
|
-
type_message: typeMessage,
|
|
333
|
-
};
|
|
334
|
-
}
|
|
185
|
+
responseData = await messageContext_handler_1.executeMessageContext.call(this, baseUrl, i);
|
|
335
186
|
}
|
|
336
|
-
// ============================================================
|
|
337
|
-
// UTILITÁRIO: MOVER LEAD NA PIPELINE
|
|
338
|
-
// ============================================================
|
|
339
187
|
else if (resource === 'leadMover') {
|
|
340
|
-
|
|
341
|
-
const pipelineName = this.getNodeParameter('pipelineName', i);
|
|
342
|
-
const destinationStageId = this.getNodeParameter('destinationStageId', i);
|
|
343
|
-
const createNote = this.getNodeParameter('createNote', i, true);
|
|
344
|
-
const noteContent = createNote
|
|
345
|
-
? this.getNodeParameter('noteContent', i, '')
|
|
346
|
-
: '';
|
|
347
|
-
const dealSelection = this.getNodeParameter('dealSelection', i, 'mostRecent');
|
|
348
|
-
// 1. Buscar negócios do lead
|
|
349
|
-
const businessesResponse = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/leads/${leadId}/businesses`);
|
|
350
|
-
const allDeals = (_26 = (_25 = businessesResponse === null || businessesResponse === void 0 ? void 0 : businessesResponse.data) !== null && _25 !== void 0 ? _25 : businessesResponse) !== null && _26 !== void 0 ? _26 : [];
|
|
351
|
-
// 2. Filtrar pela pipeline
|
|
352
|
-
const filteredDeals = allDeals.filter((d) => { var _a, _b; return ((_b = (_a = d.stage) === null || _a === void 0 ? void 0 : _a.pipeline) === null || _b === void 0 ? void 0 : _b.name) === pipelineName; });
|
|
353
|
-
if (filteredDeals.length === 0) {
|
|
354
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Nenhum negócio encontrado na pipeline "${pipelineName}" para o lead ${leadId}.`);
|
|
355
|
-
}
|
|
356
|
-
// 3. Selecionar negócio(s)
|
|
357
|
-
let dealsToMove;
|
|
358
|
-
if (dealSelection === 'all') {
|
|
359
|
-
dealsToMove = filteredDeals;
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
// Mais recente por lastMovedAt
|
|
363
|
-
const sorted = [...filteredDeals].sort((a, b) => {
|
|
364
|
-
var _a, _b;
|
|
365
|
-
return new Date((_a = b.lastMovedAt) !== null && _a !== void 0 ? _a : b.createdAt).getTime() -
|
|
366
|
-
new Date((_b = a.lastMovedAt) !== null && _b !== void 0 ? _b : a.createdAt).getTime();
|
|
367
|
-
});
|
|
368
|
-
dealsToMove = [sorted[0]];
|
|
369
|
-
}
|
|
370
|
-
const businessIds = dealsToMove.map((d) => d.id);
|
|
371
|
-
// 4. Mover negócio(s)
|
|
372
|
-
const moveResult = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/businesses/actions/move', { businessIds, stageId: destinationStageId });
|
|
373
|
-
// 5. Criar nota (se solicitado)
|
|
374
|
-
let noteResult = null;
|
|
375
|
-
if (createNote && noteContent) {
|
|
376
|
-
noteResult = await makeRequest.call(this, baseUrl, 'POST', `/api/v1/leads/${leadId}/notes`, { content: noteContent });
|
|
377
|
-
}
|
|
378
|
-
responseData = {
|
|
379
|
-
success: true,
|
|
380
|
-
leadId,
|
|
381
|
-
pipelineName,
|
|
382
|
-
destinationStageId,
|
|
383
|
-
businessIdsMoved: businessIds,
|
|
384
|
-
totalMoved: businessIds.length,
|
|
385
|
-
moveResult,
|
|
386
|
-
noteCreated: createNote && !!noteContent,
|
|
387
|
-
noteResult,
|
|
388
|
-
};
|
|
188
|
+
responseData = await leadMover_handler_1.executeLeadMover.call(this, baseUrl, i);
|
|
389
189
|
}
|
|
390
|
-
// ============================================================
|
|
391
|
-
// LEADS
|
|
392
|
-
// ============================================================
|
|
393
190
|
else if (resource === 'lead') {
|
|
394
|
-
|
|
395
|
-
const opts = this.getNodeParameter('queryOptions', i, {});
|
|
396
|
-
const qs = {};
|
|
397
|
-
if (opts.search)
|
|
398
|
-
qs.search = opts.search;
|
|
399
|
-
if (opts.skip !== undefined)
|
|
400
|
-
qs.skip = opts.skip;
|
|
401
|
-
if (opts.take !== undefined)
|
|
402
|
-
qs.take = opts.take;
|
|
403
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/leads', undefined, qs);
|
|
404
|
-
}
|
|
405
|
-
else if (operation === 'get') {
|
|
406
|
-
const id = this.getNodeParameter('leadId', i);
|
|
407
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/leads/${id}`);
|
|
408
|
-
}
|
|
409
|
-
else if (operation === 'create') {
|
|
410
|
-
const name = this.getNodeParameter('name', i, '');
|
|
411
|
-
const phone = this.getNodeParameter('phone', i, '');
|
|
412
|
-
const email = this.getNodeParameter('email', i, '');
|
|
413
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
414
|
-
const body = { name, phone, email, ...extra };
|
|
415
|
-
if (extra.tagIds)
|
|
416
|
-
body.tagIds = extra.tagIds.split(',').map((s) => s.trim());
|
|
417
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/leads', body);
|
|
418
|
-
}
|
|
419
|
-
else if (operation === 'createWithAdditionalFields') {
|
|
420
|
-
const name = this.getNodeParameter('name', i, '');
|
|
421
|
-
const phone = this.getNodeParameter('phone', i, '');
|
|
422
|
-
const email = this.getNodeParameter('email', i, '');
|
|
423
|
-
const leadJson = this.getNodeParameter('leadJson', i, '{}');
|
|
424
|
-
const parsed = typeof leadJson === 'string' ? JSON.parse(leadJson) : leadJson;
|
|
425
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/leads/additional-fields', { name, phone, email, ...parsed });
|
|
426
|
-
}
|
|
427
|
-
else if (operation === 'update') {
|
|
428
|
-
const id = this.getNodeParameter('leadId', i);
|
|
429
|
-
const name = this.getNodeParameter('name', i, '');
|
|
430
|
-
const phone = this.getNodeParameter('phone', i, '');
|
|
431
|
-
const email = this.getNodeParameter('email', i, '');
|
|
432
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
433
|
-
const body = {};
|
|
434
|
-
if (name)
|
|
435
|
-
body.name = name;
|
|
436
|
-
if (phone)
|
|
437
|
-
body.phone = phone;
|
|
438
|
-
if (email)
|
|
439
|
-
body.email = email;
|
|
440
|
-
if (extra.tagIds)
|
|
441
|
-
extra.tagIds = extra.tagIds.split(',').map((s) => s.trim());
|
|
442
|
-
Object.assign(body, extra);
|
|
443
|
-
responseData = await makeRequest.call(this, baseUrl, 'PATCH', `/api/v1/leads/${id}`, body);
|
|
444
|
-
}
|
|
445
|
-
else if (operation === 'delete') {
|
|
446
|
-
const id = this.getNodeParameter('leadId', i);
|
|
447
|
-
responseData = await makeRequest.call(this, baseUrl, 'DELETE', `/api/v1/leads/${id}`);
|
|
448
|
-
}
|
|
191
|
+
responseData = await lead_handler_1.executeLead.call(this, operation, baseUrl, i);
|
|
449
192
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
// ============================================================
|
|
453
|
-
else if (resource === 'leadBusiness') {
|
|
454
|
-
const leadId = this.getNodeParameter('leadId', i);
|
|
455
|
-
const opts = this.getNodeParameter('queryOptions', i, {});
|
|
456
|
-
const qs = {};
|
|
457
|
-
if (opts.search)
|
|
458
|
-
qs.search = opts.search;
|
|
459
|
-
if (opts.skip !== undefined)
|
|
460
|
-
qs.skip = opts.skip;
|
|
461
|
-
if (opts.take !== undefined)
|
|
462
|
-
qs.take = opts.take;
|
|
463
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/leads/${leadId}/businesses`, undefined, qs);
|
|
193
|
+
else if (['leadBusiness', 'leadAttachment', 'leadNote', 'leadHistory', 'leadActivity'].includes(resource)) {
|
|
194
|
+
responseData = await leadSubResources_handler_1.executeLeadSubResource.call(this, resource, operation, baseUrl, i);
|
|
464
195
|
}
|
|
465
|
-
// ============================================================
|
|
466
|
-
// ANEXOS DO LEAD
|
|
467
|
-
// ============================================================
|
|
468
|
-
else if (resource === 'leadAttachment') {
|
|
469
|
-
const leadId = this.getNodeParameter('leadId', i);
|
|
470
|
-
if (operation === 'getAll') {
|
|
471
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/leads/${leadId}/attachments`);
|
|
472
|
-
}
|
|
473
|
-
else if (operation === 'create') {
|
|
474
|
-
const url = this.getNodeParameter('url', i);
|
|
475
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
476
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', `/api/v1/leads/${leadId}/attachments`, { url, ...extra });
|
|
477
|
-
}
|
|
478
|
-
else if (operation === 'delete') {
|
|
479
|
-
const attachmentId = this.getNodeParameter('attachmentId', i);
|
|
480
|
-
responseData = await makeRequest.call(this, baseUrl, 'DELETE', `/api/v1/leads/${leadId}/attachments/${attachmentId}`);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
// ============================================================
|
|
484
|
-
// ANOTAÇÕES DO LEAD
|
|
485
|
-
// ============================================================
|
|
486
|
-
else if (resource === 'leadNote') {
|
|
487
|
-
const leadId = this.getNodeParameter('leadId', i);
|
|
488
|
-
if (operation === 'getAll') {
|
|
489
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/leads/${leadId}/notes`);
|
|
490
|
-
}
|
|
491
|
-
else if (operation === 'create') {
|
|
492
|
-
const content = this.getNodeParameter('content', i);
|
|
493
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', `/api/v1/leads/${leadId}/notes`, { content });
|
|
494
|
-
}
|
|
495
|
-
else if (operation === 'update') {
|
|
496
|
-
const noteId = this.getNodeParameter('noteId', i);
|
|
497
|
-
const content = this.getNodeParameter('content', i);
|
|
498
|
-
responseData = await makeRequest.call(this, baseUrl, 'PUT', `/api/v1/leads/${leadId}/notes/${noteId}`, { content });
|
|
499
|
-
}
|
|
500
|
-
else if (operation === 'delete') {
|
|
501
|
-
const noteId = this.getNodeParameter('noteId', i);
|
|
502
|
-
responseData = await makeRequest.call(this, baseUrl, 'DELETE', `/api/v1/leads/${leadId}/notes/${noteId}`);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
// ============================================================
|
|
506
|
-
// HISTÓRICO DO LEAD
|
|
507
|
-
// ============================================================
|
|
508
|
-
else if (resource === 'leadHistory') {
|
|
509
|
-
const leadId = this.getNodeParameter('leadId', i);
|
|
510
|
-
const opts = this.getNodeParameter('queryOptions', i, {});
|
|
511
|
-
const qs = {};
|
|
512
|
-
if (opts.search)
|
|
513
|
-
qs.search = opts.search;
|
|
514
|
-
if (opts.skip !== undefined)
|
|
515
|
-
qs.skip = opts.skip;
|
|
516
|
-
if (opts.take !== undefined)
|
|
517
|
-
qs.take = opts.take;
|
|
518
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/leads/${leadId}/history`, undefined, qs);
|
|
519
|
-
}
|
|
520
|
-
// ============================================================
|
|
521
|
-
// ATIVIDADES DO LEAD
|
|
522
|
-
// ============================================================
|
|
523
|
-
else if (resource === 'leadActivity') {
|
|
524
|
-
const leadId = this.getNodeParameter('leadId', i);
|
|
525
|
-
const opts = this.getNodeParameter('queryOptions', i, {});
|
|
526
|
-
const qs = {};
|
|
527
|
-
if (opts.search)
|
|
528
|
-
qs.search = opts.search;
|
|
529
|
-
if (opts.skip !== undefined)
|
|
530
|
-
qs.skip = opts.skip;
|
|
531
|
-
if (opts.take !== undefined)
|
|
532
|
-
qs.take = opts.take;
|
|
533
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/leads/${leadId}/activities`, undefined, qs);
|
|
534
|
-
}
|
|
535
|
-
// ============================================================
|
|
536
|
-
// NEGÓCIOS
|
|
537
|
-
// ============================================================
|
|
538
196
|
else if (resource === 'business') {
|
|
539
|
-
|
|
540
|
-
const opts = this.getNodeParameter('queryOptions', i, {});
|
|
541
|
-
const qs = {};
|
|
542
|
-
if (opts.search)
|
|
543
|
-
qs.search = opts.search;
|
|
544
|
-
if (opts.skip !== undefined)
|
|
545
|
-
qs.skip = opts.skip;
|
|
546
|
-
if (opts.take !== undefined)
|
|
547
|
-
qs.take = opts.take;
|
|
548
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/businesses', undefined, qs);
|
|
549
|
-
}
|
|
550
|
-
else if (operation === 'get') {
|
|
551
|
-
const id = this.getNodeParameter('businessId', i);
|
|
552
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/businesses/${id}`);
|
|
553
|
-
}
|
|
554
|
-
else if (operation === 'create') {
|
|
555
|
-
const leadId = this.getNodeParameter('leadId', i);
|
|
556
|
-
const stageId = this.getNodeParameter('stageId', i);
|
|
557
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
558
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/businesses', { leadId, stageId, ...extra });
|
|
559
|
-
}
|
|
560
|
-
else if (operation === 'update') {
|
|
561
|
-
const id = this.getNodeParameter('businessId', i);
|
|
562
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
563
|
-
responseData = await makeRequest.call(this, baseUrl, 'PATCH', `/api/v1/businesses/${id}`, extra);
|
|
564
|
-
}
|
|
565
|
-
else if (operation === 'delete') {
|
|
566
|
-
const id = this.getNodeParameter('businessId', i);
|
|
567
|
-
responseData = await makeRequest.call(this, baseUrl, 'DELETE', `/api/v1/businesses/${id}`);
|
|
568
|
-
}
|
|
197
|
+
responseData = await business_handler_1.executeBusiness.call(this, operation, baseUrl, i);
|
|
569
198
|
}
|
|
570
|
-
// ============================================================
|
|
571
|
-
// AÇÕES DE NEGÓCIO
|
|
572
|
-
// ============================================================
|
|
573
199
|
else if (resource === 'businessAction') {
|
|
574
|
-
|
|
575
|
-
const businessIds = typeof rawIds === 'string' ? JSON.parse(rawIds) : rawIds;
|
|
576
|
-
if (operation === 'move') {
|
|
577
|
-
const stageId = this.getNodeParameter('stageId', i);
|
|
578
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/businesses/actions/move', { businessIds, stageId });
|
|
579
|
-
}
|
|
580
|
-
else if (operation === 'win') {
|
|
581
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/businesses/actions/win', { businessIds });
|
|
582
|
-
}
|
|
583
|
-
else if (operation === 'lose') {
|
|
584
|
-
const lossReasonId = this.getNodeParameter('lossReasonId', i, '');
|
|
585
|
-
const body = { businessIds };
|
|
586
|
-
if (lossReasonId)
|
|
587
|
-
body.lossReasonId = lossReasonId;
|
|
588
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/businesses/actions/lose', body);
|
|
589
|
-
}
|
|
590
|
-
else if (operation === 'restore') {
|
|
591
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/businesses/actions/restore', { businessIds });
|
|
592
|
-
}
|
|
200
|
+
responseData = await businessAction_handler_1.executeBusinessAction.call(this, operation, baseUrl, i);
|
|
593
201
|
}
|
|
594
|
-
// ============================================================
|
|
595
|
-
// MOTIVOS DE PERDA
|
|
596
|
-
// ============================================================
|
|
597
202
|
else if (resource === 'businessLossReason') {
|
|
598
|
-
|
|
599
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/business-loss-reasons');
|
|
600
|
-
}
|
|
601
|
-
else if (operation === 'get') {
|
|
602
|
-
const id = this.getNodeParameter('lossReasonId', i);
|
|
603
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/business-loss-reasons/${id}`);
|
|
604
|
-
}
|
|
605
|
-
else if (operation === 'create') {
|
|
606
|
-
const name = this.getNodeParameter('name', i);
|
|
607
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/business-loss-reasons', { name });
|
|
608
|
-
}
|
|
609
|
-
else if (operation === 'update') {
|
|
610
|
-
const id = this.getNodeParameter('lossReasonId', i);
|
|
611
|
-
const name = this.getNodeParameter('name', i);
|
|
612
|
-
responseData = await makeRequest.call(this, baseUrl, 'PUT', `/api/v1/business-loss-reasons/${id}`, { name });
|
|
613
|
-
}
|
|
614
|
-
else if (operation === 'delete') {
|
|
615
|
-
const id = this.getNodeParameter('lossReasonId', i);
|
|
616
|
-
responseData = await makeRequest.call(this, baseUrl, 'DELETE', `/api/v1/business-loss-reasons/${id}`);
|
|
617
|
-
}
|
|
203
|
+
responseData = await businessLossReason_handler_1.executeBusinessLossReason.call(this, operation, baseUrl, i);
|
|
618
204
|
}
|
|
619
|
-
// ============================================================
|
|
620
|
-
// TAGS
|
|
621
|
-
// ============================================================
|
|
622
205
|
else if (resource === 'tag') {
|
|
623
|
-
|
|
624
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/tags');
|
|
625
|
-
}
|
|
626
|
-
else if (operation === 'get') {
|
|
627
|
-
const id = this.getNodeParameter('tagId', i);
|
|
628
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/tags/${id}`);
|
|
629
|
-
}
|
|
630
|
-
else if (operation === 'create') {
|
|
631
|
-
const name = this.getNodeParameter('name', i);
|
|
632
|
-
const color = this.getNodeParameter('color', i, '#0000FF');
|
|
633
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/tags', { name, color });
|
|
634
|
-
}
|
|
635
|
-
else if (operation === 'update') {
|
|
636
|
-
const id = this.getNodeParameter('tagId', i);
|
|
637
|
-
const name = this.getNodeParameter('name', i);
|
|
638
|
-
const color = this.getNodeParameter('color', i, '#0000FF');
|
|
639
|
-
responseData = await makeRequest.call(this, baseUrl, 'PUT', `/api/v1/tags/${id}`, { name, color });
|
|
640
|
-
}
|
|
641
|
-
else if (operation === 'delete') {
|
|
642
|
-
const id = this.getNodeParameter('tagId', i);
|
|
643
|
-
responseData = await makeRequest.call(this, baseUrl, 'DELETE', `/api/v1/tags/${id}`);
|
|
644
|
-
}
|
|
206
|
+
responseData = await tag_handler_1.executeTag.call(this, operation, baseUrl, i);
|
|
645
207
|
}
|
|
646
|
-
// ============================================================
|
|
647
|
-
// LISTAS
|
|
648
|
-
// ============================================================
|
|
649
208
|
else if (resource === 'list') {
|
|
650
|
-
|
|
651
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/lists');
|
|
652
|
-
}
|
|
653
|
-
else if (operation === 'get') {
|
|
654
|
-
const id = this.getNodeParameter('listId', i);
|
|
655
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/lists/${id}`);
|
|
656
|
-
}
|
|
657
|
-
else if (operation === 'create') {
|
|
658
|
-
const name = this.getNodeParameter('name', i);
|
|
659
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
660
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/lists', { name, ...extra });
|
|
661
|
-
}
|
|
662
|
-
else if (operation === 'update') {
|
|
663
|
-
const id = this.getNodeParameter('listId', i);
|
|
664
|
-
const name = this.getNodeParameter('name', i);
|
|
665
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
666
|
-
responseData = await makeRequest.call(this, baseUrl, 'PUT', `/api/v1/lists/${id}`, { name, ...extra });
|
|
667
|
-
}
|
|
668
|
-
else if (operation === 'delete') {
|
|
669
|
-
const id = this.getNodeParameter('listId', i);
|
|
670
|
-
responseData = await makeRequest.call(this, baseUrl, 'DELETE', `/api/v1/lists/${id}`);
|
|
671
|
-
}
|
|
209
|
+
responseData = await list_handler_1.executeList.call(this, operation, baseUrl, i);
|
|
672
210
|
}
|
|
673
|
-
// ============================================================
|
|
674
|
-
// PRODUTOS
|
|
675
|
-
// ============================================================
|
|
676
211
|
else if (resource === 'product') {
|
|
677
|
-
|
|
678
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/products');
|
|
679
|
-
}
|
|
680
|
-
else if (operation === 'get') {
|
|
681
|
-
const id = this.getNodeParameter('productId', i);
|
|
682
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/products/${id}`);
|
|
683
|
-
}
|
|
684
|
-
else if (operation === 'create') {
|
|
685
|
-
const name = this.getNodeParameter('name', i);
|
|
686
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
687
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/products', { name, ...extra });
|
|
688
|
-
}
|
|
689
|
-
else if (operation === 'update') {
|
|
690
|
-
const id = this.getNodeParameter('productId', i);
|
|
691
|
-
const name = this.getNodeParameter('name', i);
|
|
692
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
693
|
-
responseData = await makeRequest.call(this, baseUrl, 'PUT', `/api/v1/products/${id}`, { name, ...extra });
|
|
694
|
-
}
|
|
695
|
-
else if (operation === 'delete') {
|
|
696
|
-
const id = this.getNodeParameter('productId', i);
|
|
697
|
-
responseData = await makeRequest.call(this, baseUrl, 'DELETE', `/api/v1/products/${id}`);
|
|
698
|
-
}
|
|
212
|
+
responseData = await product_handler_1.executeProduct.call(this, operation, baseUrl, i);
|
|
699
213
|
}
|
|
700
|
-
// ============================================================
|
|
701
|
-
// ATIVIDADES
|
|
702
|
-
// ============================================================
|
|
703
214
|
else if (resource === 'activity') {
|
|
704
|
-
|
|
705
|
-
const opts = this.getNodeParameter('queryOptions', i, {});
|
|
706
|
-
const qs = {};
|
|
707
|
-
if (opts.search)
|
|
708
|
-
qs.search = opts.search;
|
|
709
|
-
if (opts.skip !== undefined)
|
|
710
|
-
qs.skip = opts.skip;
|
|
711
|
-
if (opts.take !== undefined)
|
|
712
|
-
qs.take = opts.take;
|
|
713
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/activities', undefined, qs);
|
|
714
|
-
}
|
|
715
|
-
else if (operation === 'get') {
|
|
716
|
-
const id = this.getNodeParameter('activityId', i);
|
|
717
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/activities/${id}`);
|
|
718
|
-
}
|
|
719
|
-
else if (operation === 'create') {
|
|
720
|
-
const title = this.getNodeParameter('title', i);
|
|
721
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
722
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', '/api/v1/activities', { title, ...extra });
|
|
723
|
-
}
|
|
724
|
-
else if (operation === 'update') {
|
|
725
|
-
const id = this.getNodeParameter('activityId', i);
|
|
726
|
-
const title = this.getNodeParameter('title', i);
|
|
727
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
728
|
-
responseData = await makeRequest.call(this, baseUrl, 'PATCH', `/api/v1/activities/${id}`, { title, ...extra });
|
|
729
|
-
}
|
|
730
|
-
else if (operation === 'delete') {
|
|
731
|
-
const id = this.getNodeParameter('activityId', i);
|
|
732
|
-
responseData = await makeRequest.call(this, baseUrl, 'DELETE', `/api/v1/activities/${id}`);
|
|
733
|
-
}
|
|
215
|
+
responseData = await activity_handler_1.executeActivity.call(this, operation, baseUrl, i);
|
|
734
216
|
}
|
|
735
|
-
// ============================================================
|
|
736
|
-
// CONVERSAS
|
|
737
|
-
// ============================================================
|
|
738
217
|
else if (resource === 'conversation') {
|
|
739
|
-
|
|
740
|
-
const opts = this.getNodeParameter('queryOptions', i, {});
|
|
741
|
-
const qs = {};
|
|
742
|
-
if (opts.search)
|
|
743
|
-
qs.search = opts.search;
|
|
744
|
-
if (opts.skip !== undefined)
|
|
745
|
-
qs.skip = opts.skip;
|
|
746
|
-
if (opts.take !== undefined)
|
|
747
|
-
qs.take = opts.take;
|
|
748
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/conversations', undefined, qs);
|
|
749
|
-
}
|
|
750
|
-
else if (operation === 'getMessages') {
|
|
751
|
-
const id = this.getNodeParameter('conversationId', i);
|
|
752
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/conversations/${id}/messages`);
|
|
753
|
-
}
|
|
754
|
-
else if (operation === 'sendMessage') {
|
|
755
|
-
const id = this.getNodeParameter('conversationId', i);
|
|
756
|
-
const message = this.getNodeParameter('message', i);
|
|
757
|
-
const extra = this.getNodeParameter('additionalFields', i, {});
|
|
758
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', `/api/v1/conversations/${id}/messages`, { message, ...extra });
|
|
759
|
-
}
|
|
760
|
-
else if (operation === 'finish') {
|
|
761
|
-
const id = this.getNodeParameter('conversationId', i);
|
|
762
|
-
responseData = await makeRequest.call(this, baseUrl, 'POST', `/api/v1/conversations/${id}/finish`);
|
|
763
|
-
}
|
|
218
|
+
responseData = await conversation_handler_1.executeConversation.call(this, operation, baseUrl, i);
|
|
764
219
|
}
|
|
765
|
-
// ============================================================
|
|
766
|
-
// INSTÂNCIAS
|
|
767
|
-
// ============================================================
|
|
768
220
|
else if (resource === 'instance') {
|
|
769
|
-
|
|
770
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/instances');
|
|
771
|
-
}
|
|
772
|
-
else if (operation === 'get') {
|
|
773
|
-
const id = this.getNodeParameter('instanceId', i);
|
|
774
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/instances/${id}`);
|
|
775
|
-
}
|
|
221
|
+
responseData = await instance_handler_1.executeInstance.call(this, operation, baseUrl, i);
|
|
776
222
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
// ============================================================
|
|
780
|
-
else if (resource === 'attendantMulti') {
|
|
781
|
-
if (operation === 'getAll') {
|
|
782
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/attendants/multi');
|
|
783
|
-
}
|
|
784
|
-
else if (operation === 'get') {
|
|
785
|
-
const id = this.getNodeParameter('attendantId', i);
|
|
786
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/attendants/multi/${id}`);
|
|
787
|
-
}
|
|
223
|
+
else if (resource === 'attendantCrm' || resource === 'attendantMulti') {
|
|
224
|
+
responseData = await attendant_handler_1.executeAttendant.call(this, resource, operation, baseUrl, i);
|
|
788
225
|
}
|
|
789
|
-
// ============================================================
|
|
790
|
-
// ATENDENTES CRM
|
|
791
|
-
// ============================================================
|
|
792
|
-
else if (resource === 'attendantCrm') {
|
|
793
|
-
if (operation === 'getAll') {
|
|
794
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/attendants/crm');
|
|
795
|
-
}
|
|
796
|
-
else if (operation === 'get') {
|
|
797
|
-
const id = this.getNodeParameter('attendantId', i);
|
|
798
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/attendants/crm/${id}`);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
// ============================================================
|
|
802
|
-
// PIPELINES
|
|
803
|
-
// ============================================================
|
|
804
226
|
else if (resource === 'pipeline') {
|
|
805
|
-
|
|
806
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', '/api/v1/pipelines');
|
|
807
|
-
}
|
|
808
|
-
else if (operation === 'get') {
|
|
809
|
-
const id = this.getNodeParameter('pipelineId', i);
|
|
810
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/pipelines/${id}`);
|
|
811
|
-
}
|
|
812
|
-
else if (operation === 'getStages') {
|
|
813
|
-
const id = this.getNodeParameter('pipelineId', i);
|
|
814
|
-
responseData = await makeRequest.call(this, baseUrl, 'GET', `/api/v1/pipelines/${id}/stages`);
|
|
815
|
-
}
|
|
227
|
+
responseData = await pipeline_handler_1.executePipeline.call(this, operation, baseUrl, i);
|
|
816
228
|
}
|
|
817
229
|
else {
|
|
818
230
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Recurso "${resource}" não encontrado.`);
|
|
@@ -832,16 +244,4 @@ class Datacrazy {
|
|
|
832
244
|
}
|
|
833
245
|
}
|
|
834
246
|
exports.Datacrazy = Datacrazy;
|
|
835
|
-
async function makeRequest(baseUrl, method, path, body, qs) {
|
|
836
|
-
const options = {
|
|
837
|
-
method,
|
|
838
|
-
url: `${baseUrl}${path}`,
|
|
839
|
-
json: true,
|
|
840
|
-
};
|
|
841
|
-
if (body && Object.keys(body).length > 0)
|
|
842
|
-
options.body = body;
|
|
843
|
-
if (qs && Object.keys(qs).length > 0)
|
|
844
|
-
options.qs = qs;
|
|
845
|
-
return this.helpers.httpRequestWithAuthentication.call(this, 'datacrazyApi', options);
|
|
846
|
-
}
|
|
847
247
|
//# sourceMappingURL=Datacrazy.node.js.map
|