n8n-nodes-zalo-nnt 0.6.17 → 1.0.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.
Files changed (138) hide show
  1. package/LICENSE.md +19 -19
  2. package/README.md +299 -160
  3. package/dist/credentials/N8nZaloApi.credentials.js +1 -31
  4. package/dist/credentials/ZaloApi.credentials.js +1 -64
  5. package/dist/credentials/ZaloApi.credentials.js.map +1 -1
  6. package/dist/credentials/ZaloApi.credentials.ts +1 -1
  7. package/dist/credentials/shared/zalo.svg +10 -10
  8. package/dist/nodes/ZaloChatHistory/ZaloChatHistory.node.d.ts +5 -0
  9. package/dist/nodes/ZaloChatHistory/ZaloChatHistory.node.js +1 -0
  10. package/dist/nodes/ZaloChatHistory/ZaloChatHistory.node.js.map +1 -0
  11. package/dist/nodes/ZaloChatHistory/ZaloChatHistory.properties.d.ts +2 -0
  12. package/dist/nodes/ZaloChatHistory/ZaloChatHistory.properties.js +1 -0
  13. package/dist/nodes/ZaloChatHistory/ZaloChatHistory.properties.js.map +1 -0
  14. package/dist/nodes/ZaloChatHistory/utils/historyProcessor.d.ts +3 -0
  15. package/dist/nodes/ZaloChatHistory/utils/historyProcessor.js +1 -0
  16. package/dist/nodes/ZaloChatHistory/utils/historyProcessor.js.map +1 -0
  17. package/dist/nodes/ZaloChatHistory/utils/index.d.ts +4 -0
  18. package/dist/nodes/ZaloChatHistory/utils/index.js +1 -0
  19. package/dist/nodes/ZaloChatHistory/utils/index.js.map +1 -0
  20. package/dist/nodes/ZaloChatHistory/utils/messageParser.d.ts +6 -0
  21. package/dist/nodes/ZaloChatHistory/utils/messageParser.js +1 -0
  22. package/dist/nodes/ZaloChatHistory/utils/messageParser.js.map +1 -0
  23. package/dist/nodes/ZaloChatHistory/utils/types.d.ts +45 -0
  24. package/dist/nodes/ZaloChatHistory/utils/types.js +1 -0
  25. package/dist/nodes/ZaloChatHistory/utils/types.js.map +1 -0
  26. package/dist/nodes/ZaloChatHistory/utils/validator.d.ts +17 -0
  27. package/dist/nodes/ZaloChatHistory/utils/validator.js +1 -0
  28. package/dist/nodes/ZaloChatHistory/utils/validator.js.map +1 -0
  29. package/dist/nodes/ZaloGroup/ZaloGroup.node.js +1 -264
  30. package/dist/nodes/ZaloGroup/ZaloGroup.node.js.map +1 -1
  31. package/dist/nodes/ZaloGroup/ZaloGroup.properties.d.ts +2 -0
  32. package/dist/nodes/ZaloGroup/ZaloGroup.properties.js +1 -0
  33. package/dist/nodes/ZaloGroup/ZaloGroup.properties.js.map +1 -0
  34. package/dist/nodes/ZaloGroup/utils/groupProcessor.d.ts +26 -0
  35. package/dist/nodes/ZaloGroup/utils/groupProcessor.js +1 -0
  36. package/dist/nodes/ZaloGroup/utils/groupProcessor.js.map +1 -0
  37. package/dist/nodes/ZaloGroup/utils/index.d.ts +3 -0
  38. package/dist/nodes/ZaloGroup/utils/index.js +1 -0
  39. package/dist/nodes/ZaloGroup/utils/index.js.map +1 -0
  40. package/dist/nodes/ZaloGroup/utils/types.d.ts +81 -0
  41. package/dist/nodes/ZaloGroup/utils/types.js +1 -0
  42. package/dist/nodes/ZaloGroup/utils/types.js.map +1 -0
  43. package/dist/nodes/ZaloGroup/utils/validator.d.ts +15 -0
  44. package/dist/nodes/ZaloGroup/utils/validator.js +1 -0
  45. package/dist/nodes/ZaloGroup/utils/validator.js.map +1 -0
  46. package/dist/nodes/ZaloLoginByQr/ZaloLoginByQr.node.js +1 -313
  47. package/dist/nodes/ZaloLoginByQr/ZaloLoginByQr.node.js.map +1 -1
  48. package/dist/nodes/ZaloMessageTrigger/EventFilter.d.ts +12 -0
  49. package/dist/nodes/ZaloMessageTrigger/EventFilter.js +1 -0
  50. package/dist/nodes/ZaloMessageTrigger/EventFilter.js.map +1 -0
  51. package/dist/nodes/ZaloMessageTrigger/EventListenerRegistry.d.ts +16 -0
  52. package/dist/nodes/ZaloMessageTrigger/EventListenerRegistry.js +1 -0
  53. package/dist/nodes/ZaloMessageTrigger/EventListenerRegistry.js.map +1 -0
  54. package/dist/nodes/ZaloMessageTrigger/ZaloConnectionManager.d.ts +8 -0
  55. package/dist/nodes/ZaloMessageTrigger/ZaloConnectionManager.js +1 -0
  56. package/dist/nodes/ZaloMessageTrigger/ZaloConnectionManager.js.map +1 -0
  57. package/dist/nodes/ZaloMessageTrigger/ZaloMessageTrigger.node.js +1 -147
  58. package/dist/nodes/ZaloMessageTrigger/ZaloMessageTrigger.node.js.map +1 -1
  59. package/dist/nodes/ZaloMessageTrigger/constants.d.ts +16 -0
  60. package/dist/nodes/ZaloMessageTrigger/constants.js +1 -0
  61. package/dist/nodes/ZaloMessageTrigger/constants.js.map +1 -0
  62. package/dist/nodes/ZaloMessageTrigger/types.d.ts +34 -0
  63. package/dist/nodes/ZaloMessageTrigger/types.js +1 -0
  64. package/dist/nodes/ZaloMessageTrigger/types.js.map +1 -0
  65. package/dist/nodes/ZaloMessageTrigger/utils.d.ts +4 -0
  66. package/dist/nodes/ZaloMessageTrigger/utils.js +1 -0
  67. package/dist/nodes/ZaloMessageTrigger/utils.js.map +1 -0
  68. package/dist/nodes/ZaloPoll/ZaloPoll.node.js +1 -187
  69. package/dist/nodes/ZaloPoll/ZaloPoll.node.js.map +1 -1
  70. package/dist/nodes/ZaloPoll/ZaloPollDescription.js +1 -260
  71. package/dist/nodes/ZaloReminder/ZaloReminder.node.d.ts +5 -0
  72. package/dist/nodes/ZaloReminder/ZaloReminder.node.js +1 -0
  73. package/dist/nodes/ZaloReminder/ZaloReminder.node.js.map +1 -0
  74. package/dist/nodes/ZaloReminder/ZaloReminder.properties.d.ts +2 -0
  75. package/dist/nodes/ZaloReminder/ZaloReminder.properties.js +1 -0
  76. package/dist/nodes/ZaloReminder/ZaloReminder.properties.js.map +1 -0
  77. package/dist/nodes/ZaloReminder/utils/index.d.ts +3 -0
  78. package/dist/nodes/ZaloReminder/utils/index.js +1 -0
  79. package/dist/nodes/ZaloReminder/utils/index.js.map +1 -0
  80. package/dist/nodes/ZaloReminder/utils/reminderProcessor.d.ts +8 -0
  81. package/dist/nodes/ZaloReminder/utils/reminderProcessor.js +1 -0
  82. package/dist/nodes/ZaloReminder/utils/reminderProcessor.js.map +1 -0
  83. package/dist/nodes/ZaloReminder/utils/types.d.ts +53 -0
  84. package/dist/nodes/ZaloReminder/utils/types.js +1 -0
  85. package/dist/nodes/ZaloReminder/utils/types.js.map +1 -0
  86. package/dist/nodes/ZaloReminder/utils/validator.d.ts +12 -0
  87. package/dist/nodes/ZaloReminder/utils/validator.js +1 -0
  88. package/dist/nodes/ZaloReminder/utils/validator.js.map +1 -0
  89. package/dist/nodes/ZaloSendMessage/ZaloSendMessage.node.js +1 -426
  90. package/dist/nodes/ZaloSendMessage/ZaloSendMessage.node.js.map +1 -1
  91. package/dist/nodes/ZaloSendMessage/ZaloSendMessage.properties.d.ts +2 -0
  92. package/dist/nodes/ZaloSendMessage/ZaloSendMessage.properties.js +1 -0
  93. package/dist/nodes/ZaloSendMessage/ZaloSendMessage.properties.js.map +1 -0
  94. package/dist/nodes/ZaloSendMessage/utils/attachmentProcessor.d.ts +9 -0
  95. package/dist/nodes/ZaloSendMessage/utils/attachmentProcessor.js +1 -0
  96. package/dist/nodes/ZaloSendMessage/utils/attachmentProcessor.js.map +1 -0
  97. package/dist/nodes/ZaloSendMessage/utils/index.d.ts +5 -0
  98. package/dist/nodes/ZaloSendMessage/utils/index.js +1 -0
  99. package/dist/nodes/ZaloSendMessage/utils/index.js.map +1 -0
  100. package/dist/nodes/ZaloSendMessage/utils/markdownToZaloStyles.d.ts +11 -0
  101. package/dist/nodes/ZaloSendMessage/utils/markdownToZaloStyles.js +1 -0
  102. package/dist/nodes/ZaloSendMessage/utils/markdownToZaloStyles.js.map +1 -0
  103. package/dist/nodes/ZaloSendMessage/utils/messageBuilder.d.ts +2 -0
  104. package/dist/nodes/ZaloSendMessage/utils/messageBuilder.js +1 -0
  105. package/dist/nodes/ZaloSendMessage/utils/messageBuilder.js.map +1 -0
  106. package/dist/nodes/ZaloSendMessage/utils/types.d.ts +38 -0
  107. package/dist/nodes/ZaloSendMessage/utils/types.js +1 -0
  108. package/dist/nodes/ZaloSendMessage/utils/types.js.map +1 -0
  109. package/dist/nodes/ZaloSendMessage/utils/validator.d.ts +6 -0
  110. package/dist/nodes/ZaloSendMessage/utils/validator.js +1 -0
  111. package/dist/nodes/ZaloSendMessage/utils/validator.js.map +1 -0
  112. package/dist/nodes/ZaloTag/ZaloTag.node.js +1 -81
  113. package/dist/nodes/ZaloTag/ZaloTag.node.js.map +1 -1
  114. package/dist/nodes/ZaloUser/ZaloUser.node.js +1 -229
  115. package/dist/nodes/ZaloUser/ZaloUser.node.js.map +1 -1
  116. package/dist/nodes/ZaloUser/ZaloUserDescription.d.ts +2 -3
  117. package/dist/nodes/ZaloUser/ZaloUserDescription.js +1 -361
  118. package/dist/nodes/ZaloUser/ZaloUserDescription.js.map +1 -1
  119. package/dist/nodes/shared/branding.d.ts +6 -0
  120. package/dist/nodes/shared/branding.js +1 -0
  121. package/dist/nodes/shared/branding.js.map +1 -0
  122. package/dist/nodes/shared/image.png +0 -0
  123. package/dist/nodes/utils/helper.d.ts +5 -0
  124. package/dist/nodes/utils/helper.js +1 -111
  125. package/dist/nodes/utils/helper.js.map +1 -1
  126. package/dist/package.json +15 -5
  127. package/dist/tsconfig.tsbuildinfo +1 -1
  128. package/package.json +98 -86
  129. package/LICENSE +0 -201
  130. package/dist/ZaloSendMessage/ZaloSendMessage.node.js +0 -431
  131. package/dist/nodes/ZaloFriendTrigger/ZaloFriendTrigger.node.d.ts +0 -12
  132. package/dist/nodes/ZaloFriendTrigger/ZaloFriendTrigger.node.js +0 -129
  133. package/dist/nodes/ZaloFriendTrigger/ZaloFriendTrigger.node.js.map +0 -1
  134. package/dist/nodes/ZaloGroup/ZaloGroupDescription.d.ts +0 -3
  135. package/dist/nodes/ZaloGroup/ZaloGroupDescription.js +0 -348
  136. package/dist/nodes/ZaloGroup/ZaloGroupDescription.js.map +0 -1
  137. package/dist/nodes/shared/zalo.svg +0 -10
  138. package/dist/utils/helper.js +0 -90
@@ -1,431 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.ZaloSendMessage = void 0;
40
- var n8n_workflow_1 = require("n8n-workflow");
41
- var zca_js_1 = require("zca-js");
42
- var helper_1 = require("../utils/helper");
43
- var api;
44
- var ZaloSendMessage = /** @class */ (function () {
45
- function ZaloSendMessage() {
46
- this.description = {
47
- displayName: 'Zalo Send Message',
48
- name: 'zaloSendMessage',
49
- icon: 'file:../shared/zalo.svg',
50
- group: ['Zalo'],
51
- version: 5,
52
- description: 'Gửi tin nhắn qua API Zalo sử dụng kết nối đăng nhập bằng cookie',
53
- defaults: {
54
- name: 'Zalo Send Message',
55
- },
56
- // @ts-ignore
57
- inputs: ['main'],
58
- // @ts-ignore
59
- outputs: ['main'],
60
- credentials: [
61
- {
62
- name: 'zaloApi',
63
- required: true,
64
- },
65
- ],
66
- properties: [
67
- {
68
- displayName: 'Thread ID',
69
- name: 'threadId',
70
- type: 'string',
71
- default: '',
72
- required: true,
73
- description: 'ID của thread để gửi tin nhắn',
74
- },
75
- {
76
- displayName: 'Type',
77
- name: 'type',
78
- type: 'options',
79
- options: [
80
- {
81
- name: 'User',
82
- value: 0,
83
- },
84
- {
85
- name: 'Group',
86
- value: 1,
87
- },
88
- ],
89
- default: 0,
90
- description: 'Loại của tin nhắn (user hoặc group)',
91
- },
92
- {
93
- displayName: 'Message',
94
- name: 'message',
95
- type: 'string',
96
- default: '',
97
- required: true,
98
- description: 'Nội dung tin nhắn cần gửi',
99
- },
100
- {
101
- displayName: 'Urgency',
102
- name: 'urgency',
103
- type: 'options',
104
- options: [
105
- {
106
- name: 'Default',
107
- value: 0,
108
- },
109
- {
110
- name: 'Important',
111
- value: 1,
112
- },
113
- {
114
- name: 'Urgent',
115
- value: 2,
116
- },
117
- ],
118
- default: 0,
119
- description: 'Mức độ khẩn cấp của tin nhắn',
120
- },
121
- {
122
- displayName: 'Quote Message',
123
- name: 'quote',
124
- type: 'collection',
125
- placeholder: 'Add Quote',
126
- default: {},
127
- options: [
128
- {
129
- displayName: 'Message ID',
130
- name: 'msgId',
131
- type: 'string',
132
- default: '',
133
- description: 'ID của tin nhắn cần trích dẫn',
134
- },
135
- {
136
- displayName: 'Sender ID',
137
- name: 'senderId',
138
- type: 'string',
139
- default: '',
140
- description: 'ID của người gửi tin nhắn trích dẫn',
141
- },
142
- {
143
- displayName: 'Content',
144
- name: 'content',
145
- type: 'string',
146
- default: '',
147
- description: 'Nội dung tin nhắn trích dẫn',
148
- },
149
- ],
150
- },
151
- {
152
- displayName: 'Mentions',
153
- name: 'mentions',
154
- type: 'collection',
155
- placeholder: 'Add Mention',
156
- default: {},
157
- options: [
158
- {
159
- displayName: 'User ID',
160
- name: 'uid',
161
- type: 'string',
162
- default: '',
163
- description: 'ID của người dùng được mention',
164
- },
165
- {
166
- displayName: 'Position',
167
- name: 'pos',
168
- type: 'number',
169
- default: 0,
170
- description: 'Vị trí mention trong tin nhắn',
171
- },
172
- {
173
- displayName: 'Length',
174
- name: 'len',
175
- type: 'number',
176
- default: 0,
177
- description: 'Độ dài của mention',
178
- },
179
- ],
180
- },
181
- {
182
- displayName: 'Attachments',
183
- name: 'attachments',
184
- type: 'fixedCollection',
185
- typeOptions: {
186
- multipleValues: true,
187
- },
188
- placeholder: 'Add Attachment',
189
- default: {},
190
- options: [
191
- {
192
- name: 'attachment',
193
- displayName: 'Attachment',
194
- values: [
195
- {
196
- displayName: 'Type',
197
- name: 'type',
198
- type: 'options',
199
- options: [
200
- {
201
- name: 'Image URL/File URL',
202
- value: 'url',
203
- },
204
- {
205
- name: 'Array of URLs',
206
- value: 'urlArray',
207
- }
208
- ],
209
- default: 'url',
210
- description: 'Loại file đính kèm',
211
- },
212
- {
213
- displayName: 'Image URL/File URL',
214
- name: 'imageUrl',
215
- type: 'string',
216
- default: '',
217
- displayOptions: {
218
- show: {
219
- 'type': ['url'],
220
- },
221
- },
222
- description: 'URL công khai của ảnh hoặc file',
223
- },
224
- {
225
- displayName: 'Image URLs Array',
226
- name: 'imageUrls',
227
- type: 'string',
228
- default: '',
229
- displayOptions: {
230
- show: {
231
- 'type': ['urlArray'],
232
- },
233
- },
234
- description: 'Array of URLs (JSON format) hoặc comma-separated URLs. VD: ["url1","url2"] hoặc url1,url2',
235
- }
236
- ],
237
- },
238
- ],
239
- description: 'Một hoặc nhiều ảnh đính kèm để gửi',
240
- },
241
- ],
242
- };
243
- }
244
- ZaloSendMessage.prototype.execute = function () {
245
- return __awaiter(this, void 0, void 0, function () {
246
- var returnData, items, zaloCred, cookieFromCred, imeiFromCred, userAgentFromCred, zalo, error_1, i, threadId, typeNumber, type, message, urgency, quote, mentions, attachments, messageContent, _i, _a, attachment, fileData, urls, _b, urls_1, url, fileData, recipentObj, result, e_1, response, _c, _d, attachment, error_2;
247
- return __generator(this, function (_e) {
248
- switch (_e.label) {
249
- case 0:
250
- returnData = [];
251
- items = this.getInputData();
252
- return [4 /*yield*/, this.getCredentials('zaloApi')];
253
- case 1:
254
- zaloCred = _e.sent();
255
- cookieFromCred = JSON.parse(zaloCred.cookie);
256
- imeiFromCred = zaloCred.imei;
257
- userAgentFromCred = zaloCred.userAgent;
258
- _e.label = 2;
259
- case 2:
260
- _e.trys.push([2, 4, , 5]);
261
- zalo = new zca_js_1.Zalo();
262
- return [4 /*yield*/, zalo.login({
263
- cookie: cookieFromCred,
264
- imei: imeiFromCred,
265
- userAgent: userAgentFromCred
266
- })];
267
- case 3:
268
- api = _e.sent();
269
- if (!api) {
270
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Failed to initialize Zalo API. Check your credentials.');
271
- }
272
- return [3 /*break*/, 5];
273
- case 4:
274
- error_1 = _e.sent();
275
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Zalo login error: ".concat(error_1.message));
276
- case 5:
277
- i = 0;
278
- _e.label = 6;
279
- case 6:
280
- if (!(i < items.length)) return [3 /*break*/, 23];
281
- _e.label = 7;
282
- case 7:
283
- _e.trys.push([7, 21, , 22]);
284
- threadId = this.getNodeParameter('threadId', i);
285
- typeNumber = this.getNodeParameter('type', i);
286
- type = typeNumber === 0 ? zca_js_1.ThreadType.User : zca_js_1.ThreadType.Group;
287
- message = this.getNodeParameter('message', i);
288
- urgency = this.getNodeParameter('urgency', i, 0);
289
- quote = this.getNodeParameter('quote', i, {});
290
- mentions = this.getNodeParameter('mentions', i, {});
291
- attachments = this.getNodeParameter('attachments', i, {});
292
- messageContent = {
293
- msg: message,
294
- };
295
- // Add urgency if specified
296
- if (urgency !== 0) {
297
- messageContent.urgency = urgency;
298
- }
299
- // Add quote if specified
300
- if (quote && Object.keys(quote).length > 0) {
301
- messageContent.quote = {
302
- msgId: quote.msgId,
303
- senderId: quote.senderId,
304
- content: quote.content,
305
- };
306
- }
307
- // Add mentions if specified
308
- if (mentions && Object.keys(mentions).length > 0) {
309
- messageContent.mentions = [{
310
- pos: mentions.pos || 0,
311
- uid: mentions.uid,
312
- len: mentions.len || 0,
313
- }];
314
- }
315
- if (!(attachments && attachments.attachment && attachments.attachment.length > 0)) return [3 /*break*/, 15];
316
- messageContent.attachments = [];
317
- _i = 0, _a = attachments.attachment;
318
- _e.label = 8;
319
- case 8:
320
- if (!(_i < _a.length)) return [3 /*break*/, 15];
321
- attachment = _a[_i];
322
- if (!(attachment.type === 'url')) return [3 /*break*/, 10];
323
- return [4 /*yield*/, (0, helper_1.saveFile)(attachment.imageUrl)];
324
- case 9:
325
- fileData = _e.sent();
326
- messageContent.attachments.push(fileData);
327
- return [3 /*break*/, 14];
328
- case 10:
329
- if (!(attachment.type === 'urlArray')) return [3 /*break*/, 14];
330
- urls = [];
331
- // Parse URLs from string input
332
- if (typeof attachment.imageUrls === 'string') {
333
- try {
334
- // Try to parse as JSON array first
335
- urls = JSON.parse(attachment.imageUrls);
336
- }
337
- catch (_f) {
338
- // If not JSON, try comma-separated
339
- urls = attachment.imageUrls.split(',').map(function (url) { return url.trim(); }).filter(function (url) { return url; });
340
- }
341
- }
342
- _b = 0, urls_1 = urls;
343
- _e.label = 11;
344
- case 11:
345
- if (!(_b < urls_1.length)) return [3 /*break*/, 14];
346
- url = urls_1[_b];
347
- if (!url) return [3 /*break*/, 13];
348
- return [4 /*yield*/, (0, helper_1.saveFile)(url)];
349
- case 12:
350
- fileData = _e.sent();
351
- messageContent.attachments.push(fileData);
352
- _e.label = 13;
353
- case 13:
354
- _b++;
355
- return [3 /*break*/, 11];
356
- case 14:
357
- _i++;
358
- return [3 /*break*/, 8];
359
- case 15:
360
- // Log the parameters before sending
361
- this.logger.info("Sending message with parameters: ".concat(JSON.stringify(messageContent)));
362
- // Send the message
363
- if (!api) {
364
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zalo API not initialized');
365
- }
366
- _e.label = 16;
367
- case 16:
368
- _e.trys.push([16, 18, , 19]);
369
- recipentObj = {
370
- id: threadId,
371
- type: type
372
- };
373
- return [4 /*yield*/, api.sendTypingEvent(recipentObj.id, recipentObj.type)];
374
- case 17:
375
- result = _e.sent();
376
- if (!!result) {
377
- this.logger.info("Send! typing event");
378
- }
379
- return [3 /*break*/, 19];
380
- case 18:
381
- e_1 = _e.sent();
382
- this.logger.error("Cannot send typing event");
383
- return [3 /*break*/, 19];
384
- case 19: return [4 /*yield*/, api.sendMessage(messageContent, threadId, type)];
385
- case 20:
386
- response = _e.sent();
387
- //Remove temp img
388
- if (messageContent.attachments && messageContent.attachments.length > 0) {
389
- for (_c = 0, _d = messageContent.attachments; _c < _d.length; _c++) {
390
- attachment = _d[_c];
391
- this.logger.info("Remove attachment: ".concat(attachment));
392
- (0, helper_1.removeFile)(attachment);
393
- }
394
- }
395
- this.logger.info('Message sent successfully', { threadId: threadId, type: type });
396
- returnData.push({
397
- json: {
398
- success: true,
399
- response: response,
400
- threadId: threadId,
401
- threadType: type,
402
- messageContent: messageContent,
403
- },
404
- });
405
- return [3 /*break*/, 22];
406
- case 21:
407
- error_2 = _e.sent();
408
- this.logger.error('Error sending Zalo message:', error_2);
409
- if (this.continueOnFail()) {
410
- returnData.push({
411
- json: {
412
- success: false,
413
- error: error_2.message,
414
- },
415
- });
416
- }
417
- else {
418
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), error_2, { itemIndex: i });
419
- }
420
- return [3 /*break*/, 22];
421
- case 22:
422
- i++;
423
- return [3 /*break*/, 6];
424
- case 23: return [2 /*return*/, [returnData]];
425
- }
426
- });
427
- });
428
- };
429
- return ZaloSendMessage;
430
- }());
431
- exports.ZaloSendMessage = ZaloSendMessage;
@@ -1,12 +0,0 @@
1
- import { INodeType, INodeTypeDescription, IWebhookFunctions, IWebhookResponseData, IHookFunctions } from 'n8n-workflow';
2
- export declare class ZaloFriendTrigger implements INodeType {
3
- description: INodeTypeDescription;
4
- webhookMethods: {
5
- default: {
6
- checkExists(this: IHookFunctions): Promise<boolean>;
7
- create(this: IHookFunctions): Promise<boolean>;
8
- delete(this: IHookFunctions): Promise<boolean>;
9
- };
10
- };
11
- webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
12
- }
@@ -1,129 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZaloFriendTrigger = void 0;
4
- const n8n_workflow_1 = require("n8n-workflow");
5
- const zca_js_1 = require("zca-js");
6
- let api;
7
- let reconnectTimer;
8
- class ZaloFriendTrigger {
9
- constructor() {
10
- this.description = {
11
- displayName: 'Zalo Friend Trigger',
12
- name: 'zaloFriendTrigger',
13
- icon: 'file:../shared/zalo.svg',
14
- group: ['trigger'],
15
- version: 1,
16
- description: 'Lắng nghe sự kiện kết bạn trên Zalo',
17
- defaults: {
18
- name: 'Zalo Friend Trigger',
19
- },
20
- inputs: [],
21
- outputs: ['main'],
22
- webhooks: [
23
- {
24
- name: 'default',
25
- httpMethod: 'POST',
26
- responseMode: 'onReceived',
27
- path: 'webhook',
28
- },
29
- ],
30
- credentials: [
31
- {
32
- name: 'zaloApi',
33
- required: true,
34
- displayName: 'Zalo Credential to connect with',
35
- },
36
- ],
37
- properties: [
38
- {
39
- displayName: 'Event Types',
40
- name: 'eventTypes',
41
- type: 'multiOptions',
42
- options: [
43
- {
44
- name: 'Friend Requests',
45
- value: zca_js_1.FriendEventType.REQUEST,
46
- description: 'Nghe sự kiện yêu cầu kết bạn',
47
- }
48
- ],
49
- default: [zca_js_1.FriendEventType.REQUEST],
50
- required: true,
51
- description: 'Friend events to listen for',
52
- },
53
- ],
54
- };
55
- this.webhookMethods = {
56
- default: {
57
- async checkExists() {
58
- const webhookData = this.getWorkflowStaticData('node');
59
- return !!webhookData.isConnected;
60
- },
61
- async create() {
62
- const credentials = await this.getCredentials('zaloApi');
63
- if (!credentials) {
64
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No credentials found');
65
- }
66
- try {
67
- const cookieFromCred = JSON.parse(credentials.cookie);
68
- const imeiFromCred = credentials.imei;
69
- const userAgentFromCred = credentials.userAgent;
70
- const zalo = new zca_js_1.Zalo();
71
- api = await zalo.login({ cookie: cookieFromCred, imei: imeiFromCred, userAgent: userAgentFromCred });
72
- if (!api) {
73
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No API instance found. Please make sure to provide valid credentials.');
74
- }
75
- const webhookUrl = this.getNodeWebhookUrl('default');
76
- console.log(webhookUrl);
77
- api.listener.on('friend_event', async (event) => {
78
- const nodeEventTypes = this.getNodeParameter('eventTypes', 0);
79
- if (nodeEventTypes.includes(event.type)) {
80
- this.helpers.httpRequest({
81
- method: 'POST',
82
- url: webhookUrl,
83
- body: {
84
- friendEvent: event.data,
85
- },
86
- headers: {
87
- 'Content-Type': 'application/json',
88
- },
89
- });
90
- }
91
- });
92
- api.listener.start();
93
- const webhookData = this.getWorkflowStaticData('node');
94
- webhookData.isConnected = true;
95
- webhookData.eventTypes = this.getNodeParameter('eventTypes', 0);
96
- return true;
97
- }
98
- catch (error) {
99
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zalo connection failed');
100
- }
101
- },
102
- async delete() {
103
- const webhookData = this.getWorkflowStaticData('node');
104
- if (api) {
105
- api.listener.stop();
106
- api = undefined;
107
- }
108
- if (reconnectTimer) {
109
- clearTimeout(reconnectTimer);
110
- reconnectTimer = undefined;
111
- }
112
- delete webhookData.isConnected;
113
- delete webhookData.eventTypes;
114
- return true;
115
- },
116
- },
117
- };
118
- }
119
- async webhook() {
120
- const req = this.getRequestObject();
121
- const body = req.body;
122
- console.log(body);
123
- return {
124
- workflowData: [this.helpers.returnJsonArray(req.body)],
125
- };
126
- }
127
- }
128
- exports.ZaloFriendTrigger = ZaloFriendTrigger;
129
- //# sourceMappingURL=ZaloFriendTrigger.node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ZaloFriendTrigger.node.js","sourceRoot":"","sources":["../../../nodes/ZaloFriendTrigger/ZaloFriendTrigger.node.ts"],"names":[],"mappings":";;;AAAA,+CAOsB;AACtB,mCAAiE;AAEjE,IAAI,GAAoB,CAAC;AACzB,IAAI,cAA0C,CAAC;AAE/C,MAAa,iBAAiB;IAA9B;QACC,gBAAW,GAAyB;YACnC,WAAW,EAAE,qBAAqB;YAClC,IAAI,EAAE,mBAAmB;YACzB,IAAI,EAAE,yBAAyB;YAC/B,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,OAAO,EAAE,CAAC;YACV,WAAW,EAAE,qCAAqC;YAClD,QAAQ,EAAE;gBACT,IAAI,EAAE,qBAAqB;aAC3B;YAED,MAAM,EAAE,EAAE;YAEV,OAAO,EAAE,CAAC,MAAM,CAAC;YACjB,QAAQ,EAAE;gBACT;oBACC,IAAI,EAAE,SAAS;oBACf,UAAU,EAAE,MAAM;oBAClB,YAAY,EAAE,YAAY;oBAC1B,IAAI,EAAE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CAAC,CAAC;oBACxE,CAAC;gBACF,CAAC;gBAED,KAAK,CAAC,MAAM;oBACX,MAAM,WAAW,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;oBAEvD,IAAI,GAAG,EAAE,CAAC;wBACT,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;wBACpB,GAAG,GAAG,SAAS,CAAC;oBACjB,CAAC;oBAED,IAAI,cAAc,EAAE,CAAC;wBACpB,YAAY,CAAC,cAAc,CAAC,CAAC;wBAC7B,cAAc,GAAG,SAAS,CAAC;oBAC5B,CAAC;oBAED,OAAO,WAAW,CAAC,WAAW,CAAC;oBAC/B,OAAO,WAAW,CAAC,UAAU,CAAC;oBAC9B,OAAO,IAAI,CAAC;gBACb,CAAC;aACD;SACD,CAAC;IAWH,CAAC;IATA,KAAK,CAAC,OAAO;QACZ,MAAM,GAAG,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAElB,OAAO;YACN,YAAY,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SACtD,CAAC;IACH,CAAC;CACD;AA5ID,8CA4IC"}
@@ -1,3 +0,0 @@
1
- import { INodeProperties } from 'n8n-workflow';
2
- export declare const zaloGroupOperations: INodeProperties[];
3
- export declare const zaloGroupFields: INodeProperties[];