n8n-nodes-zalo-stable 0.6.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 (53) hide show
  1. package/LICENSE.md +19 -0
  2. package/README.md +93 -0
  3. package/dist/credentials/N8nZaloApi.credentials.d.ts +8 -0
  4. package/dist/credentials/N8nZaloApi.credentials.js +31 -0
  5. package/dist/credentials/N8nZaloApi.credentials.js.map +1 -0
  6. package/dist/credentials/N8nZaloApi.credentials.ts +32 -0
  7. package/dist/credentials/ZaloApi.credentials.d.ts +8 -0
  8. package/dist/credentials/ZaloApi.credentials.js +64 -0
  9. package/dist/credentials/ZaloApi.credentials.js.map +1 -0
  10. package/dist/credentials/ZaloApi.credentials.ts +66 -0
  11. package/dist/credentials/shared/n8n.png +0 -0
  12. package/dist/credentials/shared/zalo.svg +10 -0
  13. package/dist/nodes/ZaloFriendTrigger/ZaloFriendTrigger.node.d.ts +12 -0
  14. package/dist/nodes/ZaloFriendTrigger/ZaloFriendTrigger.node.js +129 -0
  15. package/dist/nodes/ZaloFriendTrigger/ZaloFriendTrigger.node.js.map +1 -0
  16. package/dist/nodes/ZaloGroup/ZaloGroup.node.d.ts +5 -0
  17. package/dist/nodes/ZaloGroup/ZaloGroup.node.js +228 -0
  18. package/dist/nodes/ZaloGroup/ZaloGroup.node.js.map +1 -0
  19. package/dist/nodes/ZaloGroup/ZaloGroupDescription.d.ts +3 -0
  20. package/dist/nodes/ZaloGroup/ZaloGroupDescription.js +348 -0
  21. package/dist/nodes/ZaloGroup/ZaloGroupDescription.js.map +1 -0
  22. package/dist/nodes/ZaloLoginByQr/ZaloLoginByQr.node.d.ts +5 -0
  23. package/dist/nodes/ZaloLoginByQr/ZaloLoginByQr.node.js +422 -0
  24. package/dist/nodes/ZaloLoginByQr/ZaloLoginByQr.node.js.map +1 -0
  25. package/dist/nodes/ZaloMessageTrigger/ZaloMessageTrigger.node.d.ts +12 -0
  26. package/dist/nodes/ZaloMessageTrigger/ZaloMessageTrigger.node.js +147 -0
  27. package/dist/nodes/ZaloMessageTrigger/ZaloMessageTrigger.node.js.map +1 -0
  28. package/dist/nodes/ZaloPoll/ZaloPoll.node.d.ts +5 -0
  29. package/dist/nodes/ZaloPoll/ZaloPoll.node.js +187 -0
  30. package/dist/nodes/ZaloPoll/ZaloPoll.node.js.map +1 -0
  31. package/dist/nodes/ZaloPoll/ZaloPollDescription.d.ts +3 -0
  32. package/dist/nodes/ZaloPoll/ZaloPollDescription.js +260 -0
  33. package/dist/nodes/ZaloPoll/ZaloPollDescription.js.map +1 -0
  34. package/dist/nodes/ZaloSendMessage/ZaloSendMessage.node.d.ts +5 -0
  35. package/dist/nodes/ZaloSendMessage/ZaloSendMessage.node.js +305 -0
  36. package/dist/nodes/ZaloSendMessage/ZaloSendMessage.node.js.map +1 -0
  37. package/dist/nodes/ZaloTag/ZaloTag.node.d.ts +5 -0
  38. package/dist/nodes/ZaloTag/ZaloTag.node.js +81 -0
  39. package/dist/nodes/ZaloTag/ZaloTag.node.js.map +1 -0
  40. package/dist/nodes/ZaloUser/ZaloUser.node.d.ts +5 -0
  41. package/dist/nodes/ZaloUser/ZaloUser.node.js +235 -0
  42. package/dist/nodes/ZaloUser/ZaloUser.node.js.map +1 -0
  43. package/dist/nodes/ZaloUser/ZaloUserDescription.d.ts +3 -0
  44. package/dist/nodes/ZaloUser/ZaloUserDescription.js +361 -0
  45. package/dist/nodes/ZaloUser/ZaloUserDescription.js.map +1 -0
  46. package/dist/nodes/shared/zalo.svg +10 -0
  47. package/dist/nodes/utils/helper.d.ts +2 -0
  48. package/dist/nodes/utils/helper.js +42 -0
  49. package/dist/nodes/utils/helper.js.map +1 -0
  50. package/dist/package.json +81 -0
  51. package/dist/tsconfig.tsbuildinfo +1 -0
  52. package/index.js +0 -0
  53. package/package.json +81 -0
@@ -0,0 +1,422 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ZaloLoginByQr = void 0;
40
+ const n8n_workflow_1 = require("n8n-workflow");
41
+ const zca_js_1 = require("zca-js");
42
+ const path = __importStar(require("path"));
43
+ const axios_1 = __importDefault(require("axios"));
44
+ class ZaloLoginByQr {
45
+ constructor() {
46
+ this.description = {
47
+ displayName: 'Zalo Login Via QR Code',
48
+ name: 'zaloLoginByQr',
49
+ group: ['Zalo'],
50
+ version: 1,
51
+ description: 'LĐăng nhập Zalo bằng QR code và lưu thông tin vào Credentia',
52
+ defaults: {
53
+ name: 'Zalo Login Via QR Code',
54
+ },
55
+ inputs: ['main'],
56
+ outputs: ['main'],
57
+ icon: 'file:../shared/zalo.svg',
58
+ credentials: [
59
+ {
60
+ name: 'zaloApi',
61
+ required: false,
62
+ displayName: 'Zalo Credential to connect with',
63
+ },
64
+ {
65
+ name: 'n8nZaloApi',
66
+ required: true,
67
+ displayName: 'n8n Account Credential',
68
+ },
69
+ ],
70
+ properties: [
71
+ {
72
+ displayName: 'Proxy',
73
+ name: 'proxy',
74
+ type: 'string',
75
+ default: '',
76
+ placeholder: 'https://user:pass@host:port',
77
+ description: 'HTTP proxy to use for Zalo API requests',
78
+ },
79
+ ],
80
+ };
81
+ }
82
+ async execute() {
83
+ const returnData = [];
84
+ const proxy = this.getNodeParameter('proxy', 0, '');
85
+ const timeout = 30;
86
+ const fileName = 'zalo-qr-code.png';
87
+ let zaloCredential;
88
+ let n8nCredential;
89
+ try {
90
+ zaloCredential = await this.getCredentials('zaloApi');
91
+ }
92
+ catch (error) {
93
+ }
94
+ try {
95
+ n8nCredential = await this.getCredentials('n8nZaloApi');
96
+ }
97
+ catch (error) {
98
+ }
99
+ let selectedCredential = undefined;
100
+ if (n8nCredential) {
101
+ console.error('Using n8n account credential');
102
+ selectedCredential = n8nCredential;
103
+ }
104
+ else if (zaloCredential) {
105
+ console.error('Using Zalo API credential');
106
+ selectedCredential = zaloCredential;
107
+ }
108
+ else {
109
+ console.error('No credentials provided, will generate QR code for login');
110
+ }
111
+ try {
112
+ const zaloOptions = {
113
+ selfListen: true,
114
+ logging: true,
115
+ };
116
+ if (proxy) {
117
+ zaloOptions.proxy = proxy;
118
+ }
119
+ let zalo;
120
+ if (selectedCredential) {
121
+ console.error('Using existing Zalo credentials');
122
+ zalo = new zca_js_1.Zalo(zaloOptions);
123
+ if (selectedCredential === n8nCredential) {
124
+ console.error('Using n8n credential to get Zalo credentials');
125
+ const n8nApiKey = selectedCredential.apiKey;
126
+ const n8nUrl = selectedCredential.url || 'http://localhost:5678';
127
+ console.error(`Using n8n API at ${n8nUrl} with API key ${n8nApiKey ? 'provided' : 'not provided'}`);
128
+ console.error('n8n credential support is not fully implemented yet. Will use QR code login.');
129
+ zalo = new zca_js_1.Zalo(zaloOptions);
130
+ }
131
+ else {
132
+ console.error('Using Zalo credential for login');
133
+ const cookie = selectedCredential.cookie;
134
+ const imei = selectedCredential.imei;
135
+ const userAgent = selectedCredential.userAgent;
136
+ const supportCode = selectedCredential.supportCode;
137
+ const licenseKey = selectedCredential.licenseKey;
138
+ if (selectedCredential.proxy) {
139
+ console.error('Using proxy from credential:', selectedCredential.proxy);
140
+ zaloOptions.proxy = selectedCredential.proxy;
141
+ }
142
+ await zalo.login({
143
+ cookie,
144
+ imei,
145
+ userAgent,
146
+ supportCode,
147
+ licenseKey,
148
+ });
149
+ }
150
+ }
151
+ else {
152
+ zalo = new zca_js_1.Zalo(zaloOptions);
153
+ }
154
+ console.error('Starting Zalo QR login process...');
155
+ const processContext = (context) => {
156
+ if (!context) {
157
+ console.error('Context is null or undefined');
158
+ return;
159
+ }
160
+ const cookie = context.cookie || '';
161
+ const imei = context.imei || '';
162
+ const userAgent = context.userAgent || '';
163
+ console.error('=== ZALO CREDENTIALS ===');
164
+ console.error('Cookie:', cookie ? `Received (length: ${typeof cookie === 'string' ? cookie.length : (Array.isArray(cookie) ? cookie.length : 'unknown')})` : 'None');
165
+ console.error('IMEI:', imei ? imei : 'None');
166
+ console.error('User Agent:', userAgent ? userAgent : 'None');
167
+ console.error('=== END CREDENTIALS ===');
168
+ };
169
+ const setupEventListeners = (api) => {
170
+ console.error('Setting up event listeners to get credentials');
171
+ try {
172
+ if (typeof api.getContext === 'function') {
173
+ const contextResult = api.getContext();
174
+ if (contextResult && typeof contextResult.then === 'function') {
175
+ contextResult.then((context) => {
176
+ processContext(context);
177
+ }).catch((error) => {
178
+ console.error('Error getting context:', error);
179
+ });
180
+ }
181
+ else {
182
+ processContext(contextResult);
183
+ }
184
+ }
185
+ else {
186
+ console.error('getContext is not a function');
187
+ if (api.context) {
188
+ console.error('Found context in api object');
189
+ processContext(api.context);
190
+ }
191
+ else {
192
+ console.error('No context found in api object');
193
+ }
194
+ }
195
+ }
196
+ catch (error) {
197
+ console.error('Error in setupEventListeners:', error);
198
+ }
199
+ };
200
+ const qrCodePromise = new Promise(async (resolve, reject) => {
201
+ let isResolved = false;
202
+ const timeoutId = setTimeout(() => {
203
+ if (!isResolved) {
204
+ isResolved = true;
205
+ reject(new n8n_workflow_1.NodeOperationError(this.getNode(), 'Timeout generating QR code. Please try again or check your Zalo connection.'));
206
+ }
207
+ }, timeout * 1000);
208
+ try {
209
+ let api = await zalo.loginQR(null, (qrEvent) => {
210
+ var _a, _b;
211
+ console.error('Received QR event type:', qrEvent ? qrEvent.type : 'no event');
212
+ switch (qrEvent.type) {
213
+ case 0:
214
+ if ((_a = qrEvent === null || qrEvent === void 0 ? void 0 : qrEvent.data) === null || _a === void 0 ? void 0 : _a.image) {
215
+ const qrCodeBase64 = qrEvent.data.image;
216
+ console.error('QR code generated, length:', qrCodeBase64.length);
217
+ if (isResolved)
218
+ return;
219
+ clearTimeout(timeoutId);
220
+ if (qrCodeBase64) {
221
+ isResolved = true;
222
+ resolve(qrCodeBase64);
223
+ }
224
+ }
225
+ else {
226
+ console.error('Could not get QR code from Zalo SDK');
227
+ reject(new Error("Could not get QR code"));
228
+ }
229
+ break;
230
+ case 1:
231
+ console.error('QR code expired. Please try again.');
232
+ break;
233
+ case 2:
234
+ console.error('=== QR CODE SCANNED ===');
235
+ if (qrEvent === null || qrEvent === void 0 ? void 0 : qrEvent.data) {
236
+ console.error('User:', qrEvent.data.display_name);
237
+ console.error('Avatar:', qrEvent.data.avatar ? 'Yes' : 'No');
238
+ }
239
+ break;
240
+ case 3:
241
+ console.error('=== QR CODE DECLINED ===');
242
+ if ((_b = qrEvent === null || qrEvent === void 0 ? void 0 : qrEvent.data) === null || _b === void 0 ? void 0 : _b.code) {
243
+ console.error('Decline code:', qrEvent.data.code);
244
+ }
245
+ break;
246
+ case 4:
247
+ console.error('=== GOT LOGIN INFO ===');
248
+ if (qrEvent === null || qrEvent === void 0 ? void 0 : qrEvent.data) {
249
+ const cookie = qrEvent.data.cookie || [];
250
+ const imei = qrEvent.data.imei || '';
251
+ const userAgent = qrEvent.data.userAgent || '';
252
+ console.error('Cookie received:', cookie.length > 0 ? 'Yes' : 'No');
253
+ console.error('IMEI received:', imei ? 'Yes' : 'No');
254
+ console.error('User Agent received:', userAgent ? 'Yes' : 'No');
255
+ try {
256
+ if (cookie.length > 0 || imei || userAgent) {
257
+ const credentialName = 'Zalo API Credentials';
258
+ const credentialData = {
259
+ cookie: JSON.stringify(cookie),
260
+ imei: imei,
261
+ userAgent: userAgent,
262
+ proxy: proxy || '',
263
+ supportCode: '',
264
+ licenseKey: ''
265
+ };
266
+ try {
267
+ console.error('Attempting to create Zalo credential via n8n API');
268
+ const credentialApiData = {
269
+ name: credentialName,
270
+ type: 'zaloApi',
271
+ nodesAccess: [],
272
+ data: credentialData
273
+ };
274
+ const ports = [5678];
275
+ const createCredentialOnPort = async (port) => {
276
+ const n8nApi = await this.getCredentials('n8nZaloApi');
277
+ const n8nApiUrl = n8nApi.url;
278
+ const fullApiUrl = `${n8nApiUrl}/api/v1/credentials`;
279
+ const n8nApiKey = n8nApi.apiKey;
280
+ console.error(`Trying to create credential via n8n API at ${fullApiUrl}`);
281
+ try {
282
+ await axios_1.default.post(fullApiUrl, credentialApiData, {
283
+ headers: {
284
+ 'Content-Type': 'application/json',
285
+ 'X-N8N-API-KEY': n8nApiKey
286
+ },
287
+ });
288
+ console.error('Credential created successfully via n8n API');
289
+ console.error('Credential ID:');
290
+ return true;
291
+ }
292
+ catch (apiError) {
293
+ console.error(`Error creating credential on port ${port}:`, apiError.message);
294
+ return false;
295
+ }
296
+ };
297
+ let credentialCreated = false;
298
+ (async () => {
299
+ for (const port of ports) {
300
+ try {
301
+ const result = await createCredentialOnPort.call(this, port);
302
+ if (result) {
303
+ credentialCreated = true;
304
+ break;
305
+ }
306
+ }
307
+ catch (error) {
308
+ console.error(`Error trying port ${port}:`, error.message);
309
+ }
310
+ }
311
+ })().catch(error => {
312
+ console.error('Error in credential creation:', error.message);
313
+ });
314
+ if (!credentialCreated) {
315
+ console.error('Could not create credential via n8n API on any port.');
316
+ console.error('Credential info saved to file. You can create it manually using:');
317
+ console.error('node auto-create-zalo-credential.js');
318
+ }
319
+ }
320
+ catch (error) {
321
+ console.error(`Error creating credential: ${error.message}`);
322
+ console.error('Credential info saved to file. You can create it manually using:');
323
+ console.error('node auto-create-zalo-credential.js');
324
+ }
325
+ }
326
+ else {
327
+ console.error('=== NO CREDENTIALS TO SAVE ===');
328
+ console.error('No login information available to save');
329
+ }
330
+ }
331
+ catch (fileError) {
332
+ console.error('Error saving credentials:', fileError.message);
333
+ }
334
+ }
335
+ break;
336
+ default:
337
+ console.error('Unknown QR event type:', qrEvent.type);
338
+ }
339
+ });
340
+ console.error('Starting Zalo listener');
341
+ api.listener.start();
342
+ api.listener.onConnected(() => {
343
+ console.error("=== ZALO SDK CONNECTED ===");
344
+ setupEventListeners(api);
345
+ });
346
+ api.listener.onError((error) => {
347
+ console.error("=== ZALO ERROR ===", error);
348
+ });
349
+ api.listener.onMessage((message) => {
350
+ console.error("=== ZALO MESSAGE RECEIVED ===");
351
+ console.error("Message type:", message.type);
352
+ console.error("Message content:", JSON.stringify(message).substring(0, 200) + '...');
353
+ if (message.type === 'login_success' || message.type === 'qr_scanned') {
354
+ console.error("=== QR CODE SCANNED OR LOGIN SUCCESSFUL ===");
355
+ setupEventListeners(api);
356
+ }
357
+ });
358
+ console.error('All event listeners set up');
359
+ }
360
+ catch (error) {
361
+ clearTimeout(timeoutId);
362
+ if (!isResolved) {
363
+ isResolved = true;
364
+ reject(error);
365
+ }
366
+ }
367
+ });
368
+ const qrCodeBase64 = await qrCodePromise;
369
+ const binaryData = Buffer.from(qrCodeBase64, 'base64');
370
+ const newItem = {
371
+ json: {
372
+ success: true,
373
+ message: selectedCredential === n8nCredential
374
+ ? 'Using n8n account credential. QR code generated successfully.'
375
+ : (selectedCredential === zaloCredential
376
+ ? 'Using existing Zalo credentials. QR code generated successfully.'
377
+ : 'QR code generated successfully. Scan with Zalo app to login.'),
378
+ fileName,
379
+ usingExistingCredential: !!selectedCredential,
380
+ credentialType: selectedCredential === n8nCredential ? 'n8nZaloApi' : (selectedCredential === zaloCredential ? 'zaloApi' : null),
381
+ },
382
+ binary: {
383
+ data: await this.helpers.prepareBinaryData(binaryData, fileName, 'image/png'),
384
+ },
385
+ };
386
+ returnData.push(newItem);
387
+ if (returnData[0] && returnData[0].json) {
388
+ if (!selectedCredential) {
389
+ returnData[0].json.credentialInstructions = 'Credentials have been saved to file. Credentials will be created automatically if n8n API credentials are provided.';
390
+ returnData[0].json.credentialFilePath = path.join(process.cwd(), 'output', 'zalo-credentials.json');
391
+ returnData[0].json.autoCreateScript = 'node auto-create-zalo-credential.js';
392
+ returnData[0].json.autoCreateApi = 'Credentials will be created automatically via n8n API if n8n API credentials are provided.';
393
+ }
394
+ else if (selectedCredential === n8nCredential) {
395
+ returnData[0].json.credentialInstructions = 'Using n8n account credential. New Zalo credentials will be created automatically after successful login.';
396
+ returnData[0].json.credentialName = selectedCredential.name || 'Unknown';
397
+ returnData[0].json.credentialId = selectedCredential.id || 'Unknown';
398
+ returnData[0].json.credentialType = 'n8nZaloApi';
399
+ returnData[0].json.autoCreateApi = 'Credentials will be created automatically via n8n API after successful login.';
400
+ }
401
+ else {
402
+ returnData[0].json.credentialInstructions = 'Using existing Zalo credentials from the selected credential.';
403
+ returnData[0].json.credentialName = selectedCredential.name || 'Unknown';
404
+ returnData[0].json.credentialId = selectedCredential.id || 'Unknown';
405
+ returnData[0].json.credentialType = 'zaloApi';
406
+ }
407
+ }
408
+ return [returnData];
409
+ }
410
+ catch (error) {
411
+ if (this.continueOnFail()) {
412
+ const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: 0 } });
413
+ return [executionData];
414
+ }
415
+ else {
416
+ throw error;
417
+ }
418
+ }
419
+ }
420
+ }
421
+ exports.ZaloLoginByQr = ZaloLoginByQr;
422
+ //# sourceMappingURL=ZaloLoginByQr.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZaloLoginByQr.node.js","sourceRoot":"","sources":["../../../nodes/ZaloLoginByQr/ZaloLoginByQr.node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAMsB;AACtB,mCAA8B;AAC9B,2CAA6B;AAC7B,kDAA0B;AAE1B,MAAa,aAAa;IAA1B;QACC,gBAAW,GAAyB;YACnC,WAAW,EAAE,wBAAwB;YACrC,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE,CAAC,MAAM,CAAC;YACf,OAAO,EAAE,CAAC;YACV,WAAW,EAAE,6DAA6D;YAC1E,QAAQ,EAAE;gBACT,IAAI,EAAE,wBAAwB;aAC9B;YAED,MAAM,EAAE,CAAC,MAAM,CAAC;YAEhB,OAAO,EAAE,CAAC,MAAM,CAAC;YACjB,IAAI,EAAE,yBAAyB;YAC/B,WAAW,EAAE;gBACZ;oBACC,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE,KAAK;oBACf,WAAW,EAAE,iCAAiC;iBAC9C;gBACD;oBACC,IAAI,EAAE,YAAY;oBAClB,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,wBAAwB;iBACnC;aACH;YACD,UAAU,EAAE;gBACX;oBACC,WAAW,EAAE,OAAO;oBACpB,IAAI,EAAE,OAAO;oBACb,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,EAAE;oBACX,WAAW,EAAE,6BAA6B;oBAC1C,WAAW,EAAE,yCAAyC;iBACtD;aACD;SACD,CAAC;IAmcH,CAAC;IAjcA,KAAK,CAAC,OAAO;QACZ,MAAM,UAAU,GAAyB,EAAE,CAAC;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,EA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,CAAC,CAAC,IAAI,CAAC,YAAY,GAAG,kBAAkB,CAAC,EAAE,IAAI,SAAS,CAAC;oBACrE,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;gBAC/C,CAAC;YACF,CAAC;YAED,OAAO,CAAC,UAAU,CAAC,CAAC;QACrB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACrB,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;gBAC3B,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,0BAA0B,CAC5D,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,EACtD,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CACzB,CAAC;gBACF,OAAO,CAAC,aAAa,CAAC,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACP,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;CACD;AAxeD,sCAweC"}
@@ -0,0 +1,12 @@
1
+ import { INodeType, INodeTypeDescription, IWebhookFunctions, IWebhookResponseData, IHookFunctions } from 'n8n-workflow';
2
+ export declare class ZaloMessageTrigger 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
+ }
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZaloMessageTrigger = 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 ZaloMessageTrigger {
9
+ constructor() {
10
+ this.description = {
11
+ displayName: 'Zalo Message Trigger',
12
+ name: 'zaloMessageTrigger',
13
+ icon: 'file:../shared/zalo.svg',
14
+ group: ['trigger'],
15
+ version: 1,
16
+ description: 'Sự kiện lắng nghe tin nhắn trên Zalo',
17
+ defaults: {
18
+ name: 'Zalo Message 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: 'User Messages',
45
+ value: zca_js_1.ThreadType.User,
46
+ description: 'Lắng nghe tin nhắn từ người dùng',
47
+ },
48
+ {
49
+ name: 'Group Messages',
50
+ value: zca_js_1.ThreadType.Group,
51
+ description: 'Lắng nghe tin nhắn từ nhóm',
52
+ },
53
+ ],
54
+ default: [zca_js_1.ThreadType.User, zca_js_1.ThreadType.Group],
55
+ required: true,
56
+ description: 'Types of messages to listen for',
57
+ },
58
+ {
59
+ displayName: 'Self Listen',
60
+ name: 'selfListen',
61
+ type: 'boolean',
62
+ default: false,
63
+ required: true,
64
+ description: 'Cho phép lắng nghe tin nhắn của chính mình tự gửi',
65
+ },
66
+ ],
67
+ };
68
+ this.webhookMethods = {
69
+ default: {
70
+ async checkExists() {
71
+ const webhookData = this.getWorkflowStaticData('node');
72
+ return !!webhookData.isConnected;
73
+ },
74
+ async create() {
75
+ const credentials = await this.getCredentials('zaloApi');
76
+ if (!credentials) {
77
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No credentials found');
78
+ }
79
+ try {
80
+ const cookieFromCred = JSON.parse(credentials.cookie);
81
+ const imeiFromCred = credentials.imei;
82
+ const userAgentFromCred = credentials.userAgent;
83
+ const selfListen = this.getNodeParameter('selfListen', 0);
84
+ const zalo = new zca_js_1.Zalo({ selfListen });
85
+ api = await zalo.login({ cookie: cookieFromCred, imei: imeiFromCred, userAgent: userAgentFromCred });
86
+ if (!api) {
87
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No API instance found. Please make sure to provide valid credentials.');
88
+ }
89
+ const webhookUrl = this.getNodeWebhookUrl('default');
90
+ console.log(webhookUrl);
91
+ api.listener.on('message', async (message) => {
92
+ const webhookData = this.getWorkflowStaticData('node');
93
+ this.helpers.httpRequest({
94
+ method: 'POST',
95
+ url: webhookUrl,
96
+ body: {
97
+ message: message,
98
+ },
99
+ headers: {
100
+ 'Content-Type': 'application/json',
101
+ },
102
+ });
103
+ webhookData.lastMessage = message;
104
+ });
105
+ api.listener.start();
106
+ const webhookData = this.getWorkflowStaticData('node');
107
+ webhookData.isConnected = true;
108
+ webhookData.eventTypes = this.getNodeParameter('eventTypes', 0);
109
+ return true;
110
+ }
111
+ catch (error) {
112
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Zalo connection failed');
113
+ }
114
+ },
115
+ async delete() {
116
+ const webhookData = this.getWorkflowStaticData('node');
117
+ if (api) {
118
+ api.listener.stop();
119
+ api = undefined;
120
+ }
121
+ if (reconnectTimer) {
122
+ clearTimeout(reconnectTimer);
123
+ reconnectTimer = undefined;
124
+ }
125
+ delete webhookData.isConnected;
126
+ delete webhookData.eventTypes;
127
+ delete webhookData.lastMessage;
128
+ return true;
129
+ },
130
+ },
131
+ };
132
+ }
133
+ async webhook() {
134
+ const req = this.getRequestObject();
135
+ const body = req.body;
136
+ console.log(body);
137
+ const webhookData = this.getWorkflowStaticData('node');
138
+ const message = webhookData.lastMessage;
139
+ console.log(message);
140
+ delete webhookData.lastMessage;
141
+ return {
142
+ workflowData: [this.helpers.returnJsonArray(req.body)],
143
+ };
144
+ }
145
+ }
146
+ exports.ZaloMessageTrigger = ZaloMessageTrigger;
147
+ //# sourceMappingURL=ZaloMessageTrigger.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZaloMessageTrigger.node.js","sourceRoot":"","sources":["../../../nodes/ZaloMessageTrigger/ZaloMessageTrigger.node.ts"],"names":[],"mappings":";;;AAAA,+CAQsB;AACtB,mCAA+C;AAE/C,IAAI,GAAoB,CAAC;AACzB,IAAI,cAA0C,CAAC;AAE/C,MAAa,kBAAkB;IAA/B;QACC,gBAAW,GAAyB;YACnC,WAAW,EAAE,sBAAsB;YACnC,IAAI,EAAE,oBAAoB;YAC1B,IAAI,EAAE,yBAAyB;YAC/B,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,OAAO,EAAE,CAAC;YACV,WAAW,EAAE,sCAAsC;YACnD,QAAQ,EAAE;gBACT,IAAI,EAAE,sBAAsB;aAC5B;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,SAAS;iBACf;aACD;YACD,WAAW,EAAE;gBACZ;oBACC,IAAI,EAAE,SAAS;oBACf,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,iCAAiC;iBAC9C;aACD;YACD,UAAU,EAAE;gBACX;oBACC,WAAW,EAAE,aAAa;oBAC1B,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE;wBACR;4BACC,IAAI,EAAE,eAAe;4BACrB,KAAK,EAAE,mBAAU,CAAC,IAAI;4BACtB,WAAW,EAAE,kCAAkC;yBAC/C;wBACD;4BACC,IAAI,EAAE,gBAAgB;4BACtB,KAAK,EAAE,mBAAU,CAAC,KAAK;4BACvB,WAAW,EAAE,4BAA4B;yBACzC;qBACD;oBACD,OAAO,EAAE,CAAC,mBAAU,CAAC,IAAI,EAAE,mBAAU,CAAC,KAAK,CAAC;oBAC5C,QAAQ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AAG,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,WAAW,CAAC,WAAW,CAAC;oBAC/B,OAAO,IAAI,CAAC;gBACb,CAAC;aACD;SACD,CAAC;IAmBH,CAAC;IAjBA,KAAK,CAAC,OAAO;QACN,MAAM,GAAG,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,WAAW,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;QACvD,MAAM,OAAO,GAAG,WAAW,CAAC,WAA0B,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAI3B,OAAO,WAAW,CAAC,WAAW,CAAC;QAG/B,OAAO;YACN,YAAY,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SACtD,CAAC;IACH,CAAC;CACD;AArKD,gDAqKC"}
@@ -0,0 +1,5 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class ZaloPoll implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }