n8n-nodes-zalo-custom 1.0.9 → 1.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.
@@ -6,6 +6,7 @@ const n8n_workflow_1 = require("n8n-workflow");
6
6
  const ZaloNodeProperties_1 = require("../shared/ZaloNodeProperties");
7
7
  const ZaloUserDescription_1 = require("./ZaloUserDescription");
8
8
  const zalo_helper_1 = require("../utils/zalo.helper");
9
+ const helper_1 = require("../utils/helper");
9
10
  let api;
10
11
  class ZaloUser {
11
12
  constructor() {
@@ -47,9 +48,20 @@ class ZaloUser {
47
48
  const items = this.getInputData();
48
49
  const returnData = [];
49
50
 
50
- api = await (0, zalo_helper_1.getZaloApiClient)(this, {});
51
- if (!api) {
52
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Failed to initialize Zalo API. Check credentials or User ID.');
51
+ const needsImageMetadataGetter = items.some((_, i) => {
52
+ try {
53
+ return this.getNodeParameter('operation', i) === 'changeAccountAvatar';
54
+ } catch (e) { return false; }
55
+ });
56
+
57
+ try {
58
+ api = await (0, zalo_helper_1.getZaloApiClient)(this, { needsImageMetadataGetter });
59
+ if (!api) {
60
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Failed to initialize Zalo API. Check credentials or User ID.');
61
+ }
62
+ }
63
+ catch (error) {
64
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Zalo login error: ${error.message}`);
53
65
  }
54
66
 
55
67
  for (let i = 0; i < items.length; i++) {
@@ -119,7 +131,7 @@ class ZaloUser {
119
131
  returnData.push({ json: { success: true, response }, pairedItem: { item: i } });
120
132
  break;
121
133
  }
122
- case 'getFriendOnlines': {
134
+ case 'getFriendOnlines': { // err
123
135
  const response = await api.getFriendOnlines();
124
136
  returnData.push({ json: { success: true, response }, pairedItem: { item: i } });
125
137
  break;
@@ -260,6 +272,93 @@ class ZaloUser {
260
272
  returnData.push({ json: { success: true, ...processedResponse }, pairedItem: { item: i } });
261
273
  break;
262
274
  }
275
+ case 'setMute': {
276
+ const threadId = this.getNodeParameter('threadId', i);
277
+ const muteAction = this.getNodeParameter('muteAction', i);
278
+ const type = this.getNodeParameter('threadType', i);
279
+ let duration = -1;
280
+ if (muteAction === 1) {
281
+ const durationParam = this.getNodeParameter('muteDuration', i);
282
+ if (durationParam === -2) {
283
+ duration = this.getNodeParameter('customMuteDuration', i) * 60;
284
+ console.log(duration)
285
+ } else {
286
+ duration = durationParam;
287
+ }
288
+ }
289
+ const params = {
290
+ action: muteAction,
291
+ duration: duration,
292
+ };
293
+ const response = await api.setMute(params, threadId, type);
294
+ returnData.push({ json: { success: true, response }, pairedItem: { item: i } });
295
+ break;
296
+ }
297
+ case 'deleteMessage': {
298
+ const threadId = this.getNodeParameter('threadId', i);
299
+ const uidFrom = this.getNodeParameter('userId', i);
300
+ const msgId = this.getNodeParameter('msgId', i);
301
+ const cliMsgId = this.getNodeParameter('cliMsgId', i);
302
+ const onlyMe = this.getNodeParameter('onlyMe', i, true);
303
+ const type = this.getNodeParameter('threadType', i);
304
+ const dest = {
305
+ data: { cliMsgId, msgId, uidFrom },
306
+ threadId: threadId,
307
+ type: type,
308
+ };
309
+ const response = await api.deleteMessage(dest, onlyMe);
310
+ returnData.push({ json: { success: true, response }, pairedItem: { item: i } });
311
+ break;
312
+ }
313
+ case 'updateSettings': {
314
+ const settings = this.getNodeParameter('updateSettingsOptions', i);
315
+ const results = {};
316
+ const keys = Object.keys(settings);
317
+ for (let k = 0; k < keys.length; k++) {
318
+ const key = keys[k];
319
+ const value = settings[key];
320
+ try {
321
+ const response = await api.updateSettings(key, value);
322
+ results[key] = { success: true, response };
323
+ } catch (error) {
324
+ results[key] = { success: false, error: error.message };
325
+ }
326
+ if (k < keys.length - 1) {
327
+ await new Promise((resolve) => setTimeout(resolve, 1000));
328
+ }
329
+ }
330
+ returnData.push({ json: { success: true, results }, pairedItem: { item: i } });
331
+ break;
332
+ }
333
+ case 'changeAccountAvatar': {
334
+ const imageUrl = this.getNodeParameter('imageUrl', i);
335
+ let finalAvatarSource;
336
+ let tempFilePath;
337
+ try {
338
+ if (!imageUrl) {
339
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Image URL is required for changing account avatar.', { itemIndex: i });
340
+ }
341
+ try {
342
+ new URL(imageUrl);
343
+ this.logger.info(`Downloading image from URL for avatar: ${imageUrl}`);
344
+ tempFilePath = await (0, helper_1.saveFile)(imageUrl);
345
+ finalAvatarSource = tempFilePath;
346
+ }
347
+ catch (urlError) {
348
+ this.logger.info(`Treating image URL as local file path for avatar: ${imageUrl}`);
349
+ finalAvatarSource = imageUrl;
350
+ }
351
+ const response = await api.changeAccountAvatar(finalAvatarSource);
352
+ returnData.push({ json: { success: true, response }, pairedItem: { item: i } });
353
+ }
354
+ finally {
355
+ if (tempFilePath) {
356
+ await (0, helper_1.removeFile)(tempFilePath);
357
+ this.logger.info(`Successfully removed temporary avatar file: ${tempFilePath}`);
358
+ }
359
+ }
360
+ break;
361
+ }
263
362
  }
264
363
  }
265
364
  }
@@ -91,12 +91,6 @@ exports.zaloUserOperations = [
91
91
  action: 'Lấy QR người dùng',
92
92
  description: 'Lấy QR của người dùng',
93
93
  },
94
- {
95
- name: 'Cập Nhật Thông Tin Tài Khoản',
96
- value: 'updateProfile',
97
- action: 'Cập nhật thông tin tài khoản',
98
- description: 'Cập nhật tên, ngày sinh, giới tính của tài khoản',
99
- },
100
94
  {
101
95
  name: 'Bỏ Chặn Người Dùng',
102
96
  value: 'unblockUser',
@@ -109,12 +103,6 @@ exports.zaloUserOperations = [
109
103
  action: 'Chặn người dùng',
110
104
  description: 'Chặn người dùng',
111
105
  },
112
- {
113
- name: 'Thu Hồi Tin Nhắn',
114
- value: 'undoMessage',
115
- action: 'Thu hồi tin nhắn',
116
- description: 'Thu hồi tin nhắn đã gửi',
117
- },
118
106
  {
119
107
  name: 'Đánh Dấu Tin Nhắn Chưa Đọc',
120
108
  value: 'addUnreadMark',
@@ -133,6 +121,24 @@ exports.zaloUserOperations = [
133
121
  action: 'Lấy trạng thái hoạt động của người dùng',
134
122
  description: 'Lấy thời gian hoạt động cuối cùng của một người dùng qua User ID',
135
123
  },
124
+ {
125
+ name: 'Tắt Hoặc Bật Thông Báo',
126
+ value: 'setMute',
127
+ action: 'Tắt hoặc bật thông báo',
128
+ description: 'Tắt hoặc bật thông báo cho Người dùng/Nhóm',
129
+ },
130
+ {
131
+ name: 'Xóa Tin Nhắn',
132
+ value: 'deleteMessage',
133
+ action: 'Xóa tin nhắn',
134
+ description: 'Xóa tin nhắn (chỉ mình tôi hoặc mọi người nếu là admin)',
135
+ },
136
+ {
137
+ name: 'Thu Hồi Tin Nhắn',
138
+ value: 'undoMessage',
139
+ action: 'Thu hồi tin nhắn',
140
+ description: 'Thu hồi tin nhắn đã gửi',
141
+ },
136
142
  {
137
143
  name: 'Lấy Thông Tin Tài Khoản',
138
144
  value: 'fetchAccountInfo',
@@ -146,30 +152,34 @@ exports.zaloUserOperations = [
146
152
  description: 'Lấy ngữ cảnh (context) của phiên làm việc hiện tại',
147
153
  },
148
154
  {
149
- name: 'Lấy Tin Nhắn Đến Cũ của tài khoản',
155
+ name: 'Lấy Tin Nhắn Đến Cũ Của Tài Khoản',
150
156
  value: 'getOldMessages',
151
157
  action: 'Lấy tin nhắn đến cũ của tài khoản',
152
158
  description: 'Lấy các tin nhắn cũ hơn trong một cuộc trò chuyện',
153
159
  },
160
+ {
161
+ name: 'Cập Nhật Thông Tin Tài Khoản',
162
+ value: 'updateProfile',
163
+ action: 'Cập nhật thông tin tài khoản',
164
+ description: 'Cập nhật tên, ngày sinh, giới tính của tài khoản',
165
+ },
166
+ {
167
+ name: 'Đổi Avatar Tài Khoản',
168
+ value: 'changeAccountAvatar',
169
+ action: 'Đổi avatar tài khoản',
170
+ description: 'Đổi ảnh đại diện của tài khoản hiện tại',
171
+ },
172
+ {
173
+ name: 'Cập Nhật Cài Đặt Quyền Riêng Tư',
174
+ value: 'updateSettings',
175
+ action: 'Cập nhật cài đặt quyền riêng tư',
176
+ description: 'Cập nhật các cài đặt quyền riêng tư (ngày sinh, trạng thái online, nguồn kết bạn...)',
177
+ },
154
178
  ],
155
179
  default: 'getUserInfo',
156
180
  },
157
181
  ];
158
182
  exports.zaloUserFields = [
159
- {
160
- displayName: 'Thread ID',
161
- name: 'threadId',
162
- type: 'string',
163
- required: true,
164
- displayOptions: {
165
- show: {
166
- resource: ['zaloUser'],
167
- operation: ['undoMessage', 'removeUnreadMark', 'addUnreadMark'],
168
- },
169
- },
170
- default: '',
171
- description: 'ID của cuộc trò chuyện (có thể là user ID hoặc group ID)',
172
- },
173
183
  {
174
184
  displayName: 'Thread Type',
175
185
  name: 'threadType',
@@ -178,23 +188,37 @@ exports.zaloUserFields = [
178
188
  displayOptions: {
179
189
  show: {
180
190
  resource: ['zaloUser'],
181
- operation: ['removeUnreadMark', 'addUnreadMark', 'undoMessage', 'getOldMessages'],
191
+ operation: ['removeUnreadMark', 'addUnreadMark', 'undoMessage', 'getOldMessages', 'setMute', 'deleteMessage'],
182
192
  },
183
193
  },
184
194
  options: [
185
195
  {
186
196
  name: 'User',
187
197
  value: 0,
188
- description: 'Cuộc trò chuyện với một người dùng',
198
+ description: 'Người dùng',
189
199
  },
190
200
  {
191
201
  name: 'Group',
192
202
  value: 1,
193
- description: 'Cuộc trò chuyện trong nhóm',
203
+ description: 'Nhóm',
194
204
  },
195
205
  ],
196
206
  default: 0,
197
- description: 'Loại cuộc trò chuyện.',
207
+ description: 'Loại cuộc trò chuyện đang tương tác',
208
+ },
209
+ {
210
+ displayName: 'Thread ID',
211
+ name: 'threadId',
212
+ type: 'string',
213
+ required: true,
214
+ displayOptions: {
215
+ show: {
216
+ resource: ['zaloUser'],
217
+ operation: ['undoMessage', 'removeUnreadMark', 'addUnreadMark', 'setMute', 'deleteMessage'],
218
+ },
219
+ },
220
+ default: '',
221
+ description: 'ID của cuộc trò chuyện (có thể là user ID hoặc group ID)',
198
222
  },
199
223
  {
200
224
  displayName: 'msgId',
@@ -204,7 +228,7 @@ exports.zaloUserFields = [
204
228
  displayOptions: {
205
229
  show: {
206
230
  resource: ['zaloUser'],
207
- operation: ['undoMessage'],
231
+ operation: ['undoMessage', 'deleteMessage'],
208
232
  },
209
233
  },
210
234
  default: '',
@@ -218,7 +242,7 @@ exports.zaloUserFields = [
218
242
  displayOptions: {
219
243
  show: {
220
244
  resource: ['zaloUser'],
221
- operation: ['undoMessage'],
245
+ operation: ['undoMessage', 'deleteMessage'],
222
246
  },
223
247
  },
224
248
  default: '',
@@ -244,6 +268,7 @@ exports.zaloUserFields = [
244
268
  'undoFriendRequest',
245
269
  'getQR',
246
270
  'getLastOnline',
271
+ 'deleteMessage',
247
272
  ],
248
273
  },
249
274
  },
@@ -349,6 +374,20 @@ exports.zaloUserFields = [
349
374
  default: 1,
350
375
  description: 'Giới tính',
351
376
  },
377
+ {
378
+ displayName: 'URL Ảnh',
379
+ name: 'imageUrl',
380
+ type: 'string',
381
+ required: true,
382
+ default: '',
383
+ displayOptions: {
384
+ show: {
385
+ resource: ['zaloUser'],
386
+ operation: ['changeAccountAvatar'],
387
+ },
388
+ },
389
+ description: 'URL ảnh (nếu avatar cần ảnh hơn 240x240 rõ nét để tránh bị gỡ)',
390
+ },
352
391
  {
353
392
  displayName: 'Language',
354
393
  name: 'language',
@@ -377,18 +416,229 @@ exports.zaloUserFields = [
377
416
  default: '',
378
417
  description: 'Số điện thoại cần tìm kiếm',
379
418
  },
380
- // {
381
- // displayName: 'Limit',
382
- // name: 'limit',
383
- // type: 'number',
384
- // required: true,
385
- // displayOptions: {
386
- // show: {
387
- // resource: ['zaloUser'],
388
- // operation: [''],
389
- // },
390
- // },
391
- // default: 50,
392
- // description: 'Số lượng kết quả tối đa',
393
- // },
419
+ {
420
+ displayName: 'Hành Động',
421
+ name: 'muteAction',
422
+ type: 'options',
423
+ options: [
424
+ {
425
+ name: 'Tắt Thông Báo',
426
+ value: 1,
427
+ },
428
+ {
429
+ name: 'Bật Thông Báo',
430
+ value: 3,
431
+ },
432
+ ],
433
+ default: 1,
434
+ displayOptions: {
435
+ show: {
436
+ resource: ['zaloUser'],
437
+ operation: ['setMute'],
438
+ },
439
+ },
440
+ description: 'Chọn hành động tắt hoặc bật thông báo',
441
+ },
442
+ {
443
+ displayName: 'Thời Gian Tắt',
444
+ name: 'muteDuration',
445
+ type: 'options',
446
+ options: [
447
+ {
448
+ name: '1 Giờ',
449
+ value: 3600,
450
+ },
451
+ {
452
+ name: '4 Giờ',
453
+ value: 14400,
454
+ },
455
+ {
456
+ name: 'Đến 8h Sáng',
457
+ value: 'until8AM',
458
+ },
459
+ {
460
+ name: 'Vĩnh Viễn',
461
+ value: -1,
462
+ },
463
+ {
464
+ name: 'Tùy Chỉnh (Phút)',
465
+ value: -2,
466
+ },
467
+ ],
468
+ default: -1,
469
+ displayOptions: {
470
+ show: {
471
+ resource: ['zaloUser'],
472
+ operation: ['setMute'],
473
+ muteAction: [1],
474
+ },
475
+ },
476
+ description: 'Thời gian tắt thông báo',
477
+ },
478
+ {
479
+ displayName: 'Số Phút',
480
+ name: 'customMuteDuration',
481
+ type: 'number',
482
+ default: 5,
483
+ required: true,
484
+ displayOptions: {
485
+ show: {
486
+ resource: ['zaloUser'],
487
+ operation: ['setMute'],
488
+ muteAction: [1],
489
+ muteDuration: [-2],
490
+ },
491
+ },
492
+ description: 'Nhập số phút muốn tắt thông báo',
493
+ },
494
+ {
495
+ displayName: 'Only Me',
496
+ name: 'onlyMe',
497
+ type: 'boolean',
498
+ default: true,
499
+ displayOptions: {
500
+ show: {
501
+ resource: ['zaloUser'],
502
+ operation: ['deleteMessage'],
503
+ },
504
+ },
505
+ description: 'Bật để xóa tin nhắn ở phía bạn. Tắt để xóa với mọi người (quyền admin)',
506
+ },
507
+ {
508
+ displayName: 'Cài Đặt Quyền Riêng Tư',
509
+ name: 'updateSettingsOptions',
510
+ type: 'collection',
511
+ placeholder: 'Thêm Cài Đặt',
512
+ default: {},
513
+ displayOptions: {
514
+ show: {
515
+ resource: ['zaloUser'],
516
+ operation: ['updateSettings'],
517
+ },
518
+ },
519
+ options: [
520
+ {
521
+ displayName: 'Hiển Thị Ngày Sinh',
522
+ name: 'view_birthday',
523
+ type: 'options',
524
+ default: 0,
525
+ options: [
526
+ { name: 'Ẩn', value: 0 },
527
+ { name: 'Hiện Ngày/Tháng/Năm', value: 1 },
528
+ { name: 'Hiện Ngày/Tháng', value: 2 },
529
+ ],
530
+ },
531
+ {
532
+ displayName: 'Trạng Thái Online',
533
+ name: 'show_online_status',
534
+ type: 'options',
535
+ default: 1,
536
+ options: [
537
+ { name: 'Ẩn', value: 0 },
538
+ { name: 'Hiện', value: 1 },
539
+ ],
540
+ },
541
+ {
542
+ displayName: 'Trạng Thái Đã Xem',
543
+ name: 'display_seen_status',
544
+ type: 'options',
545
+ default: 1,
546
+ options: [
547
+ { name: 'Ẩn', value: 0 },
548
+ { name: 'Hiện', value: 1 },
549
+ ],
550
+ },
551
+ {
552
+ displayName: 'Nhận Tin Nhắn Từ',
553
+ name: 'receive_message',
554
+ type: 'options',
555
+ default: 1,
556
+ options: [
557
+ { name: 'Mọi Người', value: 1 },
558
+ { name: 'Chỉ Bạn Bè', value: 2 },
559
+ ],
560
+ },
561
+ {
562
+ displayName: 'Nhận Cuộc Gọi Từ',
563
+ name: 'accept_stranger_call',
564
+ type: 'options',
565
+ default: 3,
566
+ options: [
567
+ { name: 'Chỉ Bạn Bè', value: 2 },
568
+ { name: 'Mọi Người', value: 3 },
569
+ { name: 'Bạn Bè & Người Lạ Từng Liên Hệ', value: 4 },
570
+ ],
571
+ },
572
+ {
573
+ displayName: 'Nguồn Kết Bạn: Số Điện Thoại',
574
+ name: 'add_friend_via_phone',
575
+ type: 'options',
576
+ default: 1,
577
+ options: [
578
+ { name: 'Tắt', value: 0 },
579
+ { name: 'Bật', value: 1 },
580
+ ],
581
+ },
582
+ {
583
+ displayName: 'Nguồn Kết Bạn: Mã QR',
584
+ name: 'add_friend_via_qr',
585
+ type: 'options',
586
+ default: 1,
587
+ options: [
588
+ { name: 'Tắt', value: 0 },
589
+ { name: 'Bật', value: 1 },
590
+ ],
591
+ },
592
+ {
593
+ displayName: 'Nguồn Kết Bạn: Nhóm',
594
+ name: 'add_friend_via_group',
595
+ type: 'options',
596
+ default: 1,
597
+ options: [
598
+ { name: 'Tắt', value: 0 },
599
+ { name: 'Bật', value: 1 },
600
+ ],
601
+ },
602
+ {
603
+ displayName: 'Nguồn Kết Bạn: Danh Thiếp',
604
+ name: 'add_friend_via_contact',
605
+ type: 'options',
606
+ default: 1,
607
+ options: [
608
+ { name: 'Tắt', value: 0 },
609
+ { name: 'Bật', value: 1 },
610
+ ],
611
+ },
612
+ {
613
+ displayName: 'Hiện Trong Gợi Ý Kết Bạn',
614
+ name: 'display_on_recommend_friend',
615
+ type: 'options',
616
+ default: 1,
617
+ options: [
618
+ { name: 'Tắt', value: 0 },
619
+ { name: 'Bật', value: 1 },
620
+ ],
621
+ },
622
+ {
623
+ displayName: 'Ẩn Trò Chuyện',
624
+ name: 'archivedChatStatus',
625
+ type: 'options',
626
+ default: 1,
627
+ options: [
628
+ { name: 'Tắt', value: 0 },
629
+ { name: 'Bật', value: 1 },
630
+ ],
631
+ },
632
+ {
633
+ displayName: 'Tin Nhắn Nhanh',
634
+ name: 'quickMessageStatus',
635
+ type: 'options',
636
+ default: 1,
637
+ options: [
638
+ { name: 'Tắt', value: 0 },
639
+ { name: 'Bật', value: 1 },
640
+ ],
641
+ },
642
+ ],
643
+ },
394
644
  ];