@growsalesai/n8n-nodes-sendflow 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nodes/Sendflow/Sendflow.node.js +497 -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 +91 -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 +518 -0
- package/dist/nodes/Sendflow/descriptions/ActionDescription.js.map +1 -0
- 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/DirectMessageDescription.d.ts +3 -0
- package/dist/nodes/Sendflow/descriptions/DirectMessageDescription.js +124 -0
- package/dist/nodes/Sendflow/descriptions/DirectMessageDescription.js.map +1 -0
- 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 +97 -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 +149 -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 +42 -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,18 +24,45 @@ 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
|
};
|
|
48
68
|
}
|
|
@@ -62,6 +82,33 @@ class Sendflow {
|
|
|
62
82
|
else if (resource === 'analytics') {
|
|
63
83
|
await executeAnalytics.call(this, operation, i, returnData);
|
|
64
84
|
}
|
|
85
|
+
else if (resource === 'account') {
|
|
86
|
+
await executeAccount.call(this, operation, i, returnData);
|
|
87
|
+
}
|
|
88
|
+
else if (resource === 'action') {
|
|
89
|
+
await executeAction.call(this, operation, i, returnData);
|
|
90
|
+
}
|
|
91
|
+
else if (resource === 'blockNumber') {
|
|
92
|
+
await executeBlockNumber.call(this, operation, i, returnData);
|
|
93
|
+
}
|
|
94
|
+
else if (resource === 'directMessage') {
|
|
95
|
+
await executeDirectMessage.call(this, operation, i, returnData);
|
|
96
|
+
}
|
|
97
|
+
else if (resource === 'media') {
|
|
98
|
+
await executeMedia.call(this, operation, i, returnData);
|
|
99
|
+
}
|
|
100
|
+
else if (resource === 'messageTemplate') {
|
|
101
|
+
await executeMessageTemplate.call(this, operation, i, returnData);
|
|
102
|
+
}
|
|
103
|
+
else if (resource === 'releaseGroup') {
|
|
104
|
+
await executeReleaseGroup.call(this, operation, i, returnData);
|
|
105
|
+
}
|
|
106
|
+
else if (resource === 'variable') {
|
|
107
|
+
await executeVariable.call(this, operation, i, returnData);
|
|
108
|
+
}
|
|
109
|
+
else if (resource === 'verification') {
|
|
110
|
+
await executeVerification.call(this, operation, i, returnData);
|
|
111
|
+
}
|
|
65
112
|
}
|
|
66
113
|
catch (error) {
|
|
67
114
|
if (this.continueOnFail()) {
|
|
@@ -75,59 +122,70 @@ class Sendflow {
|
|
|
75
122
|
}
|
|
76
123
|
}
|
|
77
124
|
exports.Sendflow = Sendflow;
|
|
78
|
-
// ───
|
|
125
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
|
+
function parseJsonField(value) {
|
|
128
|
+
if (typeof value === 'string') {
|
|
129
|
+
try {
|
|
130
|
+
return JSON.parse(value);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
function buildShippingOptions(opts) {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
const options = {};
|
|
141
|
+
if (opts.shippingSpeed)
|
|
142
|
+
options.shippingSpeed = opts.shippingSpeed;
|
|
143
|
+
if (opts.shippingSpeed === 'custom') {
|
|
144
|
+
options.customShippingSpeed = { min: (_a = opts.customSpeedMin) !== null && _a !== void 0 ? _a : 5, max: (_b = opts.customSpeedMax) !== null && _b !== void 0 ? _b : 15 };
|
|
145
|
+
}
|
|
146
|
+
return options;
|
|
147
|
+
}
|
|
148
|
+
// ─── Campaign ─────────────────────────────────────────────────────────────────
|
|
79
149
|
async function executeCampaign(operation, i, returnData) {
|
|
80
150
|
if (operation === 'getAll') {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
returnData.push(...items);
|
|
151
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/releases');
|
|
152
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
84
153
|
return;
|
|
85
154
|
}
|
|
86
155
|
if (operation === 'create') {
|
|
87
156
|
const name = this.getNodeParameter('name', i);
|
|
88
157
|
const type = this.getNodeParameter('type', i);
|
|
89
|
-
const
|
|
158
|
+
const af = this.getNodeParameter('additionalFields', i);
|
|
90
159
|
const body = { name, type };
|
|
91
|
-
if (
|
|
92
|
-
body.projectId =
|
|
93
|
-
|
|
94
|
-
returnData.push(response);
|
|
160
|
+
if (af.projectId)
|
|
161
|
+
body.projectId = af.projectId;
|
|
162
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/releases', body));
|
|
95
163
|
return;
|
|
96
164
|
}
|
|
97
165
|
const releaseId = this.getNodeParameter('releaseId', i);
|
|
98
166
|
if (operation === 'get') {
|
|
99
|
-
|
|
100
|
-
returnData.push(response);
|
|
101
|
-
return;
|
|
167
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}`));
|
|
102
168
|
}
|
|
103
|
-
if (operation === 'delete') {
|
|
169
|
+
else if (operation === 'delete') {
|
|
104
170
|
await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/releases/${releaseId}`);
|
|
105
171
|
returnData.push({ success: true, releaseId });
|
|
106
|
-
return;
|
|
107
172
|
}
|
|
108
|
-
if (operation === 'updateRedirectLink') {
|
|
173
|
+
else if (operation === 'updateRedirectLink') {
|
|
109
174
|
const slug = this.getNodeParameter('slug', i);
|
|
110
|
-
|
|
111
|
-
returnData.push(response);
|
|
112
|
-
return;
|
|
175
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PATCH', `/releases/${releaseId}/redirect-link`, { slug }));
|
|
113
176
|
}
|
|
114
|
-
if (operation === 'removeDuplicatedParticipants') {
|
|
115
|
-
|
|
116
|
-
returnData.push(response);
|
|
117
|
-
return;
|
|
177
|
+
else if (operation === 'removeDuplicatedParticipants') {
|
|
178
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/releases/${releaseId}/remove-duplicated-participants`));
|
|
118
179
|
}
|
|
119
|
-
if (operation === 'update') {
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
const body = { ...
|
|
180
|
+
else if (operation === 'update') {
|
|
181
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
182
|
+
const gc = this.getNodeParameter('groupConfig', i);
|
|
183
|
+
const body = { ...uf };
|
|
123
184
|
if (body.accountIds) {
|
|
124
|
-
body.accountIds = body.accountIds
|
|
125
|
-
.split(',')
|
|
126
|
-
.map((s) => s.trim())
|
|
127
|
-
.filter(Boolean);
|
|
185
|
+
body.accountIds = body.accountIds.split(',').map((s) => s.trim()).filter(Boolean);
|
|
128
186
|
}
|
|
129
|
-
if (Object.keys(
|
|
130
|
-
const group = { ...
|
|
187
|
+
if (Object.keys(gc).length) {
|
|
188
|
+
const group = { ...gc };
|
|
131
189
|
if (typeof group.admins === 'string') {
|
|
132
190
|
try {
|
|
133
191
|
group.admins = JSON.parse(group.admins);
|
|
@@ -138,35 +196,416 @@ async function executeCampaign(operation, i, returnData) {
|
|
|
138
196
|
}
|
|
139
197
|
body.group = group;
|
|
140
198
|
}
|
|
141
|
-
|
|
142
|
-
returnData.push(response);
|
|
199
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/releases/${releaseId}`, body));
|
|
143
200
|
}
|
|
144
201
|
}
|
|
145
|
-
// ─── Group
|
|
202
|
+
// ─── Group ────────────────────────────────────────────────────────────────────
|
|
146
203
|
async function executeGroup(operation, i, returnData) {
|
|
147
204
|
if (operation === 'getAll') {
|
|
148
205
|
const releaseId = this.getNodeParameter('releaseId', i);
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
returnData.push(...items);
|
|
206
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/groups`);
|
|
207
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
152
208
|
}
|
|
153
209
|
}
|
|
154
|
-
// ─── Analytics
|
|
210
|
+
// ─── Analytics ────────────────────────────────────────────────────────────────
|
|
155
211
|
async function executeAnalytics(operation, i, returnData) {
|
|
156
212
|
const releaseId = this.getNodeParameter('releaseId', i);
|
|
157
213
|
if (operation === 'get') {
|
|
158
|
-
|
|
159
|
-
|
|
214
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/analytics`));
|
|
215
|
+
}
|
|
216
|
+
else if (operation === 'getLeadScoring') {
|
|
217
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/leadscoring`));
|
|
218
|
+
}
|
|
219
|
+
else if (operation === 'downloadLeadScoring') {
|
|
220
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/leadscoring/download`);
|
|
221
|
+
returnData.push({ downloadUrl: res });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// ─── Account ──────────────────────────────────────────────────────────────────
|
|
225
|
+
async function executeAccount(operation, i, returnData) {
|
|
226
|
+
if (operation === 'getAll') {
|
|
227
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/accounts');
|
|
228
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (operation === 'create') {
|
|
232
|
+
const name = this.getNodeParameter('name', i);
|
|
233
|
+
const type = this.getNodeParameter('type', i);
|
|
234
|
+
const af = this.getNodeParameter('additionalFields', i);
|
|
235
|
+
const body = { data: { name, type } };
|
|
236
|
+
if (af.projectId)
|
|
237
|
+
body.projectId = af.projectId;
|
|
238
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/accounts/create', body));
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const accountId = this.getNodeParameter('accountId', i);
|
|
242
|
+
if (operation === 'update') {
|
|
243
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
244
|
+
const body = { data: {} };
|
|
245
|
+
if (uf.name)
|
|
246
|
+
body.data.name = uf.name;
|
|
247
|
+
if (uf.type)
|
|
248
|
+
body.data.type = uf.type;
|
|
249
|
+
if (uf.projectId)
|
|
250
|
+
body.projectId = uf.projectId;
|
|
251
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/accounts/${accountId}`, body));
|
|
252
|
+
}
|
|
253
|
+
else if (operation === 'delete') {
|
|
254
|
+
await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/accounts/${accountId}`);
|
|
255
|
+
returnData.push({ success: true, accountId });
|
|
256
|
+
}
|
|
257
|
+
else if (operation === 'connect') {
|
|
258
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/accounts/connect-account/${accountId}`));
|
|
259
|
+
}
|
|
260
|
+
else if (operation === 'disconnect') {
|
|
261
|
+
await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/accounts/disconnect-account/${accountId}`);
|
|
262
|
+
returnData.push({ success: true, accountId });
|
|
263
|
+
}
|
|
264
|
+
else if (operation === 'getQrCode') {
|
|
265
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/accounts/${accountId}/qrcode`));
|
|
266
|
+
}
|
|
267
|
+
else if (operation === 'getQrCodeImage') {
|
|
268
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/accounts/${accountId}/qrcode-image`));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// ─── Action ───────────────────────────────────────────────────────────────────
|
|
272
|
+
async function executeAction(operation, i, returnData) {
|
|
273
|
+
if (operation === 'analyzeGroups') {
|
|
274
|
+
const af = this.getNodeParameter('analyzeFields', i);
|
|
275
|
+
const body = {};
|
|
276
|
+
if (af.accountIds)
|
|
277
|
+
body.accountIds = parseJsonField(af.accountIds);
|
|
278
|
+
if (af.to)
|
|
279
|
+
body.to = af.to;
|
|
280
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/analyze-groups', body));
|
|
160
281
|
return;
|
|
161
282
|
}
|
|
162
|
-
if (operation === '
|
|
163
|
-
const
|
|
164
|
-
|
|
283
|
+
if (operation === 'findParticipant') {
|
|
284
|
+
const accountId = this.getNodeParameter('accountId', i);
|
|
285
|
+
const phoneNumber = this.getNodeParameter('phoneNumber', i);
|
|
286
|
+
const timeout = this.getNodeParameter('timeout', i);
|
|
287
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/find-participant', { accountId, phoneNumber, timeout }));
|
|
165
288
|
return;
|
|
166
289
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
290
|
+
const accountId = this.getNodeParameter('accountId', i);
|
|
291
|
+
const releaseId = this.getNodeParameter('releaseId', i);
|
|
292
|
+
if (operation === 'createGroup') {
|
|
293
|
+
const groupName = this.getNodeParameter('groupName', i);
|
|
294
|
+
const participantsRaw = this.getNodeParameter('participants', i);
|
|
295
|
+
const standardization = this.getNodeParameter('standardization', i);
|
|
296
|
+
const participants = participantsRaw.split(',').map((s) => s.trim()).filter(Boolean);
|
|
297
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/group-create', {
|
|
298
|
+
accountId, releaseId, payload: { name: groupName, participants, standardization },
|
|
299
|
+
}));
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (operation === 'makeGroupAdmin') {
|
|
303
|
+
const participants = parseJsonField(this.getNodeParameter('adminParticipants', i));
|
|
304
|
+
const chooseSpecificGroups = this.getNodeParameter('chooseSpecificGroupsAdmin', i);
|
|
305
|
+
const body = { accountId, releaseId, participants, chooseSpecificGroups };
|
|
306
|
+
if (chooseSpecificGroups) {
|
|
307
|
+
const raw = this.getNodeParameter('groupIdsAdmin', i);
|
|
308
|
+
body.groupIds = raw.split(',').map((s) => s.trim()).filter(Boolean);
|
|
309
|
+
}
|
|
310
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/make-group-admin', body));
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (operation === 'sendTextMessage') {
|
|
314
|
+
const messageText = this.getNodeParameter('messageText', i);
|
|
315
|
+
const opts = this.getNodeParameter('textOptions', i);
|
|
316
|
+
const body = { accountId, releaseId, messageText };
|
|
317
|
+
if (opts.accountIds)
|
|
318
|
+
body.accountIds = parseJsonField(opts.accountIds);
|
|
319
|
+
if (opts.linkPreview !== undefined)
|
|
320
|
+
body.linkPreview = opts.linkPreview;
|
|
321
|
+
if (opts.scheduled !== undefined)
|
|
322
|
+
body.scheduled = opts.scheduled;
|
|
323
|
+
if (opts.scheduledTo)
|
|
324
|
+
body.scheduledTo = opts.scheduledTo;
|
|
325
|
+
if (opts.chooseSpecificGroups !== undefined)
|
|
326
|
+
body.chooseSpecificGroups = opts.chooseSpecificGroups;
|
|
327
|
+
if (opts.groupIds)
|
|
328
|
+
body.groupIds = parseJsonField(opts.groupIds);
|
|
329
|
+
const shippingOpts = buildShippingOptions(opts);
|
|
330
|
+
if (Object.keys(shippingOpts).length)
|
|
331
|
+
body.options = shippingOpts;
|
|
332
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-text-message', body));
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (operation === 'sendImageMessage') {
|
|
336
|
+
const url = this.getNodeParameter('imageUrl', i);
|
|
337
|
+
const caption = this.getNodeParameter('imageCaption', i);
|
|
338
|
+
const opts = this.getNodeParameter('imageOptions', i);
|
|
339
|
+
const body = { accountId, releaseId, url, caption };
|
|
340
|
+
applyCommonSendOptions(body, opts);
|
|
341
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-image-message', body));
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (operation === 'sendVideoMessage') {
|
|
345
|
+
const url = this.getNodeParameter('videoUrl', i);
|
|
346
|
+
const caption = this.getNodeParameter('videoCaption', i);
|
|
347
|
+
const opts = this.getNodeParameter('videoOptions', i);
|
|
348
|
+
const body = { accountId, releaseId, url, caption };
|
|
349
|
+
applyCommonSendOptions(body, opts);
|
|
350
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-video-message', body));
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (operation === 'sendAudioMessage') {
|
|
354
|
+
const url = this.getNodeParameter('audioUrl', i);
|
|
355
|
+
const ptt = this.getNodeParameter('ptt', i);
|
|
356
|
+
const opts = this.getNodeParameter('audioOptions', i);
|
|
357
|
+
const body = { accountId, releaseId, url, ptt };
|
|
358
|
+
if (opts.caption)
|
|
359
|
+
body.caption = opts.caption;
|
|
360
|
+
applyCommonSendOptions(body, opts);
|
|
361
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-audio-message', body));
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (operation === 'sendDocumentMessage') {
|
|
365
|
+
const url = this.getNodeParameter('documentUrl', i);
|
|
366
|
+
const fileName = this.getNodeParameter('fileName', i);
|
|
367
|
+
const opts = this.getNodeParameter('documentOptions', i);
|
|
368
|
+
const body = { accountId, releaseId, url, fileName };
|
|
369
|
+
if (opts.caption)
|
|
370
|
+
body.caption = opts.caption;
|
|
371
|
+
applyCommonSendOptions(body, opts);
|
|
372
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-document-message', body));
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (operation === 'sendMessage') {
|
|
376
|
+
const type = this.getNodeParameter('messageType', i);
|
|
377
|
+
const opts = this.getNodeParameter('genericOptions', i);
|
|
378
|
+
const body = { accountId, releaseId, type };
|
|
379
|
+
if (type === 'extendedTextMessage') {
|
|
380
|
+
body.text = this.getNodeParameter('genericText', i);
|
|
381
|
+
if (opts.linkPreview !== undefined)
|
|
382
|
+
body.linkPreview = opts.linkPreview;
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
body.url = this.getNodeParameter('genericUrl', i);
|
|
386
|
+
body.caption = this.getNodeParameter('genericCaption', i);
|
|
387
|
+
if (type === 'documentMessage')
|
|
388
|
+
body.fileName = this.getNodeParameter('genericFileName', i);
|
|
389
|
+
if (type === 'audioMessage')
|
|
390
|
+
body.ptt = this.getNodeParameter('genericPtt', i);
|
|
391
|
+
}
|
|
392
|
+
if (opts.accountIds)
|
|
393
|
+
body.accountIds = parseJsonField(opts.accountIds);
|
|
394
|
+
if (opts.scheduledTo)
|
|
395
|
+
body.scheduledTo = opts.scheduledTo;
|
|
396
|
+
if (opts.chooseSpecificGroups !== undefined)
|
|
397
|
+
body.chooseSpecificGroups = opts.chooseSpecificGroups;
|
|
398
|
+
if (opts.groupIds)
|
|
399
|
+
body.groupIds = parseJsonField(opts.groupIds);
|
|
400
|
+
const msgOptions = buildShippingOptions(opts);
|
|
401
|
+
if (opts.ephemeralExpiration)
|
|
402
|
+
msgOptions.ephemeralExpiration = opts.ephemeralExpiration;
|
|
403
|
+
if (opts.mentionAllParticipants !== undefined)
|
|
404
|
+
msgOptions.mentionAllParticipants = opts.mentionAllParticipants;
|
|
405
|
+
if (Object.keys(msgOptions).length)
|
|
406
|
+
body.options = msgOptions;
|
|
407
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-message', body));
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
if (operation === 'sendMessages') {
|
|
411
|
+
const accountsFrom = this.getNodeParameter('accountsFrom', i);
|
|
412
|
+
const toType = this.getNodeParameter('toType', i);
|
|
413
|
+
const toIds = parseJsonField(this.getNodeParameter('toIds', i));
|
|
414
|
+
const messages = parseJsonField(this.getNodeParameter('bulkMessages', i));
|
|
415
|
+
const opts = this.getNodeParameter('bulkOptions', i);
|
|
416
|
+
const body = {
|
|
417
|
+
releaseId,
|
|
418
|
+
accountsFrom,
|
|
419
|
+
to: { type: toType, ids: toIds },
|
|
420
|
+
data: { messages },
|
|
421
|
+
};
|
|
422
|
+
if (opts.accounts)
|
|
423
|
+
body.accounts = parseJsonField(opts.accounts);
|
|
424
|
+
if (opts.scheduledTo)
|
|
425
|
+
body.scheduledTo = opts.scheduledTo;
|
|
426
|
+
const shippingOpts = buildShippingOptions(opts);
|
|
427
|
+
if (Object.keys(shippingOpts).length)
|
|
428
|
+
body.options = shippingOpts;
|
|
429
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/actions/send-messages', body));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function applyCommonSendOptions(body, opts) {
|
|
433
|
+
if (opts.accountIds)
|
|
434
|
+
body.accountIds = parseJsonField(opts.accountIds);
|
|
435
|
+
if (opts.scheduledTo)
|
|
436
|
+
body.scheduledTo = opts.scheduledTo;
|
|
437
|
+
if (opts.chooseSpecificGroups !== undefined)
|
|
438
|
+
body.chooseSpecificGroups = opts.chooseSpecificGroups;
|
|
439
|
+
if (opts.groupIds)
|
|
440
|
+
body.groupIds = parseJsonField(opts.groupIds);
|
|
441
|
+
const shippingOpts = buildShippingOptions(opts);
|
|
442
|
+
if (Object.keys(shippingOpts).length)
|
|
443
|
+
body.options = shippingOpts;
|
|
444
|
+
}
|
|
445
|
+
// ─── Block Number ─────────────────────────────────────────────────────────────
|
|
446
|
+
async function executeBlockNumber(operation, i, returnData) {
|
|
447
|
+
if (operation === 'getAll') {
|
|
448
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/block-numbers');
|
|
449
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
450
|
+
}
|
|
451
|
+
else if (operation === 'create') {
|
|
452
|
+
const number = this.getNodeParameter('number', i);
|
|
453
|
+
const name = this.getNodeParameter('name', i);
|
|
454
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/block-numbers', { number, name }));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
// ─── Direct Message ───────────────────────────────────────────────────────────
|
|
458
|
+
async function executeDirectMessage(operation, i, returnData) {
|
|
459
|
+
const accountId = this.getNodeParameter('accountId', i);
|
|
460
|
+
const phoneNumber = this.getNodeParameter('phoneNumber', i);
|
|
461
|
+
if (operation === 'sendText') {
|
|
462
|
+
const text = this.getNodeParameter('text', i);
|
|
463
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/send-text-message/${accountId}`, { text, phoneNumber }));
|
|
464
|
+
}
|
|
465
|
+
else if (operation === 'sendImage') {
|
|
466
|
+
const url = this.getNodeParameter('url', i);
|
|
467
|
+
const caption = this.getNodeParameter('captionImage', i);
|
|
468
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/send-image-message/${accountId}`, { url, caption, phoneNumber }));
|
|
469
|
+
}
|
|
470
|
+
else if (operation === 'sendVideo') {
|
|
471
|
+
const url = this.getNodeParameter('urlVideo', i);
|
|
472
|
+
const caption = this.getNodeParameter('captionVideo', i);
|
|
473
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/send-video-message/${accountId}`, { url, caption, phoneNumber }));
|
|
474
|
+
}
|
|
475
|
+
else if (operation === 'sendAudio') {
|
|
476
|
+
const url = this.getNodeParameter('urlAudio', i);
|
|
477
|
+
const caption = this.getNodeParameter('captionAudio', i);
|
|
478
|
+
const ptt = this.getNodeParameter('ptt', i);
|
|
479
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', `/send-audio-message/${accountId}`, { url, caption, ptt, phoneNumber }));
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
// ─── Media ────────────────────────────────────────────────────────────────────
|
|
483
|
+
async function executeMedia(operation, i, returnData) {
|
|
484
|
+
if (operation === 'generateMediaId') {
|
|
485
|
+
const mediaId = this.getNodeParameter('mediaId', i);
|
|
486
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/generate-media-id', {}, { mediaId }));
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
// ─── Message Template ─────────────────────────────────────────────────────────
|
|
490
|
+
async function executeMessageTemplate(operation, i, returnData) {
|
|
491
|
+
if (operation === 'getAll') {
|
|
492
|
+
const res = await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/message-templates');
|
|
493
|
+
returnData.push(...(Array.isArray(res) ? res : [res]));
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (operation === 'create') {
|
|
497
|
+
const title = this.getNodeParameter('title', i);
|
|
498
|
+
const template = parseJsonField(this.getNodeParameter('template', i));
|
|
499
|
+
const af = this.getNodeParameter('additionalFields', i);
|
|
500
|
+
const body = { title, template };
|
|
501
|
+
if (af.folderId)
|
|
502
|
+
body.folderId = af.folderId;
|
|
503
|
+
if (af.intervalRangeType)
|
|
504
|
+
body.intervalRangeType = af.intervalRangeType;
|
|
505
|
+
if (af.intervalRange)
|
|
506
|
+
body.intervalRange = parseJsonField(af.intervalRange);
|
|
507
|
+
if (af.archived !== undefined)
|
|
508
|
+
body.archived = af.archived;
|
|
509
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/message-templates', body));
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const templateId = this.getNodeParameter('templateId', i);
|
|
513
|
+
if (operation === 'update') {
|
|
514
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
515
|
+
const body = {};
|
|
516
|
+
if (uf.title)
|
|
517
|
+
body.title = uf.title;
|
|
518
|
+
if (uf.template)
|
|
519
|
+
body.template = parseJsonField(uf.template);
|
|
520
|
+
if (uf.folderId !== undefined)
|
|
521
|
+
body.folderId = uf.folderId || null;
|
|
522
|
+
if (uf.intervalRangeType)
|
|
523
|
+
body.intervalRangeType = uf.intervalRangeType;
|
|
524
|
+
if (uf.intervalRange)
|
|
525
|
+
body.intervalRange = parseJsonField(uf.intervalRange);
|
|
526
|
+
if (uf.archived !== undefined)
|
|
527
|
+
body.archived = uf.archived;
|
|
528
|
+
if (uf.position !== undefined)
|
|
529
|
+
body.position = uf.position;
|
|
530
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/message-templates/${templateId}`, body));
|
|
531
|
+
}
|
|
532
|
+
else if (operation === 'delete') {
|
|
533
|
+
await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/message-templates/${templateId}`);
|
|
534
|
+
returnData.push({ success: true, templateId });
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
// ─── Release Group ────────────────────────────────────────────────────────────
|
|
538
|
+
async function executeReleaseGroup(operation, i, returnData) {
|
|
539
|
+
if (operation === 'create') {
|
|
540
|
+
const gid = this.getNodeParameter('gid', i);
|
|
541
|
+
const releaseId = this.getNodeParameter('releaseId', i);
|
|
542
|
+
const name = this.getNodeParameter('name', i);
|
|
543
|
+
const af = this.getNodeParameter('additionalFields', i);
|
|
544
|
+
const body = { gid, releaseId, name, ...af };
|
|
545
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/release-groups', body));
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const releaseGroupId = this.getNodeParameter('releaseGroupId', i);
|
|
549
|
+
if (operation === 'get') {
|
|
550
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/release-groups/${releaseGroupId}`));
|
|
551
|
+
}
|
|
552
|
+
else if (operation === 'update') {
|
|
553
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
554
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/release-groups/${releaseGroupId}`, uf));
|
|
555
|
+
}
|
|
556
|
+
else if (operation === 'delete') {
|
|
557
|
+
await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/release-groups/${releaseGroupId}`);
|
|
558
|
+
returnData.push({ success: true, releaseGroupId });
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
// ─── Variable ─────────────────────────────────────────────────────────────────
|
|
562
|
+
async function executeVariable(operation, i, returnData) {
|
|
563
|
+
if (operation === 'getAll') {
|
|
564
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', '/variables'));
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
if (operation === 'create') {
|
|
568
|
+
const name = this.getNodeParameter('name', i);
|
|
569
|
+
const type = this.getNodeParameter('type', i);
|
|
570
|
+
const category = this.getNodeParameter('category', i);
|
|
571
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/variables', { name, type, category }));
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
if (operation === 'update') {
|
|
575
|
+
const variableId = this.getNodeParameter('variableId', i);
|
|
576
|
+
const uf = this.getNodeParameter('updateFields', i);
|
|
577
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/variables/${variableId}`, uf));
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
if (operation === 'delete') {
|
|
581
|
+
const variableId = this.getNodeParameter('variableId', i);
|
|
582
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'DELETE', `/variables/${variableId}`));
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const releaseId = this.getNodeParameter('releaseId', i);
|
|
586
|
+
if (operation === 'getCampaignValues') {
|
|
587
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/variable-values`));
|
|
588
|
+
}
|
|
589
|
+
else if (operation === 'saveCampaignValues') {
|
|
590
|
+
const items = parseJsonField(this.getNodeParameter('campaignItems', i));
|
|
591
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/releases/${releaseId}/variable-values`, { items }));
|
|
592
|
+
}
|
|
593
|
+
else if (operation === 'getGroupValues') {
|
|
594
|
+
const groupDocId = this.getNodeParameter('groupDocId', i);
|
|
595
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'GET', `/releases/${releaseId}/release-groups/${groupDocId}/variable-values`));
|
|
596
|
+
}
|
|
597
|
+
else if (operation === 'saveGroupValues') {
|
|
598
|
+
const groupDocId = this.getNodeParameter('groupDocId', i);
|
|
599
|
+
const items = parseJsonField(this.getNodeParameter('groupItems', i));
|
|
600
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'PUT', `/releases/${releaseId}/release-groups/${groupDocId}/variable-values`, { items }));
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
// ─── Verification ─────────────────────────────────────────────────────────────
|
|
604
|
+
async function executeVerification(operation, i, returnData) {
|
|
605
|
+
if (operation === 'verifyNumber') {
|
|
606
|
+
const releaseId = this.getNodeParameter('releaseId', i);
|
|
607
|
+
const phoneNumber = this.getNodeParameter('phoneNumber', i);
|
|
608
|
+
returnData.push(await GenericFunctions_1.sendflowApiRequest.call(this, 'POST', '/verify-number', { releaseId, phoneNumber }));
|
|
170
609
|
}
|
|
171
610
|
}
|
|
172
611
|
//# sourceMappingURL=Sendflow.node.js.map
|