@growsalesai/n8n-nodes-sendflow 0.1.0 → 0.1.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/Sendflow/Sendflow.node.d.ts +10 -1
- package/dist/nodes/Sendflow/Sendflow.node.js +548 -58
- package/dist/nodes/Sendflow/Sendflow.node.js.map +1 -1
- package/dist/nodes/Sendflow/descriptions/AccountDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/AccountDescription.js +92 -0
- package/dist/nodes/Sendflow/descriptions/AccountDescription.js.map +1 -0
- package/dist/nodes/Sendflow/descriptions/ActionDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/ActionDescription.js +524 -0
- package/dist/nodes/Sendflow/descriptions/ActionDescription.js.map +1 -0
- package/dist/nodes/Sendflow/descriptions/AnalyticsDescription.js +10 -24
- package/dist/nodes/Sendflow/descriptions/AnalyticsDescription.js.map +1 -1
- package/dist/nodes/Sendflow/descriptions/BlockNumberDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/BlockNumberDescription.js +38 -0
- package/dist/nodes/Sendflow/descriptions/BlockNumberDescription.js.map +1 -0
- package/dist/nodes/Sendflow/descriptions/CampaignDescription.js +46 -219
- package/dist/nodes/Sendflow/descriptions/CampaignDescription.js.map +1 -1
- package/dist/nodes/Sendflow/descriptions/DirectMessageDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/DirectMessageDescription.js +127 -0
- package/dist/nodes/Sendflow/descriptions/DirectMessageDescription.js.map +1 -0
- package/dist/nodes/Sendflow/descriptions/GroupDescription.js +7 -8
- package/dist/nodes/Sendflow/descriptions/GroupDescription.js.map +1 -1
- package/dist/nodes/Sendflow/descriptions/MediaDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/MediaDescription.js +33 -0
- package/dist/nodes/Sendflow/descriptions/MediaDescription.js.map +1 -0
- package/dist/nodes/Sendflow/descriptions/MessageTemplateDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/MessageTemplateDescription.js +94 -0
- package/dist/nodes/Sendflow/descriptions/MessageTemplateDescription.js.map +1 -0
- package/dist/nodes/Sendflow/descriptions/ReleaseGroupDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/ReleaseGroupDescription.js +96 -0
- package/dist/nodes/Sendflow/descriptions/ReleaseGroupDescription.js.map +1 -0
- package/dist/nodes/Sendflow/descriptions/VariableDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/VariableDescription.js +147 -0
- package/dist/nodes/Sendflow/descriptions/VariableDescription.js.map +1 -0
- package/dist/nodes/Sendflow/descriptions/VerificationDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/VerificationDescription.js +45 -0
- package/dist/nodes/Sendflow/descriptions/VerificationDescription.js.map +1 -0
- package/dist/nodes/Sendflow/descriptions/index.d.ts +10 -1
- package/dist/nodes/Sendflow/descriptions/index.js +31 -4
- package/dist/nodes/Sendflow/descriptions/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -13,17 +13,10 @@ class Sendflow {
|
|
|
13
13
|
version: 1,
|
|
14
14
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
15
15
|
description: 'Gerencie campanhas WhatsApp via SendFlow API',
|
|
16
|
-
defaults: {
|
|
17
|
-
name: 'SendFlow',
|
|
18
|
-
},
|
|
16
|
+
defaults: { name: 'SendFlow' },
|
|
19
17
|
inputs: ['main'],
|
|
20
18
|
outputs: ['main'],
|
|
21
|
-
credentials: [
|
|
22
|
-
{
|
|
23
|
-
name: 'sendflowApi',
|
|
24
|
-
required: true,
|
|
25
|
-
},
|
|
26
|
-
],
|
|
19
|
+
credentials: [{ name: 'sendflowApi', required: true }],
|
|
27
20
|
properties: [
|
|
28
21
|
{
|
|
29
22
|
displayName: 'Resource',
|
|
@@ -31,20 +24,98 @@ class Sendflow {
|
|
|
31
24
|
type: 'options',
|
|
32
25
|
noDataExpression: true,
|
|
33
26
|
options: [
|
|
27
|
+
{ name: 'Account', value: 'account' },
|
|
28
|
+
{ name: 'Action', value: 'action' },
|
|
34
29
|
{ name: 'Analytics', value: 'analytics' },
|
|
30
|
+
{ name: 'Block Number', value: 'blockNumber' },
|
|
35
31
|
{ name: 'Campaign', value: 'campaign' },
|
|
32
|
+
{ name: 'Campaign Group (Release Group)', value: 'releaseGroup' },
|
|
33
|
+
{ name: 'Direct Message', value: 'directMessage' },
|
|
36
34
|
{ name: 'Group', value: 'group' },
|
|
35
|
+
{ name: 'Media', value: 'media' },
|
|
36
|
+
{ name: 'Message Template', value: 'messageTemplate' },
|
|
37
|
+
{ name: 'Variable', value: 'variable' },
|
|
38
|
+
{ name: 'Verification', value: 'verification' },
|
|
37
39
|
],
|
|
38
40
|
default: 'campaign',
|
|
39
41
|
},
|
|
42
|
+
...descriptions_1.accountOperations,
|
|
43
|
+
...descriptions_1.accountFields,
|
|
44
|
+
...descriptions_1.actionOperations,
|
|
45
|
+
...descriptions_1.actionFields,
|
|
46
|
+
...descriptions_1.analyticsOperations,
|
|
47
|
+
...descriptions_1.analyticsFields,
|
|
48
|
+
...descriptions_1.blockNumberOperations,
|
|
49
|
+
...descriptions_1.blockNumberFields,
|
|
40
50
|
...descriptions_1.campaignOperations,
|
|
41
51
|
...descriptions_1.campaignFields,
|
|
52
|
+
...descriptions_1.releaseGroupOperations,
|
|
53
|
+
...descriptions_1.releaseGroupFields,
|
|
54
|
+
...descriptions_1.directMessageOperations,
|
|
55
|
+
...descriptions_1.directMessageFields,
|
|
42
56
|
...descriptions_1.groupOperations,
|
|
43
57
|
...descriptions_1.groupFields,
|
|
44
|
-
...descriptions_1.
|
|
45
|
-
...descriptions_1.
|
|
58
|
+
...descriptions_1.mediaOperations,
|
|
59
|
+
...descriptions_1.mediaFields,
|
|
60
|
+
...descriptions_1.messageTemplateOperations,
|
|
61
|
+
...descriptions_1.messageTemplateFields,
|
|
62
|
+
...descriptions_1.variableOperations,
|
|
63
|
+
...descriptions_1.variableFields,
|
|
64
|
+
...descriptions_1.verificationOperations,
|
|
65
|
+
...descriptions_1.verificationFields,
|
|
46
66
|
],
|
|
47
67
|
};
|
|
68
|
+
this.methods = {
|
|
69
|
+
loadOptions: {
|
|
70
|
+
async getCampaigns() {
|
|
71
|
+
const response = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/releases');
|
|
72
|
+
const campaigns = Array.isArray(response) ? response : [];
|
|
73
|
+
return campaigns.map((c) => ({
|
|
74
|
+
name: c.name,
|
|
75
|
+
value: c.id,
|
|
76
|
+
}));
|
|
77
|
+
},
|
|
78
|
+
async getAccounts() {
|
|
79
|
+
const response = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/accounts');
|
|
80
|
+
const accounts = Array.isArray(response) ? response : [];
|
|
81
|
+
return accounts.map((a) => {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
const data = ((_a = a.data) !== null && _a !== void 0 ? _a : a);
|
|
84
|
+
return {
|
|
85
|
+
name: ((_b = data.name) !== null && _b !== void 0 ? _b : a.id),
|
|
86
|
+
value: a.id,
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
async getMessageTemplates() {
|
|
91
|
+
const response = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/message-templates');
|
|
92
|
+
const templates = Array.isArray(response) ? response : [];
|
|
93
|
+
return templates.map((t) => ({
|
|
94
|
+
name: t.title,
|
|
95
|
+
value: t.id,
|
|
96
|
+
}));
|
|
97
|
+
},
|
|
98
|
+
async getVariables() {
|
|
99
|
+
const response = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/variables');
|
|
100
|
+
const list = Array.isArray(response === null || response === void 0 ? void 0 : response.data) ? response.data : [];
|
|
101
|
+
return list.map((v) => ({
|
|
102
|
+
name: v.name,
|
|
103
|
+
value: v.id,
|
|
104
|
+
}));
|
|
105
|
+
},
|
|
106
|
+
async getReleaseGroupsForCampaign() {
|
|
107
|
+
const releaseId = this.getCurrentNodeParameter('releaseId');
|
|
108
|
+
if (!releaseId)
|
|
109
|
+
return [];
|
|
110
|
+
const response = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/groups`);
|
|
111
|
+
const groups = Array.isArray(response) ? response : [];
|
|
112
|
+
return groups.map((g) => ({
|
|
113
|
+
name: g.name,
|
|
114
|
+
value: g.id,
|
|
115
|
+
}));
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
};
|
|
48
119
|
}
|
|
49
120
|
async execute() {
|
|
50
121
|
const items = this.getInputData();
|
|
@@ -62,6 +133,33 @@ class Sendflow {
|
|
|
62
133
|
else if (resource === 'analytics') {
|
|
63
134
|
await executeAnalytics.call(this, operation, i, returnData);
|
|
64
135
|
}
|
|
136
|
+
else if (resource === 'account') {
|
|
137
|
+
await executeAccount.call(this, operation, i, returnData);
|
|
138
|
+
}
|
|
139
|
+
else if (resource === 'action') {
|
|
140
|
+
await executeAction.call(this, operation, i, returnData);
|
|
141
|
+
}
|
|
142
|
+
else if (resource === 'blockNumber') {
|
|
143
|
+
await executeBlockNumber.call(this, operation, i, returnData);
|
|
144
|
+
}
|
|
145
|
+
else if (resource === 'directMessage') {
|
|
146
|
+
await executeDirectMessage.call(this, operation, i, returnData);
|
|
147
|
+
}
|
|
148
|
+
else if (resource === 'media') {
|
|
149
|
+
await executeMedia.call(this, operation, i, returnData);
|
|
150
|
+
}
|
|
151
|
+
else if (resource === 'messageTemplate') {
|
|
152
|
+
await executeMessageTemplate.call(this, operation, i, returnData);
|
|
153
|
+
}
|
|
154
|
+
else if (resource === 'releaseGroup') {
|
|
155
|
+
await executeReleaseGroup.call(this, operation, i, returnData);
|
|
156
|
+
}
|
|
157
|
+
else if (resource === 'variable') {
|
|
158
|
+
await executeVariable.call(this, operation, i, returnData);
|
|
159
|
+
}
|
|
160
|
+
else if (resource === 'verification') {
|
|
161
|
+
await executeVerification.call(this, operation, i, returnData);
|
|
162
|
+
}
|
|
65
163
|
}
|
|
66
164
|
catch (error) {
|
|
67
165
|
if (this.continueOnFail()) {
|
|
@@ -75,59 +173,70 @@ class Sendflow {
|
|
|
75
173
|
}
|
|
76
174
|
}
|
|
77
175
|
exports.Sendflow = Sendflow;
|
|
78
|
-
// ───
|
|
176
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
+
function parseJsonField(value) {
|
|
179
|
+
if (typeof value === 'string') {
|
|
180
|
+
try {
|
|
181
|
+
return JSON.parse(value);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
function buildShippingOptions(opts) {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
const options = {};
|
|
192
|
+
if (opts.shippingSpeed)
|
|
193
|
+
options.shippingSpeed = opts.shippingSpeed;
|
|
194
|
+
if (opts.shippingSpeed === 'custom') {
|
|
195
|
+
options.customShippingSpeed = { min: (_a = opts.customSpeedMin) !== null && _a !== void 0 ? _a : 5, max: (_b = opts.customSpeedMax) !== null && _b !== void 0 ? _b : 15 };
|
|
196
|
+
}
|
|
197
|
+
return options;
|
|
198
|
+
}
|
|
199
|
+
// ─── Campaign ─────────────────────────────────────────────────────────────────
|
|
79
200
|
async function executeCampaign(operation, i, returnData) {
|
|
80
201
|
if (operation === 'getAll') {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
returnData.push(...items);
|
|
202
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/releases');
|
|
203
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
84
204
|
return;
|
|
85
205
|
}
|
|
86
206
|
if (operation === 'create') {
|
|
87
207
|
const name = this.getNodeParameter('name', i);
|
|
88
208
|
const type = this.getNodeParameter('type', i);
|
|
89
|
-
const
|
|
209
|
+
const af = this.getNodeParameter('additionalFields', i);
|
|
90
210
|
const body = { name, type };
|
|
91
|
-
if (
|
|
92
|
-
body.projectId =
|
|
93
|
-
|
|
94
|
-
returnData.push(response);
|
|
211
|
+
if (af.projectId)
|
|
212
|
+
body.projectId = af.projectId;
|
|
213
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/releases', body));
|
|
95
214
|
return;
|
|
96
215
|
}
|
|
97
216
|
const releaseId = this.getNodeParameter('releaseId', i);
|
|
98
217
|
if (operation === 'get') {
|
|
99
|
-
|
|
100
|
-
returnData.push(response);
|
|
101
|
-
return;
|
|
218
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}`));
|
|
102
219
|
}
|
|
103
|
-
if (operation === 'delete') {
|
|
220
|
+
else if (operation === 'delete') {
|
|
104
221
|
await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/releases/${releaseId}`);
|
|
105
222
|
returnData.push({ success: true, releaseId });
|
|
106
|
-
return;
|
|
107
223
|
}
|
|
108
|
-
if (operation === 'updateRedirectLink') {
|
|
224
|
+
else if (operation === 'updateRedirectLink') {
|
|
109
225
|
const slug = this.getNodeParameter('slug', i);
|
|
110
|
-
|
|
111
|
-
returnData.push(response);
|
|
112
|
-
return;
|
|
226
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PATCH', `/releases/${releaseId}/redirect-link`, { slug }));
|
|
113
227
|
}
|
|
114
|
-
if (operation === 'removeDuplicatedParticipants') {
|
|
115
|
-
|
|
116
|
-
returnData.push(response);
|
|
117
|
-
return;
|
|
228
|
+
else if (operation === 'removeDuplicatedParticipants') {
|
|
229
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/releases/${releaseId}/remove-duplicated-participants`));
|
|
118
230
|
}
|
|
119
|
-
if (operation === 'update') {
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
const body = { ...
|
|
231
|
+
else if (operation === 'update') {
|
|
232
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
233
|
+
const gc = this.getNodeParameter('groupConfig', i);
|
|
234
|
+
const body = { ...uf };
|
|
123
235
|
if (body.accountIds) {
|
|
124
|
-
body.accountIds = body.accountIds
|
|
125
|
-
.split(',')
|
|
126
|
-
.map((s) => s.trim())
|
|
127
|
-
.filter(Boolean);
|
|
236
|
+
body.accountIds = body.accountIds.split(',').map((s) => s.trim()).filter(Boolean);
|
|
128
237
|
}
|
|
129
|
-
if (Object.keys(
|
|
130
|
-
const group = { ...
|
|
238
|
+
if (Object.keys(gc).length) {
|
|
239
|
+
const group = { ...gc };
|
|
131
240
|
if (typeof group.admins === 'string') {
|
|
132
241
|
try {
|
|
133
242
|
group.admins = JSON.parse(group.admins);
|
|
@@ -138,35 +247,416 @@ async function executeCampaign(operation, i, returnData) {
|
|
|
138
247
|
}
|
|
139
248
|
body.group = group;
|
|
140
249
|
}
|
|
141
|
-
|
|
142
|
-
returnData.push(response);
|
|
250
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/releases/${releaseId}`, body));
|
|
143
251
|
}
|
|
144
252
|
}
|
|
145
|
-
// ─── Group
|
|
253
|
+
// ─── Group ────────────────────────────────────────────────────────────────────
|
|
146
254
|
async function executeGroup(operation, i, returnData) {
|
|
147
255
|
if (operation === 'getAll') {
|
|
148
256
|
const releaseId = this.getNodeParameter('releaseId', i);
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
returnData.push(...items);
|
|
257
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/groups`);
|
|
258
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
152
259
|
}
|
|
153
260
|
}
|
|
154
|
-
// ─── Analytics
|
|
261
|
+
// ─── Analytics ────────────────────────────────────────────────────────────────
|
|
155
262
|
async function executeAnalytics(operation, i, returnData) {
|
|
156
263
|
const releaseId = this.getNodeParameter('releaseId', i);
|
|
157
264
|
if (operation === 'get') {
|
|
158
|
-
|
|
159
|
-
|
|
265
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/analytics`));
|
|
266
|
+
}
|
|
267
|
+
else if (operation === 'getLeadScoring') {
|
|
268
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/leadscoring`));
|
|
269
|
+
}
|
|
270
|
+
else if (operation === 'downloadLeadScoring') {
|
|
271
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/leadscoring/download`);
|
|
272
|
+
returnData.push({ downloadUrl: res });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// ─── Account ──────────────────────────────────────────────────────────────────
|
|
276
|
+
async function executeAccount(operation, i, returnData) {
|
|
277
|
+
if (operation === 'getAll') {
|
|
278
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/accounts');
|
|
279
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
160
280
|
return;
|
|
161
281
|
}
|
|
162
|
-
if (operation === '
|
|
163
|
-
const
|
|
164
|
-
|
|
282
|
+
if (operation === 'create') {
|
|
283
|
+
const name = this.getNodeParameter('name', i);
|
|
284
|
+
const type = this.getNodeParameter('type', i);
|
|
285
|
+
const af = this.getNodeParameter('additionalFields', i);
|
|
286
|
+
const body = { data: { name, type } };
|
|
287
|
+
if (af.projectId)
|
|
288
|
+
body.projectId = af.projectId;
|
|
289
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/accounts/create', body));
|
|
165
290
|
return;
|
|
166
291
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
292
|
+
const accountId = this.getNodeParameter('accountId', i);
|
|
293
|
+
if (operation === 'update') {
|
|
294
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
295
|
+
const body = { data: {} };
|
|
296
|
+
if (uf.name)
|
|
297
|
+
body.data.name = uf.name;
|
|
298
|
+
if (uf.type)
|
|
299
|
+
body.data.type = uf.type;
|
|
300
|
+
if (uf.projectId)
|
|
301
|
+
body.projectId = uf.projectId;
|
|
302
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/accounts/${accountId}`, body));
|
|
303
|
+
}
|
|
304
|
+
else if (operation === 'delete') {
|
|
305
|
+
await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/accounts/${accountId}`);
|
|
306
|
+
returnData.push({ success: true, accountId });
|
|
307
|
+
}
|
|
308
|
+
else if (operation === 'connect') {
|
|
309
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/accounts/connect-account/${accountId}`));
|
|
310
|
+
}
|
|
311
|
+
else if (operation === 'disconnect') {
|
|
312
|
+
await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/accounts/disconnect-account/${accountId}`);
|
|
313
|
+
returnData.push({ success: true, accountId });
|
|
314
|
+
}
|
|
315
|
+
else if (operation === 'getQrCode') {
|
|
316
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/accounts/${accountId}/qrcode`));
|
|
317
|
+
}
|
|
318
|
+
else if (operation === 'getQrCodeImage') {
|
|
319
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/accounts/${accountId}/qrcode-image`));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// ─── Action ───────────────────────────────────────────────────────────────────
|
|
323
|
+
async function executeAction(operation, i, returnData) {
|
|
324
|
+
if (operation === 'analyzeGroups') {
|
|
325
|
+
const af = this.getNodeParameter('analyzeFields', i);
|
|
326
|
+
const body = {};
|
|
327
|
+
if (af.accountIds)
|
|
328
|
+
body.accountIds = parseJsonField(af.accountIds);
|
|
329
|
+
if (af.to)
|
|
330
|
+
body.to = af.to;
|
|
331
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/analyze-groups', body));
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (operation === 'findParticipant') {
|
|
335
|
+
const accountId = this.getNodeParameter('accountId', i);
|
|
336
|
+
const phoneNumber = this.getNodeParameter('phoneNumber', i);
|
|
337
|
+
const timeout = this.getNodeParameter('timeout', i);
|
|
338
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/find-participant', { accountId, phoneNumber, timeout }));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const accountId = this.getNodeParameter('accountId', i);
|
|
342
|
+
const releaseId = this.getNodeParameter('releaseId', i);
|
|
343
|
+
if (operation === 'createGroup') {
|
|
344
|
+
const groupName = this.getNodeParameter('groupName', i);
|
|
345
|
+
const participantsRaw = this.getNodeParameter('participants', i);
|
|
346
|
+
const standardization = this.getNodeParameter('standardization', i);
|
|
347
|
+
const participants = participantsRaw.split(',').map((s) => s.trim()).filter(Boolean);
|
|
348
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/group-create', {
|
|
349
|
+
accountId, releaseId, payload: { name: groupName, participants, standardization },
|
|
350
|
+
}));
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (operation === 'makeGroupAdmin') {
|
|
354
|
+
const participants = parseJsonField(this.getNodeParameter('adminParticipants', i));
|
|
355
|
+
const chooseSpecificGroups = this.getNodeParameter('chooseSpecificGroupsAdmin', i);
|
|
356
|
+
const body = { accountId, releaseId, participants, chooseSpecificGroups };
|
|
357
|
+
if (chooseSpecificGroups) {
|
|
358
|
+
const raw = this.getNodeParameter('groupIdsAdmin', i);
|
|
359
|
+
body.groupIds = raw.split(',').map((s) => s.trim()).filter(Boolean);
|
|
360
|
+
}
|
|
361
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/make-group-admin', body));
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (operation === 'sendTextMessage') {
|
|
365
|
+
const messageText = this.getNodeParameter('messageText', i);
|
|
366
|
+
const opts = this.getNodeParameter('textOptions', i);
|
|
367
|
+
const body = { accountId, releaseId, messageText };
|
|
368
|
+
if (opts.accountIds)
|
|
369
|
+
body.accountIds = parseJsonField(opts.accountIds);
|
|
370
|
+
if (opts.linkPreview !== undefined)
|
|
371
|
+
body.linkPreview = opts.linkPreview;
|
|
372
|
+
if (opts.scheduled !== undefined)
|
|
373
|
+
body.scheduled = opts.scheduled;
|
|
374
|
+
if (opts.scheduledTo)
|
|
375
|
+
body.scheduledTo = opts.scheduledTo;
|
|
376
|
+
if (opts.chooseSpecificGroups !== undefined)
|
|
377
|
+
body.chooseSpecificGroups = opts.chooseSpecificGroups;
|
|
378
|
+
if (opts.groupIds)
|
|
379
|
+
body.groupIds = parseJsonField(opts.groupIds);
|
|
380
|
+
const shippingOpts = buildShippingOptions(opts);
|
|
381
|
+
if (Object.keys(shippingOpts).length)
|
|
382
|
+
body.options = shippingOpts;
|
|
383
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-text-message', body));
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (operation === 'sendImageMessage') {
|
|
387
|
+
const url = this.getNodeParameter('imageUrl', i);
|
|
388
|
+
const caption = this.getNodeParameter('imageCaption', i);
|
|
389
|
+
const opts = this.getNodeParameter('imageOptions', i);
|
|
390
|
+
const body = { accountId, releaseId, url, caption };
|
|
391
|
+
applyCommonSendOptions(body, opts);
|
|
392
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-image-message', body));
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (operation === 'sendVideoMessage') {
|
|
396
|
+
const url = this.getNodeParameter('videoUrl', i);
|
|
397
|
+
const caption = this.getNodeParameter('videoCaption', i);
|
|
398
|
+
const opts = this.getNodeParameter('videoOptions', i);
|
|
399
|
+
const body = { accountId, releaseId, url, caption };
|
|
400
|
+
applyCommonSendOptions(body, opts);
|
|
401
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-video-message', body));
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (operation === 'sendAudioMessage') {
|
|
405
|
+
const url = this.getNodeParameter('audioUrl', i);
|
|
406
|
+
const ptt = this.getNodeParameter('ptt', i);
|
|
407
|
+
const opts = this.getNodeParameter('audioOptions', i);
|
|
408
|
+
const body = { accountId, releaseId, url, ptt };
|
|
409
|
+
if (opts.caption)
|
|
410
|
+
body.caption = opts.caption;
|
|
411
|
+
applyCommonSendOptions(body, opts);
|
|
412
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-audio-message', body));
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (operation === 'sendDocumentMessage') {
|
|
416
|
+
const url = this.getNodeParameter('documentUrl', i);
|
|
417
|
+
const fileName = this.getNodeParameter('fileName', i);
|
|
418
|
+
const opts = this.getNodeParameter('documentOptions', i);
|
|
419
|
+
const body = { accountId, releaseId, url, fileName };
|
|
420
|
+
if (opts.caption)
|
|
421
|
+
body.caption = opts.caption;
|
|
422
|
+
applyCommonSendOptions(body, opts);
|
|
423
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-document-message', body));
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (operation === 'sendMessage') {
|
|
427
|
+
const type = this.getNodeParameter('messageType', i);
|
|
428
|
+
const opts = this.getNodeParameter('genericOptions', i);
|
|
429
|
+
const body = { accountId, releaseId, type };
|
|
430
|
+
if (type === 'extendedTextMessage') {
|
|
431
|
+
body.text = this.getNodeParameter('genericText', i);
|
|
432
|
+
if (opts.linkPreview !== undefined)
|
|
433
|
+
body.linkPreview = opts.linkPreview;
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
body.url = this.getNodeParameter('genericUrl', i);
|
|
437
|
+
body.caption = this.getNodeParameter('genericCaption', i);
|
|
438
|
+
if (type === 'documentMessage')
|
|
439
|
+
body.fileName = this.getNodeParameter('genericFileName', i);
|
|
440
|
+
if (type === 'audioMessage')
|
|
441
|
+
body.ptt = this.getNodeParameter('genericPtt', i);
|
|
442
|
+
}
|
|
443
|
+
if (opts.accountIds)
|
|
444
|
+
body.accountIds = parseJsonField(opts.accountIds);
|
|
445
|
+
if (opts.scheduledTo)
|
|
446
|
+
body.scheduledTo = opts.scheduledTo;
|
|
447
|
+
if (opts.chooseSpecificGroups !== undefined)
|
|
448
|
+
body.chooseSpecificGroups = opts.chooseSpecificGroups;
|
|
449
|
+
if (opts.groupIds)
|
|
450
|
+
body.groupIds = parseJsonField(opts.groupIds);
|
|
451
|
+
const msgOptions = buildShippingOptions(opts);
|
|
452
|
+
if (opts.ephemeralExpiration)
|
|
453
|
+
msgOptions.ephemeralExpiration = opts.ephemeralExpiration;
|
|
454
|
+
if (opts.mentionAllParticipants !== undefined)
|
|
455
|
+
msgOptions.mentionAllParticipants = opts.mentionAllParticipants;
|
|
456
|
+
if (Object.keys(msgOptions).length)
|
|
457
|
+
body.options = msgOptions;
|
|
458
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-message', body));
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (operation === 'sendMessages') {
|
|
462
|
+
const accountsFrom = this.getNodeParameter('accountsFrom', i);
|
|
463
|
+
const toType = this.getNodeParameter('toType', i);
|
|
464
|
+
const toIds = parseJsonField(this.getNodeParameter('toIds', i));
|
|
465
|
+
const messages = parseJsonField(this.getNodeParameter('bulkMessages', i));
|
|
466
|
+
const opts = this.getNodeParameter('bulkOptions', i);
|
|
467
|
+
const body = {
|
|
468
|
+
releaseId,
|
|
469
|
+
accountsFrom,
|
|
470
|
+
to: { type: toType, ids: toIds },
|
|
471
|
+
data: { messages },
|
|
472
|
+
};
|
|
473
|
+
if (opts.accounts)
|
|
474
|
+
body.accounts = parseJsonField(opts.accounts);
|
|
475
|
+
if (opts.scheduledTo)
|
|
476
|
+
body.scheduledTo = opts.scheduledTo;
|
|
477
|
+
const shippingOpts = buildShippingOptions(opts);
|
|
478
|
+
if (Object.keys(shippingOpts).length)
|
|
479
|
+
body.options = shippingOpts;
|
|
480
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-messages', body));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function applyCommonSendOptions(body, opts) {
|
|
484
|
+
if (opts.accountIds)
|
|
485
|
+
body.accountIds = parseJsonField(opts.accountIds);
|
|
486
|
+
if (opts.scheduledTo)
|
|
487
|
+
body.scheduledTo = opts.scheduledTo;
|
|
488
|
+
if (opts.chooseSpecificGroups !== undefined)
|
|
489
|
+
body.chooseSpecificGroups = opts.chooseSpecificGroups;
|
|
490
|
+
if (opts.groupIds)
|
|
491
|
+
body.groupIds = parseJsonField(opts.groupIds);
|
|
492
|
+
const shippingOpts = buildShippingOptions(opts);
|
|
493
|
+
if (Object.keys(shippingOpts).length)
|
|
494
|
+
body.options = shippingOpts;
|
|
495
|
+
}
|
|
496
|
+
// ─── Block Number ─────────────────────────────────────────────────────────────
|
|
497
|
+
async function executeBlockNumber(operation, i, returnData) {
|
|
498
|
+
if (operation === 'getAll') {
|
|
499
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/block-numbers');
|
|
500
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
501
|
+
}
|
|
502
|
+
else if (operation === 'create') {
|
|
503
|
+
const number = this.getNodeParameter('number', i);
|
|
504
|
+
const name = this.getNodeParameter('name', i);
|
|
505
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/block-numbers', { number, name }));
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
// ─── Direct Message ───────────────────────────────────────────────────────────
|
|
509
|
+
async function executeDirectMessage(operation, i, returnData) {
|
|
510
|
+
const accountId = this.getNodeParameter('accountId', i);
|
|
511
|
+
const phoneNumber = this.getNodeParameter('phoneNumber', i);
|
|
512
|
+
if (operation === 'sendText') {
|
|
513
|
+
const text = this.getNodeParameter('text', i);
|
|
514
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/send-text-message/${accountId}`, { text, phoneNumber }));
|
|
515
|
+
}
|
|
516
|
+
else if (operation === 'sendImage') {
|
|
517
|
+
const url = this.getNodeParameter('url', i);
|
|
518
|
+
const caption = this.getNodeParameter('captionImage', i);
|
|
519
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/send-image-message/${accountId}`, { url, caption, phoneNumber }));
|
|
520
|
+
}
|
|
521
|
+
else if (operation === 'sendVideo') {
|
|
522
|
+
const url = this.getNodeParameter('urlVideo', i);
|
|
523
|
+
const caption = this.getNodeParameter('captionVideo', i);
|
|
524
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/send-video-message/${accountId}`, { url, caption, phoneNumber }));
|
|
525
|
+
}
|
|
526
|
+
else if (operation === 'sendAudio') {
|
|
527
|
+
const url = this.getNodeParameter('urlAudio', i);
|
|
528
|
+
const caption = this.getNodeParameter('captionAudio', i);
|
|
529
|
+
const ptt = this.getNodeParameter('ptt', i);
|
|
530
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/send-audio-message/${accountId}`, { url, caption, ptt, phoneNumber }));
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
// ─── Media ────────────────────────────────────────────────────────────────────
|
|
534
|
+
async function executeMedia(operation, i, returnData) {
|
|
535
|
+
if (operation === 'generateMediaId') {
|
|
536
|
+
const mediaId = this.getNodeParameter('mediaId', i);
|
|
537
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/generate-media-id', {}, { mediaId }));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
// ─── Message Template ─────────────────────────────────────────────────────────
|
|
541
|
+
async function executeMessageTemplate(operation, i, returnData) {
|
|
542
|
+
if (operation === 'getAll') {
|
|
543
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/message-templates');
|
|
544
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (operation === 'create') {
|
|
548
|
+
const title = this.getNodeParameter('title', i);
|
|
549
|
+
const template = parseJsonField(this.getNodeParameter('template', i));
|
|
550
|
+
const af = this.getNodeParameter('additionalFields', i);
|
|
551
|
+
const body = { title, template };
|
|
552
|
+
if (af.folderId)
|
|
553
|
+
body.folderId = af.folderId;
|
|
554
|
+
if (af.intervalRangeType)
|
|
555
|
+
body.intervalRangeType = af.intervalRangeType;
|
|
556
|
+
if (af.intervalRange)
|
|
557
|
+
body.intervalRange = parseJsonField(af.intervalRange);
|
|
558
|
+
if (af.archived !== undefined)
|
|
559
|
+
body.archived = af.archived;
|
|
560
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/message-templates', body));
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const templateId = this.getNodeParameter('templateId', i);
|
|
564
|
+
if (operation === 'update') {
|
|
565
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
566
|
+
const body = {};
|
|
567
|
+
if (uf.title)
|
|
568
|
+
body.title = uf.title;
|
|
569
|
+
if (uf.template)
|
|
570
|
+
body.template = parseJsonField(uf.template);
|
|
571
|
+
if (uf.folderId !== undefined)
|
|
572
|
+
body.folderId = uf.folderId || null;
|
|
573
|
+
if (uf.intervalRangeType)
|
|
574
|
+
body.intervalRangeType = uf.intervalRangeType;
|
|
575
|
+
if (uf.intervalRange)
|
|
576
|
+
body.intervalRange = parseJsonField(uf.intervalRange);
|
|
577
|
+
if (uf.archived !== undefined)
|
|
578
|
+
body.archived = uf.archived;
|
|
579
|
+
if (uf.position !== undefined)
|
|
580
|
+
body.position = uf.position;
|
|
581
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/message-templates/${templateId}`, body));
|
|
582
|
+
}
|
|
583
|
+
else if (operation === 'delete') {
|
|
584
|
+
await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/message-templates/${templateId}`);
|
|
585
|
+
returnData.push({ success: true, templateId });
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
// ─── Release Group ────────────────────────────────────────────────────────────
|
|
589
|
+
async function executeReleaseGroup(operation, i, returnData) {
|
|
590
|
+
if (operation === 'create') {
|
|
591
|
+
const gid = this.getNodeParameter('gid', i);
|
|
592
|
+
const releaseId = this.getNodeParameter('releaseId', i);
|
|
593
|
+
const name = this.getNodeParameter('name', i);
|
|
594
|
+
const af = this.getNodeParameter('additionalFields', i);
|
|
595
|
+
const body = { gid, releaseId, name, ...af };
|
|
596
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/release-groups', body));
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const releaseGroupId = this.getNodeParameter('releaseGroupId', i);
|
|
600
|
+
if (operation === 'get') {
|
|
601
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/release-groups/${releaseGroupId}`));
|
|
602
|
+
}
|
|
603
|
+
else if (operation === 'update') {
|
|
604
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
605
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/release-groups/${releaseGroupId}`, uf));
|
|
606
|
+
}
|
|
607
|
+
else if (operation === 'delete') {
|
|
608
|
+
await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/release-groups/${releaseGroupId}`);
|
|
609
|
+
returnData.push({ success: true, releaseGroupId });
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
// ─── Variable ─────────────────────────────────────────────────────────────────
|
|
613
|
+
async function executeVariable(operation, i, returnData) {
|
|
614
|
+
if (operation === 'getAll') {
|
|
615
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/variables'));
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
if (operation === 'create') {
|
|
619
|
+
const name = this.getNodeParameter('name', i);
|
|
620
|
+
const type = this.getNodeParameter('type', i);
|
|
621
|
+
const category = this.getNodeParameter('category', i);
|
|
622
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/variables', { name, type, category }));
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (operation === 'update') {
|
|
626
|
+
const variableId = this.getNodeParameter('variableId', i);
|
|
627
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
628
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/variables/${variableId}`, uf));
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
if (operation === 'delete') {
|
|
632
|
+
const variableId = this.getNodeParameter('variableId', i);
|
|
633
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/variables/${variableId}`));
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const releaseId = this.getNodeParameter('releaseId', i);
|
|
637
|
+
if (operation === 'getCampaignValues') {
|
|
638
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/variable-values`));
|
|
639
|
+
}
|
|
640
|
+
else if (operation === 'saveCampaignValues') {
|
|
641
|
+
const items = parseJsonField(this.getNodeParameter('campaignItems', i));
|
|
642
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/releases/${releaseId}/variable-values`, { items }));
|
|
643
|
+
}
|
|
644
|
+
else if (operation === 'getGroupValues') {
|
|
645
|
+
const groupDocId = this.getNodeParameter('groupDocId', i);
|
|
646
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/release-groups/${groupDocId}/variable-values`));
|
|
647
|
+
}
|
|
648
|
+
else if (operation === 'saveGroupValues') {
|
|
649
|
+
const groupDocId = this.getNodeParameter('groupDocId', i);
|
|
650
|
+
const items = parseJsonField(this.getNodeParameter('groupItems', i));
|
|
651
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/releases/${releaseId}/release-groups/${groupDocId}/variable-values`, { items }));
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
// ─── Verification ─────────────────────────────────────────────────────────────
|
|
655
|
+
async function executeVerification(operation, i, returnData) {
|
|
656
|
+
if (operation === 'verifyNumber') {
|
|
657
|
+
const releaseId = this.getNodeParameter('releaseId', i);
|
|
658
|
+
const phoneNumber = this.getNodeParameter('phoneNumber', i);
|
|
659
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/verify-number', { releaseId, phoneNumber }));
|
|
170
660
|
}
|
|
171
661
|
}
|
|
172
662
|
//# sourceMappingURL=Sendflow.node.js.map
|