@growsalesai/n8n-nodes-manychat 0.1.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/ManychatApi.credentials.d.ts +9 -0
- package/dist/credentials/ManychatApi.credentials.js +38 -0
- package/dist/credentials/ManychatApi.credentials.js.map +1 -0
- package/dist/nodes/Manychat/Manychat.node.d.ts +5 -0
- package/dist/nodes/Manychat/Manychat.node.js +695 -0
- package/dist/nodes/Manychat/Manychat.node.js.map +1 -0
- package/dist/nodes/Manychat/hero_manychat.png.svg +228 -0
- package/package.json +49 -0
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Manychat = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const BASE_URL = 'https://api.manychat.com';
|
|
6
|
+
class Manychat {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.description = {
|
|
9
|
+
displayName: 'ManyChat',
|
|
10
|
+
name: 'manychat',
|
|
11
|
+
icon: 'file:hero_manychat.png.svg',
|
|
12
|
+
group: ['transform'],
|
|
13
|
+
version: 1,
|
|
14
|
+
subtitle: '={{$parameter["operation"] + " · " + $parameter["resource"]}}',
|
|
15
|
+
description: 'Interact with ManyChat API to manage subscribers, send messages, and configure your page',
|
|
16
|
+
defaults: {
|
|
17
|
+
name: 'ManyChat',
|
|
18
|
+
},
|
|
19
|
+
inputs: ['main'],
|
|
20
|
+
outputs: ['main'],
|
|
21
|
+
credentials: [
|
|
22
|
+
{
|
|
23
|
+
name: 'manychatApi',
|
|
24
|
+
required: true,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
properties: [
|
|
28
|
+
// ─── RESOURCE ────────────────────────────────────────────────────────────
|
|
29
|
+
{
|
|
30
|
+
displayName: 'Resource',
|
|
31
|
+
name: 'resource',
|
|
32
|
+
type: 'options',
|
|
33
|
+
noDataExpression: true,
|
|
34
|
+
options: [
|
|
35
|
+
{ name: 'Page', value: 'page' },
|
|
36
|
+
{ name: 'Sending', value: 'sending' },
|
|
37
|
+
{ name: 'Subscriber', value: 'subscriber' },
|
|
38
|
+
],
|
|
39
|
+
default: 'subscriber',
|
|
40
|
+
},
|
|
41
|
+
// ─── PAGE OPERATIONS ─────────────────────────────────────────────────────
|
|
42
|
+
{
|
|
43
|
+
displayName: 'Operation',
|
|
44
|
+
name: 'operation',
|
|
45
|
+
type: 'options',
|
|
46
|
+
noDataExpression: true,
|
|
47
|
+
displayOptions: { show: { resource: ['page'] } },
|
|
48
|
+
options: [
|
|
49
|
+
{ name: 'Create Bot Field', value: 'createBotField', action: 'Create a bot field' },
|
|
50
|
+
{ name: 'Create Custom Field', value: 'createCustomField', action: 'Create a custom field' },
|
|
51
|
+
{ name: 'Create Tag', value: 'createTag', action: 'Create a tag' },
|
|
52
|
+
{ name: 'Get Bot Fields', value: 'getBotFields', action: 'Get all bot fields' },
|
|
53
|
+
{ name: 'Get Custom Fields', value: 'getCustomFields', action: 'Get all custom fields' },
|
|
54
|
+
{ name: 'Get Flows', value: 'getFlows', action: 'Get all flows' },
|
|
55
|
+
{ name: 'Get Growth Tools', value: 'getGrowthTools', action: 'Get all growth tools' },
|
|
56
|
+
{ name: 'Get Info', value: 'getInfo', action: 'Get page info' },
|
|
57
|
+
{ name: 'Get OTN Topics', value: 'getOtnTopics', action: 'Get OTN topics' },
|
|
58
|
+
{ name: 'Get Tags', value: 'getTags', action: 'Get all tags' },
|
|
59
|
+
{ name: 'Remove Tag', value: 'removeTag', action: 'Remove a tag by ID' },
|
|
60
|
+
{ name: 'Remove Tag By Name', value: 'removeTagByName', action: 'Remove a tag by name' },
|
|
61
|
+
{ name: 'Set Bot Field', value: 'setBotField', action: 'Set a bot field value by ID' },
|
|
62
|
+
{ name: 'Set Bot Field By Name', value: 'setBotFieldByName', action: 'Set a bot field value by name' },
|
|
63
|
+
],
|
|
64
|
+
default: 'getInfo',
|
|
65
|
+
},
|
|
66
|
+
// ─── SENDING OPERATIONS ──────────────────────────────────────────────────
|
|
67
|
+
{
|
|
68
|
+
displayName: 'Operation',
|
|
69
|
+
name: 'operation',
|
|
70
|
+
type: 'options',
|
|
71
|
+
noDataExpression: true,
|
|
72
|
+
displayOptions: { show: { resource: ['sending'] } },
|
|
73
|
+
options: [
|
|
74
|
+
{ name: 'Send Content', value: 'sendContent', action: 'Send content to a subscriber' },
|
|
75
|
+
{ name: 'Send Flow', value: 'sendFlow', action: 'Send a flow to a subscriber' },
|
|
76
|
+
],
|
|
77
|
+
default: 'sendFlow',
|
|
78
|
+
},
|
|
79
|
+
// ─── SUBSCRIBER OPERATIONS ───────────────────────────────────────────────
|
|
80
|
+
{
|
|
81
|
+
displayName: 'Operation',
|
|
82
|
+
name: 'operation',
|
|
83
|
+
type: 'options',
|
|
84
|
+
noDataExpression: true,
|
|
85
|
+
displayOptions: { show: { resource: ['subscriber'] } },
|
|
86
|
+
options: [
|
|
87
|
+
{ name: 'Add Tag', value: 'addTag', action: 'Add a tag to a subscriber by tag ID' },
|
|
88
|
+
{ name: 'Add Tag By Name', value: 'addTagByName', action: 'Add a tag to a subscriber by tag name' },
|
|
89
|
+
{ name: 'Create Subscriber', value: 'createSubscriber', action: 'Create a new subscriber' },
|
|
90
|
+
{ name: 'Find By Custom Field', value: 'findByCustomField', action: 'Find subscribers by custom field' },
|
|
91
|
+
{ name: 'Find By Name', value: 'findByName', action: 'Find subscribers by name' },
|
|
92
|
+
{ name: 'Find By System Field', value: 'findBySystemField', action: 'Find a subscriber by email or phone' },
|
|
93
|
+
{ name: 'Get Info', value: 'getInfo', action: 'Get subscriber info' },
|
|
94
|
+
{ name: 'Remove Tag', value: 'removeTag', action: 'Remove a tag from a subscriber by tag ID' },
|
|
95
|
+
{ name: 'Remove Tag By Name', value: 'removeTagByName', action: 'Remove a tag from a subscriber by tag name' },
|
|
96
|
+
{ name: 'Set Custom Field', value: 'setCustomField', action: 'Set a custom field value by field ID' },
|
|
97
|
+
{ name: 'Set Custom Field By Name', value: 'setCustomFieldByName', action: 'Set a custom field value by field name' },
|
|
98
|
+
{ name: 'Update Subscriber', value: 'updateSubscriber', action: 'Update subscriber data' },
|
|
99
|
+
],
|
|
100
|
+
default: 'getInfo',
|
|
101
|
+
},
|
|
102
|
+
// ════════════════════════════════════════════════════════════════
|
|
103
|
+
// PAGE PARAMETERS
|
|
104
|
+
// ════════════════════════════════════════════════════════════════
|
|
105
|
+
// page > createTag
|
|
106
|
+
{
|
|
107
|
+
displayName: 'Tag Name',
|
|
108
|
+
name: 'name',
|
|
109
|
+
type: 'string',
|
|
110
|
+
required: true,
|
|
111
|
+
default: '',
|
|
112
|
+
displayOptions: { show: { resource: ['page'], operation: ['createTag'] } },
|
|
113
|
+
},
|
|
114
|
+
// page > removeTag
|
|
115
|
+
{
|
|
116
|
+
displayName: 'Tag ID',
|
|
117
|
+
name: 'tag_id',
|
|
118
|
+
type: 'number',
|
|
119
|
+
required: true,
|
|
120
|
+
default: 0,
|
|
121
|
+
displayOptions: { show: { resource: ['page'], operation: ['removeTag'] } },
|
|
122
|
+
},
|
|
123
|
+
// page > removeTagByName
|
|
124
|
+
{
|
|
125
|
+
displayName: 'Tag Name',
|
|
126
|
+
name: 'tag_name',
|
|
127
|
+
type: 'string',
|
|
128
|
+
required: true,
|
|
129
|
+
default: '',
|
|
130
|
+
displayOptions: { show: { resource: ['page'], operation: ['removeTagByName'] } },
|
|
131
|
+
},
|
|
132
|
+
// page > createCustomField
|
|
133
|
+
{
|
|
134
|
+
displayName: 'Caption',
|
|
135
|
+
name: 'caption',
|
|
136
|
+
type: 'string',
|
|
137
|
+
required: true,
|
|
138
|
+
default: '',
|
|
139
|
+
displayOptions: { show: { resource: ['page'], operation: ['createCustomField'] } },
|
|
140
|
+
},
|
|
141
|
+
// page > createCustomField + createBotField
|
|
142
|
+
{
|
|
143
|
+
displayName: 'Type',
|
|
144
|
+
name: 'type',
|
|
145
|
+
type: 'options',
|
|
146
|
+
required: true,
|
|
147
|
+
options: [
|
|
148
|
+
{ name: 'Boolean', value: 'boolean' },
|
|
149
|
+
{ name: 'Date', value: 'date' },
|
|
150
|
+
{ name: 'Datetime', value: 'datetime' },
|
|
151
|
+
{ name: 'Number', value: 'number' },
|
|
152
|
+
{ name: 'Text', value: 'text' },
|
|
153
|
+
],
|
|
154
|
+
default: 'text',
|
|
155
|
+
displayOptions: { show: { resource: ['page'], operation: ['createCustomField', 'createBotField'] } },
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
displayName: 'Description',
|
|
159
|
+
name: 'description',
|
|
160
|
+
type: 'string',
|
|
161
|
+
default: '',
|
|
162
|
+
displayOptions: { show: { resource: ['page'], operation: ['createCustomField', 'createBotField'] } },
|
|
163
|
+
},
|
|
164
|
+
// page > createBotField
|
|
165
|
+
{
|
|
166
|
+
displayName: 'Field Name',
|
|
167
|
+
name: 'name',
|
|
168
|
+
type: 'string',
|
|
169
|
+
required: true,
|
|
170
|
+
default: '',
|
|
171
|
+
displayOptions: { show: { resource: ['page'], operation: ['createBotField'] } },
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
displayName: 'Initial Value',
|
|
175
|
+
name: 'value',
|
|
176
|
+
type: 'string',
|
|
177
|
+
default: '',
|
|
178
|
+
displayOptions: { show: { resource: ['page'], operation: ['createBotField'] } },
|
|
179
|
+
},
|
|
180
|
+
// page > setBotField
|
|
181
|
+
{
|
|
182
|
+
displayName: 'Field ID',
|
|
183
|
+
name: 'field_id',
|
|
184
|
+
type: 'number',
|
|
185
|
+
required: true,
|
|
186
|
+
default: 0,
|
|
187
|
+
displayOptions: { show: { resource: ['page'], operation: ['setBotField'] } },
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
displayName: 'Field Value',
|
|
191
|
+
name: 'field_value',
|
|
192
|
+
type: 'string',
|
|
193
|
+
required: true,
|
|
194
|
+
default: '',
|
|
195
|
+
displayOptions: { show: { resource: ['page'], operation: ['setBotField', 'setBotFieldByName'] } },
|
|
196
|
+
},
|
|
197
|
+
// page > setBotFieldByName
|
|
198
|
+
{
|
|
199
|
+
displayName: 'Field Name',
|
|
200
|
+
name: 'field_name',
|
|
201
|
+
type: 'string',
|
|
202
|
+
required: true,
|
|
203
|
+
default: '',
|
|
204
|
+
displayOptions: { show: { resource: ['page'], operation: ['setBotFieldByName'] } },
|
|
205
|
+
},
|
|
206
|
+
// ════════════════════════════════════════════════════════════════
|
|
207
|
+
// SENDING PARAMETERS
|
|
208
|
+
// ════════════════════════════════════════════════════════════════
|
|
209
|
+
{
|
|
210
|
+
displayName: 'Subscriber ID',
|
|
211
|
+
name: 'subscriber_id',
|
|
212
|
+
type: 'number',
|
|
213
|
+
required: true,
|
|
214
|
+
default: 0,
|
|
215
|
+
displayOptions: { show: { resource: ['sending'], operation: ['sendFlow', 'sendContent'] } },
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
displayName: 'Flow NS',
|
|
219
|
+
name: 'flow_ns',
|
|
220
|
+
type: 'string',
|
|
221
|
+
required: true,
|
|
222
|
+
default: '',
|
|
223
|
+
description: 'The flow namespace identifier (e.g. content20180221085508_278600)',
|
|
224
|
+
displayOptions: { show: { resource: ['sending'], operation: ['sendFlow'] } },
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
displayName: 'Content Data (JSON)',
|
|
228
|
+
name: 'data',
|
|
229
|
+
type: 'json',
|
|
230
|
+
required: true,
|
|
231
|
+
default: '{"version":"v2","content":{"messages":[{"type":"text","text":"Hello!"}]}}',
|
|
232
|
+
description: 'The content object as JSON. See ManyChat API docs for the full schema.',
|
|
233
|
+
displayOptions: { show: { resource: ['sending'], operation: ['sendContent'] } },
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
displayName: 'Message Tag',
|
|
237
|
+
name: 'message_tag',
|
|
238
|
+
type: 'options',
|
|
239
|
+
options: [
|
|
240
|
+
{ name: '(None)', value: '' },
|
|
241
|
+
{ name: 'Account Update', value: 'ACCOUNT_UPDATE' },
|
|
242
|
+
{ name: 'Confirmed Event Update', value: 'CONFIRMED_EVENT_UPDATE' },
|
|
243
|
+
{ name: 'Customer Feedback', value: 'CUSTOMER_FEEDBACK' },
|
|
244
|
+
{ name: 'Post Purchase Update', value: 'POST_PURCHASE_UPDATE' },
|
|
245
|
+
],
|
|
246
|
+
default: '',
|
|
247
|
+
displayOptions: { show: { resource: ['sending'], operation: ['sendContent'] } },
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
displayName: 'OTN Topic Name',
|
|
251
|
+
name: 'otn_topic_name',
|
|
252
|
+
type: 'string',
|
|
253
|
+
default: '',
|
|
254
|
+
displayOptions: { show: { resource: ['sending'], operation: ['sendContent'] } },
|
|
255
|
+
},
|
|
256
|
+
// ════════════════════════════════════════════════════════════════
|
|
257
|
+
// SUBSCRIBER PARAMETERS
|
|
258
|
+
// ════════════════════════════════════════════════════════════════
|
|
259
|
+
{
|
|
260
|
+
displayName: 'Subscriber ID',
|
|
261
|
+
name: 'subscriber_id',
|
|
262
|
+
type: 'number',
|
|
263
|
+
required: true,
|
|
264
|
+
default: 0,
|
|
265
|
+
displayOptions: {
|
|
266
|
+
show: {
|
|
267
|
+
resource: ['subscriber'],
|
|
268
|
+
operation: ['getInfo', 'addTag', 'addTagByName', 'removeTag', 'removeTagByName', 'setCustomField', 'setCustomFieldByName', 'updateSubscriber'],
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
// subscriber > findByName
|
|
273
|
+
{
|
|
274
|
+
displayName: 'Name',
|
|
275
|
+
name: 'name',
|
|
276
|
+
type: 'string',
|
|
277
|
+
required: true,
|
|
278
|
+
default: '',
|
|
279
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['findByName'] } },
|
|
280
|
+
},
|
|
281
|
+
// subscriber > findByCustomField
|
|
282
|
+
{
|
|
283
|
+
displayName: 'Field ID',
|
|
284
|
+
name: 'field_id',
|
|
285
|
+
type: 'number',
|
|
286
|
+
required: true,
|
|
287
|
+
default: 0,
|
|
288
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['findByCustomField'] } },
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
displayName: 'Field Value',
|
|
292
|
+
name: 'field_value',
|
|
293
|
+
type: 'string',
|
|
294
|
+
required: true,
|
|
295
|
+
default: '',
|
|
296
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['findByCustomField', 'setCustomField'] } },
|
|
297
|
+
},
|
|
298
|
+
// subscriber > findBySystemField
|
|
299
|
+
{
|
|
300
|
+
displayName: 'Email',
|
|
301
|
+
name: 'email',
|
|
302
|
+
type: 'string',
|
|
303
|
+
placeholder: 'name@email.com',
|
|
304
|
+
default: '',
|
|
305
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['findBySystemField'] } },
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
displayName: 'Phone',
|
|
309
|
+
name: 'phone',
|
|
310
|
+
type: 'string',
|
|
311
|
+
default: '',
|
|
312
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['findBySystemField'] } },
|
|
313
|
+
},
|
|
314
|
+
// subscriber > addTag / removeTag
|
|
315
|
+
{
|
|
316
|
+
displayName: 'Tag ID',
|
|
317
|
+
name: 'tag_id',
|
|
318
|
+
type: 'number',
|
|
319
|
+
required: true,
|
|
320
|
+
default: 0,
|
|
321
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['addTag', 'removeTag'] } },
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
displayName: 'Tag Name',
|
|
325
|
+
name: 'tag_name',
|
|
326
|
+
type: 'string',
|
|
327
|
+
required: true,
|
|
328
|
+
default: '',
|
|
329
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['addTagByName', 'removeTagByName'] } },
|
|
330
|
+
},
|
|
331
|
+
// subscriber > setCustomField
|
|
332
|
+
{
|
|
333
|
+
displayName: 'Field ID',
|
|
334
|
+
name: 'field_id',
|
|
335
|
+
type: 'number',
|
|
336
|
+
required: true,
|
|
337
|
+
default: 0,
|
|
338
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['setCustomField'] } },
|
|
339
|
+
},
|
|
340
|
+
// subscriber > setCustomFieldByName
|
|
341
|
+
{
|
|
342
|
+
displayName: 'Field Name',
|
|
343
|
+
name: 'field_name',
|
|
344
|
+
type: 'string',
|
|
345
|
+
required: true,
|
|
346
|
+
default: '',
|
|
347
|
+
description: 'Not case sensitive',
|
|
348
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['setCustomFieldByName'] } },
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
displayName: 'Field Value',
|
|
352
|
+
name: 'field_value',
|
|
353
|
+
type: 'string',
|
|
354
|
+
required: true,
|
|
355
|
+
default: '',
|
|
356
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['setCustomFieldByName'] } },
|
|
357
|
+
},
|
|
358
|
+
// subscriber > createSubscriber / updateSubscriber
|
|
359
|
+
{
|
|
360
|
+
displayName: 'First Name',
|
|
361
|
+
name: 'first_name',
|
|
362
|
+
type: 'string',
|
|
363
|
+
default: '',
|
|
364
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['createSubscriber', 'updateSubscriber'] } },
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
displayName: 'Last Name',
|
|
368
|
+
name: 'last_name',
|
|
369
|
+
type: 'string',
|
|
370
|
+
default: '',
|
|
371
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['createSubscriber', 'updateSubscriber'] } },
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
displayName: 'Phone',
|
|
375
|
+
name: 'phone',
|
|
376
|
+
type: 'string',
|
|
377
|
+
default: '',
|
|
378
|
+
description: 'Required if email and WhatsApp phone are not provided',
|
|
379
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['createSubscriber', 'updateSubscriber'] } },
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
displayName: 'WhatsApp Phone',
|
|
383
|
+
name: 'whatsapp_phone',
|
|
384
|
+
type: 'string',
|
|
385
|
+
default: '',
|
|
386
|
+
description: 'Required if email and phone are not provided',
|
|
387
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['createSubscriber'] } },
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
displayName: 'Email',
|
|
391
|
+
name: 'email',
|
|
392
|
+
type: 'string',
|
|
393
|
+
placeholder: 'name@email.com',
|
|
394
|
+
default: '',
|
|
395
|
+
description: 'Required if phone and WhatsApp phone are not provided',
|
|
396
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['createSubscriber', 'updateSubscriber'] } },
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
displayName: 'Gender',
|
|
400
|
+
name: 'gender',
|
|
401
|
+
type: 'options',
|
|
402
|
+
options: [
|
|
403
|
+
{ name: '(Not Set)', value: '' },
|
|
404
|
+
{ name: 'Female', value: 'female' },
|
|
405
|
+
{ name: 'Male', value: 'male' },
|
|
406
|
+
],
|
|
407
|
+
default: '',
|
|
408
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['createSubscriber', 'updateSubscriber'] } },
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
displayName: 'Has Opt-In SMS',
|
|
412
|
+
name: 'has_opt_in_sms',
|
|
413
|
+
type: 'boolean',
|
|
414
|
+
default: false,
|
|
415
|
+
description: 'Whether the subscriber has opted in to SMS. Required when phone is provided.',
|
|
416
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['createSubscriber', 'updateSubscriber'] } },
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
displayName: 'Has Opt-In Email',
|
|
420
|
+
name: 'has_opt_in_email',
|
|
421
|
+
type: 'boolean',
|
|
422
|
+
default: false,
|
|
423
|
+
description: 'Whether the subscriber has opted in to email. Required when email is provided.',
|
|
424
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['createSubscriber', 'updateSubscriber'] } },
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
displayName: 'Consent Phrase',
|
|
428
|
+
name: 'consent_phrase',
|
|
429
|
+
type: 'string',
|
|
430
|
+
default: '',
|
|
431
|
+
description: 'Required when Has Opt-In SMS is true',
|
|
432
|
+
displayOptions: { show: { resource: ['subscriber'], operation: ['createSubscriber', 'updateSubscriber'] } },
|
|
433
|
+
},
|
|
434
|
+
],
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
async execute() {
|
|
438
|
+
const items = this.getInputData();
|
|
439
|
+
const returnData = [];
|
|
440
|
+
const credentials = await this.getCredentials('manychatApi');
|
|
441
|
+
const token = credentials.apiToken;
|
|
442
|
+
const makeRequest = async (method, path, body, qs) => {
|
|
443
|
+
try {
|
|
444
|
+
return await this.helpers.httpRequest({
|
|
445
|
+
method,
|
|
446
|
+
url: `${BASE_URL}${path}`,
|
|
447
|
+
headers: {
|
|
448
|
+
Authorization: `Bearer ${token}`,
|
|
449
|
+
'Content-Type': 'application/json',
|
|
450
|
+
},
|
|
451
|
+
body,
|
|
452
|
+
qs,
|
|
453
|
+
json: true,
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
catch (error) {
|
|
457
|
+
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
for (let i = 0; i < items.length; i++) {
|
|
461
|
+
try {
|
|
462
|
+
const resource = this.getNodeParameter('resource', i);
|
|
463
|
+
const operation = this.getNodeParameter('operation', i);
|
|
464
|
+
let responseData;
|
|
465
|
+
// ── PAGE ──────────────────────────────────────────────────────────────
|
|
466
|
+
if (resource === 'page') {
|
|
467
|
+
if (operation === 'getInfo') {
|
|
468
|
+
responseData = await makeRequest('GET', '/fb/page/getInfo');
|
|
469
|
+
}
|
|
470
|
+
else if (operation === 'getTags') {
|
|
471
|
+
responseData = await makeRequest('GET', '/fb/page/getTags');
|
|
472
|
+
}
|
|
473
|
+
else if (operation === 'getCustomFields') {
|
|
474
|
+
responseData = await makeRequest('GET', '/fb/page/getCustomFields');
|
|
475
|
+
}
|
|
476
|
+
else if (operation === 'getGrowthTools') {
|
|
477
|
+
responseData = await makeRequest('GET', '/fb/page/getGrowthTools');
|
|
478
|
+
}
|
|
479
|
+
else if (operation === 'getFlows') {
|
|
480
|
+
responseData = await makeRequest('GET', '/fb/page/getFlows');
|
|
481
|
+
}
|
|
482
|
+
else if (operation === 'getOtnTopics') {
|
|
483
|
+
responseData = await makeRequest('GET', '/fb/page/getOtnTopics');
|
|
484
|
+
}
|
|
485
|
+
else if (operation === 'getBotFields') {
|
|
486
|
+
responseData = await makeRequest('GET', '/fb/page/getBotFields');
|
|
487
|
+
}
|
|
488
|
+
else if (operation === 'createTag') {
|
|
489
|
+
const name = this.getNodeParameter('name', i);
|
|
490
|
+
responseData = await makeRequest('POST', '/fb/page/createTag', { name });
|
|
491
|
+
}
|
|
492
|
+
else if (operation === 'removeTag') {
|
|
493
|
+
const tag_id = this.getNodeParameter('tag_id', i);
|
|
494
|
+
responseData = await makeRequest('POST', '/fb/page/removeTag', { tag_id });
|
|
495
|
+
}
|
|
496
|
+
else if (operation === 'removeTagByName') {
|
|
497
|
+
const tag_name = this.getNodeParameter('tag_name', i);
|
|
498
|
+
responseData = await makeRequest('POST', '/fb/page/removeTagByName', { tag_name });
|
|
499
|
+
}
|
|
500
|
+
else if (operation === 'createCustomField') {
|
|
501
|
+
const caption = this.getNodeParameter('caption', i);
|
|
502
|
+
const type = this.getNodeParameter('type', i);
|
|
503
|
+
const description = this.getNodeParameter('description', i);
|
|
504
|
+
const body = { caption, type };
|
|
505
|
+
if (description)
|
|
506
|
+
body.description = description;
|
|
507
|
+
responseData = await makeRequest('POST', '/fb/page/createCustomField', body);
|
|
508
|
+
}
|
|
509
|
+
else if (operation === 'createBotField') {
|
|
510
|
+
const name = this.getNodeParameter('name', i);
|
|
511
|
+
const type = this.getNodeParameter('type', i);
|
|
512
|
+
const description = this.getNodeParameter('description', i);
|
|
513
|
+
const value = this.getNodeParameter('value', i);
|
|
514
|
+
const body = { name, type };
|
|
515
|
+
if (description)
|
|
516
|
+
body.description = description;
|
|
517
|
+
if (value)
|
|
518
|
+
body.value = value;
|
|
519
|
+
responseData = await makeRequest('POST', '/fb/page/createBotField', body);
|
|
520
|
+
}
|
|
521
|
+
else if (operation === 'setBotField') {
|
|
522
|
+
const field_id = this.getNodeParameter('field_id', i);
|
|
523
|
+
const field_value = this.getNodeParameter('field_value', i);
|
|
524
|
+
responseData = await makeRequest('POST', '/fb/page/setBotField', { field_id, field_value });
|
|
525
|
+
}
|
|
526
|
+
else if (operation === 'setBotFieldByName') {
|
|
527
|
+
const field_name = this.getNodeParameter('field_name', i);
|
|
528
|
+
const field_value = this.getNodeParameter('field_value', i);
|
|
529
|
+
responseData = await makeRequest('POST', '/fb/page/setBotFieldByName', { field_name, field_value });
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown page operation: ${operation}`, { itemIndex: i });
|
|
533
|
+
}
|
|
534
|
+
// ── SENDING ───────────────────────────────────────────────────────────
|
|
535
|
+
}
|
|
536
|
+
else if (resource === 'sending') {
|
|
537
|
+
const subscriber_id = this.getNodeParameter('subscriber_id', i);
|
|
538
|
+
if (operation === 'sendFlow') {
|
|
539
|
+
const flow_ns = this.getNodeParameter('flow_ns', i);
|
|
540
|
+
responseData = await makeRequest('POST', '/fb/sending/sendFlow', { subscriber_id, flow_ns });
|
|
541
|
+
}
|
|
542
|
+
else if (operation === 'sendContent') {
|
|
543
|
+
const dataRaw = this.getNodeParameter('data', i);
|
|
544
|
+
const data = typeof dataRaw === 'string' ? JSON.parse(dataRaw) : dataRaw;
|
|
545
|
+
const message_tag = this.getNodeParameter('message_tag', i);
|
|
546
|
+
const otn_topic_name = this.getNodeParameter('otn_topic_name', i);
|
|
547
|
+
const body = { subscriber_id, data };
|
|
548
|
+
if (message_tag)
|
|
549
|
+
body.message_tag = message_tag;
|
|
550
|
+
if (otn_topic_name)
|
|
551
|
+
body.otn_topic_name = otn_topic_name;
|
|
552
|
+
responseData = await makeRequest('POST', '/fb/sending/sendContent', body);
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown sending operation: ${operation}`, { itemIndex: i });
|
|
556
|
+
}
|
|
557
|
+
// ── SUBSCRIBER ────────────────────────────────────────────────────────
|
|
558
|
+
}
|
|
559
|
+
else if (resource === 'subscriber') {
|
|
560
|
+
if (operation === 'getInfo') {
|
|
561
|
+
const subscriber_id = this.getNodeParameter('subscriber_id', i);
|
|
562
|
+
responseData = await makeRequest('GET', '/fb/subscriber/getInfo', undefined, { subscriber_id });
|
|
563
|
+
}
|
|
564
|
+
else if (operation === 'findByName') {
|
|
565
|
+
const name = this.getNodeParameter('name', i);
|
|
566
|
+
responseData = await makeRequest('GET', '/fb/subscriber/findByName', undefined, { name });
|
|
567
|
+
}
|
|
568
|
+
else if (operation === 'findByCustomField') {
|
|
569
|
+
const field_id = this.getNodeParameter('field_id', i);
|
|
570
|
+
const field_value = this.getNodeParameter('field_value', i);
|
|
571
|
+
responseData = await makeRequest('GET', '/fb/subscriber/findByCustomField', undefined, { field_id, field_value });
|
|
572
|
+
}
|
|
573
|
+
else if (operation === 'findBySystemField') {
|
|
574
|
+
const email = this.getNodeParameter('email', i);
|
|
575
|
+
const phone = this.getNodeParameter('phone', i);
|
|
576
|
+
if (!email && !phone) {
|
|
577
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Provide at least one of Email or Phone', { itemIndex: i });
|
|
578
|
+
}
|
|
579
|
+
const qs = {};
|
|
580
|
+
if (email)
|
|
581
|
+
qs.email = email;
|
|
582
|
+
if (phone)
|
|
583
|
+
qs.phone = phone;
|
|
584
|
+
responseData = await makeRequest('GET', '/fb/subscriber/findBySystemField', undefined, qs);
|
|
585
|
+
}
|
|
586
|
+
else if (operation === 'addTag') {
|
|
587
|
+
const subscriber_id = this.getNodeParameter('subscriber_id', i);
|
|
588
|
+
const tag_id = this.getNodeParameter('tag_id', i);
|
|
589
|
+
responseData = await makeRequest('POST', '/fb/subscriber/addTag', { subscriber_id, tag_id });
|
|
590
|
+
}
|
|
591
|
+
else if (operation === 'addTagByName') {
|
|
592
|
+
const subscriber_id = this.getNodeParameter('subscriber_id', i);
|
|
593
|
+
const tag_name = this.getNodeParameter('tag_name', i);
|
|
594
|
+
responseData = await makeRequest('POST', '/fb/subscriber/addTagByName', { subscriber_id, tag_name });
|
|
595
|
+
}
|
|
596
|
+
else if (operation === 'removeTag') {
|
|
597
|
+
const subscriber_id = this.getNodeParameter('subscriber_id', i);
|
|
598
|
+
const tag_id = this.getNodeParameter('tag_id', i);
|
|
599
|
+
responseData = await makeRequest('POST', '/fb/subscriber/removeTag', { subscriber_id, tag_id });
|
|
600
|
+
}
|
|
601
|
+
else if (operation === 'removeTagByName') {
|
|
602
|
+
const subscriber_id = this.getNodeParameter('subscriber_id', i);
|
|
603
|
+
const tag_name = this.getNodeParameter('tag_name', i);
|
|
604
|
+
responseData = await makeRequest('POST', '/fb/subscriber/removeTagByName', { subscriber_id, tag_name });
|
|
605
|
+
}
|
|
606
|
+
else if (operation === 'setCustomField') {
|
|
607
|
+
const subscriber_id = this.getNodeParameter('subscriber_id', i);
|
|
608
|
+
const field_id = this.getNodeParameter('field_id', i);
|
|
609
|
+
const field_value = this.getNodeParameter('field_value', i);
|
|
610
|
+
responseData = await makeRequest('POST', '/fb/subscriber/setCustomField', { subscriber_id, field_id, field_value });
|
|
611
|
+
}
|
|
612
|
+
else if (operation === 'setCustomFieldByName') {
|
|
613
|
+
const subscriber_id = this.getNodeParameter('subscriber_id', i);
|
|
614
|
+
const field_name = this.getNodeParameter('field_name', i);
|
|
615
|
+
const field_value = this.getNodeParameter('field_value', i);
|
|
616
|
+
responseData = await makeRequest('POST', '/fb/subscriber/setCustomFieldByName', { subscriber_id, field_name, field_value });
|
|
617
|
+
}
|
|
618
|
+
else if (operation === 'createSubscriber') {
|
|
619
|
+
const body = {};
|
|
620
|
+
const first_name = this.getNodeParameter('first_name', i);
|
|
621
|
+
const last_name = this.getNodeParameter('last_name', i);
|
|
622
|
+
const phone = this.getNodeParameter('phone', i);
|
|
623
|
+
const whatsapp_phone = this.getNodeParameter('whatsapp_phone', i);
|
|
624
|
+
const email = this.getNodeParameter('email', i);
|
|
625
|
+
const gender = this.getNodeParameter('gender', i);
|
|
626
|
+
const has_opt_in_sms = this.getNodeParameter('has_opt_in_sms', i);
|
|
627
|
+
const has_opt_in_email = this.getNodeParameter('has_opt_in_email', i);
|
|
628
|
+
const consent_phrase = this.getNodeParameter('consent_phrase', i);
|
|
629
|
+
if (first_name)
|
|
630
|
+
body.first_name = first_name;
|
|
631
|
+
if (last_name)
|
|
632
|
+
body.last_name = last_name;
|
|
633
|
+
if (phone)
|
|
634
|
+
body.phone = phone;
|
|
635
|
+
if (whatsapp_phone)
|
|
636
|
+
body.whatsapp_phone = whatsapp_phone;
|
|
637
|
+
if (email)
|
|
638
|
+
body.email = email;
|
|
639
|
+
if (gender)
|
|
640
|
+
body.gender = gender;
|
|
641
|
+
body.has_opt_in_sms = has_opt_in_sms;
|
|
642
|
+
body.has_opt_in_email = has_opt_in_email;
|
|
643
|
+
if (consent_phrase)
|
|
644
|
+
body.consent_phrase = consent_phrase;
|
|
645
|
+
responseData = await makeRequest('POST', '/fb/subscriber/createSubscriber', body);
|
|
646
|
+
}
|
|
647
|
+
else if (operation === 'updateSubscriber') {
|
|
648
|
+
const subscriber_id = this.getNodeParameter('subscriber_id', i);
|
|
649
|
+
const body = { subscriber_id };
|
|
650
|
+
const first_name = this.getNodeParameter('first_name', i);
|
|
651
|
+
const last_name = this.getNodeParameter('last_name', i);
|
|
652
|
+
const phone = this.getNodeParameter('phone', i);
|
|
653
|
+
const email = this.getNodeParameter('email', i);
|
|
654
|
+
const gender = this.getNodeParameter('gender', i);
|
|
655
|
+
const has_opt_in_sms = this.getNodeParameter('has_opt_in_sms', i);
|
|
656
|
+
const has_opt_in_email = this.getNodeParameter('has_opt_in_email', i);
|
|
657
|
+
const consent_phrase = this.getNodeParameter('consent_phrase', i);
|
|
658
|
+
if (first_name)
|
|
659
|
+
body.first_name = first_name;
|
|
660
|
+
if (last_name)
|
|
661
|
+
body.last_name = last_name;
|
|
662
|
+
if (phone)
|
|
663
|
+
body.phone = phone;
|
|
664
|
+
if (email)
|
|
665
|
+
body.email = email;
|
|
666
|
+
if (gender)
|
|
667
|
+
body.gender = gender;
|
|
668
|
+
body.has_opt_in_sms = has_opt_in_sms;
|
|
669
|
+
body.has_opt_in_email = has_opt_in_email;
|
|
670
|
+
if (consent_phrase)
|
|
671
|
+
body.consent_phrase = consent_phrase;
|
|
672
|
+
responseData = await makeRequest('POST', '/fb/subscriber/updateSubscriber', body);
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown subscriber operation: ${operation}`, { itemIndex: i });
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown resource: ${resource}`, { itemIndex: i });
|
|
680
|
+
}
|
|
681
|
+
returnData.push(...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } }));
|
|
682
|
+
}
|
|
683
|
+
catch (error) {
|
|
684
|
+
if (this.continueOnFail()) {
|
|
685
|
+
returnData.push(...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } }));
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
throw error;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return [returnData];
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
exports.Manychat = Manychat;
|
|
695
|
+
//# sourceMappingURL=Manychat.node.js.map
|