n8n-nodes-mbkchat 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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # n8n-nodes-mbkchat
2
2
 
3
- This is an n8n node for connecting to WuzAPI (MBKChat).
3
+ This is an n8n node for connecting to MBKChat (MbkChat).
4
4
 
5
5
  ## Installation
6
6
 
@@ -26,12 +26,12 @@ To install this node in your n8n installation, verify you have **Node.js** and *
26
26
  ```
27
27
 
28
28
  4. **Restart n8n**:
29
- Restart your n8n server. You should see "MBKChat (WuzAPI)" in the nodes list.
29
+ Restart your n8n server. You should see "MBKChat" in the nodes list.
30
30
 
31
31
  ## Credentials
32
32
 
33
- You will need to create a new Credential of type "WuzAPI API" in n8n.
34
- - **Base URL**: The URL where your WuzAPI is running (e.g. `http://localhost:8080`).
33
+ You will need to create a new Credential of type "MBKChat API" in n8n.
34
+ - **Base URL**: The URL where your MBKChat is running (e.g. `http://localhost:8080`).
35
35
  - **Token**: Your user token or admin token.
36
36
 
37
37
  ## Operations
@@ -57,6 +57,16 @@ You will need to create a new Credential of type "WuzAPI API" in n8n.
57
57
  ### Group
58
58
  - **List**: Lists all subscribed groups.
59
59
 
60
+ ## Publishing to n8n Community Nodes
61
+
62
+ To make this node available to everyone:
63
+
64
+ 1. **Register on npm**: Create an account on [npmjs.com](https://www.npmjs.com/).
65
+ 2. **Login**: `npm login` in your terminal.
66
+ 3. **Publish**: `npm publish --access public`.
67
+
68
+ Once published, it will eventually appear in n8n's community node list (it may take some time to be indexed).
69
+
60
70
  ## License
61
71
 
62
72
  MIT
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WuzApi = void 0;
4
+ class WuzApi {
5
+ constructor() {
6
+ this.name = 'wuzApi';
7
+ this.displayName = 'MBKChat API';
8
+ this.documentationUrl = 'https://github.com/guilhermejansen/wuzapi';
9
+ this.properties = [
10
+ {
11
+ displayName: 'Base URL',
12
+ name: 'baseUrl',
13
+ type: 'string',
14
+ default: 'http://localhost:8080',
15
+ description: 'The URL of your WuzAPI server',
16
+ required: true,
17
+ },
18
+ {
19
+ displayName: 'Token',
20
+ name: 'token',
21
+ type: 'string',
22
+ typeOptions: {
23
+ password: true,
24
+ },
25
+ default: '',
26
+ description: 'The authentication token (User or Admin token)',
27
+ required: true,
28
+ },
29
+ ];
30
+ }
31
+ }
32
+ exports.WuzApi = WuzApi;
@@ -0,0 +1,490 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WuzApi = void 0;
4
+ class WuzApi {
5
+ constructor() {
6
+ this.description = {
7
+ displayName: 'MBKChat (WuzAPI)',
8
+ name: 'wuzApi',
9
+ icon: 'file:wuzapi.png',
10
+ group: ['transform'],
11
+ version: 1,
12
+ description: 'Consume WuzAPI API (MBKChat)',
13
+ defaults: {
14
+ name: 'WuzAPI',
15
+ color: '#1F845A',
16
+ },
17
+ inputs: ['main'],
18
+ outputs: ['main'],
19
+ credentials: [
20
+ {
21
+ name: 'wuzApi',
22
+ required: true,
23
+ },
24
+ ],
25
+ properties: [
26
+ {
27
+ displayName: 'Resource',
28
+ name: 'resource',
29
+ type: 'options',
30
+ options: [
31
+ {
32
+ name: 'Session',
33
+ value: 'session',
34
+ },
35
+ {
36
+ name: 'Chat',
37
+ value: 'chat',
38
+ },
39
+ {
40
+ name: 'User',
41
+ value: 'user',
42
+ },
43
+ {
44
+ name: 'Group',
45
+ value: 'group',
46
+ },
47
+ ],
48
+ default: 'chat',
49
+ description: 'The resource to operate on.',
50
+ },
51
+ // ----------------------------------
52
+ // Session
53
+ // ----------------------------------
54
+ {
55
+ displayName: 'Operation',
56
+ name: 'operation',
57
+ type: 'options',
58
+ displayOptions: {
59
+ show: {
60
+ resource: [
61
+ 'session',
62
+ ],
63
+ },
64
+ },
65
+ options: [
66
+ {
67
+ name: 'Connect',
68
+ value: 'connect',
69
+ description: 'Connect to Whatsapp servers',
70
+ },
71
+ {
72
+ name: 'Disconnect',
73
+ value: 'disconnect',
74
+ description: 'Disconnect from Whatsapp servers',
75
+ },
76
+ {
77
+ name: 'Logout',
78
+ value: 'logout',
79
+ description: 'Logout from Whatsapp session',
80
+ },
81
+ {
82
+ name: 'Status',
83
+ value: 'status',
84
+ description: 'Get session status',
85
+ },
86
+ {
87
+ name: 'Get QR',
88
+ value: 'qr',
89
+ description: 'Get QR code for scanning',
90
+ },
91
+ ],
92
+ default: 'status',
93
+ description: 'The operation to perform.',
94
+ },
95
+ {
96
+ displayName: 'Subscribe Events',
97
+ name: 'subscribe',
98
+ type: 'multiOptions',
99
+ displayOptions: {
100
+ show: {
101
+ resource: [
102
+ 'session',
103
+ ],
104
+ operation: [
105
+ 'connect',
106
+ ],
107
+ },
108
+ },
109
+ options: [
110
+ {
111
+ name: 'Message',
112
+ value: 'Message',
113
+ },
114
+ {
115
+ name: 'ReadReceipt',
116
+ value: 'ReadReceipt',
117
+ },
118
+ {
119
+ name: 'HistorySync',
120
+ value: 'HistorySync',
121
+ },
122
+ {
123
+ name: 'ChatPresence',
124
+ value: 'ChatPresence',
125
+ },
126
+ ],
127
+ default: ['Message'],
128
+ description: 'Events to subscribe to',
129
+ },
130
+ {
131
+ displayName: 'Immediate',
132
+ name: 'immediate',
133
+ type: 'boolean',
134
+ displayOptions: {
135
+ show: {
136
+ resource: [
137
+ 'session',
138
+ ],
139
+ operation: [
140
+ 'connect',
141
+ ],
142
+ },
143
+ },
144
+ default: false,
145
+ description: 'If false, waits 10 seconds to verify login',
146
+ },
147
+ // ----------------------------------
148
+ // Chat
149
+ // ----------------------------------
150
+ {
151
+ displayName: 'Operation',
152
+ name: 'operation',
153
+ type: 'options',
154
+ displayOptions: {
155
+ show: {
156
+ resource: [
157
+ 'chat',
158
+ ],
159
+ },
160
+ },
161
+ options: [
162
+ {
163
+ name: 'Send Text',
164
+ value: 'sendText',
165
+ description: 'Send a text message',
166
+ },
167
+ {
168
+ name: 'Send Image',
169
+ value: 'sendImage',
170
+ description: 'Send an image',
171
+ },
172
+ {
173
+ name: 'Send Video',
174
+ value: 'sendVideo',
175
+ description: 'Send a video',
176
+ },
177
+ {
178
+ name: 'Send Audio',
179
+ value: 'sendAudio',
180
+ description: 'Send an audio file',
181
+ },
182
+ {
183
+ name: 'Send Document',
184
+ value: 'sendDocument',
185
+ description: 'Send a document',
186
+ },
187
+ ],
188
+ default: 'sendText',
189
+ description: 'The operation to perform.',
190
+ },
191
+ {
192
+ displayName: 'Phone',
193
+ name: 'phone',
194
+ type: 'string',
195
+ required: true,
196
+ displayOptions: {
197
+ show: {
198
+ resource: [
199
+ 'chat',
200
+ ],
201
+ operation: [
202
+ 'sendText',
203
+ 'sendImage',
204
+ 'sendVideo',
205
+ 'sendAudio',
206
+ 'sendDocument',
207
+ ],
208
+ },
209
+ },
210
+ default: '',
211
+ description: 'Phone number to send message to (e.g. 5511999999999)',
212
+ },
213
+ {
214
+ displayName: 'Message Body',
215
+ name: 'body',
216
+ type: 'string',
217
+ typeOptions: {
218
+ rows: 4,
219
+ },
220
+ displayOptions: {
221
+ show: {
222
+ resource: [
223
+ 'chat',
224
+ ],
225
+ operation: [
226
+ 'sendText',
227
+ ],
228
+ },
229
+ },
230
+ default: '',
231
+ description: 'The text message to send',
232
+ },
233
+ {
234
+ displayName: 'Caption',
235
+ name: 'caption',
236
+ type: 'string',
237
+ displayOptions: {
238
+ show: {
239
+ resource: [
240
+ 'chat',
241
+ ],
242
+ operation: [
243
+ 'sendImage',
244
+ 'sendVideo',
245
+ ],
246
+ },
247
+ },
248
+ default: '',
249
+ description: 'Caption for the media',
250
+ },
251
+ {
252
+ displayName: 'Base64 Data',
253
+ name: 'data',
254
+ type: 'string',
255
+ displayOptions: {
256
+ show: {
257
+ resource: [
258
+ 'chat',
259
+ ],
260
+ operation: [
261
+ 'sendImage',
262
+ 'sendVideo',
263
+ 'sendAudio',
264
+ 'sendDocument',
265
+ ],
266
+ },
267
+ },
268
+ default: '',
269
+ description: 'Base64 encoded data (with or without data URI scheme)',
270
+ },
271
+ {
272
+ displayName: 'File Name',
273
+ name: 'fileName',
274
+ type: 'string',
275
+ displayOptions: {
276
+ show: {
277
+ resource: [
278
+ 'chat',
279
+ ],
280
+ operation: [
281
+ 'sendDocument',
282
+ ],
283
+ },
284
+ },
285
+ default: 'file.txt',
286
+ description: 'Name of the file',
287
+ },
288
+ // ----------------------------------
289
+ // User
290
+ // ----------------------------------
291
+ {
292
+ displayName: 'Operation',
293
+ name: 'operation',
294
+ type: 'options',
295
+ displayOptions: {
296
+ show: {
297
+ resource: [
298
+ 'user',
299
+ ],
300
+ },
301
+ },
302
+ options: [
303
+ {
304
+ name: 'Info',
305
+ value: 'info',
306
+ description: 'Get user info',
307
+ },
308
+ {
309
+ name: 'Check',
310
+ value: 'check',
311
+ description: 'Check if user is on WhatsApp',
312
+ },
313
+ ],
314
+ default: 'check',
315
+ },
316
+ {
317
+ displayName: 'Phones',
318
+ name: 'users',
319
+ type: 'string',
320
+ displayOptions: {
321
+ show: {
322
+ resource: [
323
+ 'user',
324
+ ],
325
+ },
326
+ },
327
+ default: '',
328
+ description: 'Comma separated list of phone numbers',
329
+ },
330
+ // ----------------------------------
331
+ // Group
332
+ // ----------------------------------
333
+ {
334
+ displayName: 'Operation',
335
+ name: 'operation',
336
+ type: 'options',
337
+ displayOptions: {
338
+ show: {
339
+ resource: [
340
+ 'group',
341
+ ],
342
+ },
343
+ },
344
+ options: [
345
+ {
346
+ name: 'List',
347
+ value: 'list',
348
+ description: 'List subscribed groups',
349
+ },
350
+ ],
351
+ default: 'list',
352
+ },
353
+ ],
354
+ };
355
+ }
356
+ async execute() {
357
+ const items = this.getInputData();
358
+ const returnData = [];
359
+ const resource = this.getNodeParameter('resource', 0);
360
+ const operation = this.getNodeParameter('operation', 0);
361
+ for (let i = 0; i < items.length; i++) {
362
+ try {
363
+ let responseData;
364
+ const credentials = await this.getCredentials('wuzApi');
365
+ // const baseUrl = credentials.baseUrl as string; // Handled by helpers.request if we used property based credentials, but here we construct URL manually or use base option.
366
+ // Actually n8n helpers.requestWithAuthentication finds the credential by name 'wuzApi' and expects the credential object to have standard auth properties or we manually use it.
367
+ // Since we defined custom credential properties (baseUrl, token), we should construct request manually or use a helper that injects them.
368
+ // Standard request object
369
+ const options = {
370
+ headers: {
371
+ 'Accept': 'application/json',
372
+ 'Content-Type': 'application/json',
373
+ 'Token': credentials.token,
374
+ },
375
+ uri: `${credentials.baseUrl}`,
376
+ json: true,
377
+ };
378
+ if (resource === 'session') {
379
+ if (operation === 'status') {
380
+ options.method = 'GET';
381
+ options.uri += '/session/status';
382
+ }
383
+ else if (operation === 'qr') {
384
+ options.method = 'GET';
385
+ options.uri += '/session/qr';
386
+ }
387
+ else if (operation === 'connect') {
388
+ options.method = 'POST';
389
+ options.uri += '/session/connect';
390
+ const subscribe = this.getNodeParameter('subscribe', i);
391
+ const immediate = this.getNodeParameter('immediate', i);
392
+ options.body = {
393
+ Subscribe: subscribe,
394
+ Immediate: immediate,
395
+ };
396
+ }
397
+ else if (operation === 'disconnect') {
398
+ options.method = 'POST';
399
+ options.uri += '/session/disconnect';
400
+ }
401
+ else if (operation === 'logout') {
402
+ options.method = 'POST';
403
+ options.uri += '/session/logout';
404
+ }
405
+ }
406
+ else if (resource === 'chat') {
407
+ const phone = this.getNodeParameter('phone', i);
408
+ if (operation === 'sendText') {
409
+ options.method = 'POST';
410
+ options.uri += '/chat/send/text';
411
+ options.body = {
412
+ Phone: phone,
413
+ Body: this.getNodeParameter('body', i),
414
+ };
415
+ }
416
+ else if (operation === 'sendImage') {
417
+ options.method = 'POST';
418
+ options.uri += '/chat/send/image';
419
+ options.body = {
420
+ Phone: phone,
421
+ Caption: this.getNodeParameter('caption', i),
422
+ Image: this.getNodeParameter('data', i),
423
+ };
424
+ }
425
+ else if (operation === 'sendVideo') {
426
+ options.method = 'POST';
427
+ options.uri += '/chat/send/video';
428
+ options.body = {
429
+ Phone: phone,
430
+ Caption: this.getNodeParameter('caption', i),
431
+ Video: this.getNodeParameter('data', i),
432
+ };
433
+ }
434
+ else if (operation === 'sendAudio') {
435
+ options.method = 'POST';
436
+ options.uri += '/chat/send/audio';
437
+ options.body = {
438
+ Phone: phone,
439
+ Audio: this.getNodeParameter('data', i),
440
+ };
441
+ }
442
+ else if (operation === 'sendDocument') {
443
+ options.method = 'POST';
444
+ options.uri += '/chat/send/document';
445
+ options.body = {
446
+ Phone: phone,
447
+ FileName: this.getNodeParameter('fileName', i),
448
+ Document: this.getNodeParameter('data', i),
449
+ };
450
+ }
451
+ }
452
+ else if (resource === 'user') {
453
+ const phonesStr = this.getNodeParameter('users', i);
454
+ const phones = phonesStr.split(',').map(s => s.trim());
455
+ if (operation === 'info') {
456
+ options.method = 'POST';
457
+ options.uri += '/user/info';
458
+ options.body = {
459
+ Phone: phones,
460
+ };
461
+ }
462
+ else if (operation === 'check') {
463
+ options.method = 'POST';
464
+ options.uri += '/user/check';
465
+ options.body = {
466
+ Phone: phones,
467
+ };
468
+ }
469
+ }
470
+ else if (resource === 'group') {
471
+ if (operation === 'list') {
472
+ options.method = 'GET';
473
+ options.uri += '/group/list';
474
+ }
475
+ }
476
+ responseData = await this.helpers.request(options);
477
+ returnData.push(responseData);
478
+ }
479
+ catch (error) {
480
+ if (this.continueOnFail()) {
481
+ returnData.push({ error: error.message });
482
+ continue;
483
+ }
484
+ throw error;
485
+ }
486
+ }
487
+ return [this.helpers.returnJsonArray(returnData)];
488
+ }
489
+ }
490
+ exports.WuzApi = WuzApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-mbkchat",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Native n8n node for MBKChat",
5
5
  "keywords": [
6
6
  "n8n-community-node-package"
@@ -42,4 +42,4 @@
42
42
  "request": "^2.88.2",
43
43
  "request-promise-native": "^1.0.9"
44
44
  }
45
- }
45
+ }