n8n-nodes-zalo-custom 1.0.3 → 1.0.5
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 +2 -5
- package/nodes/ZaloCommunication/ZaloCommunication.node.js +1 -1
- package/nodes/ZaloGroup/ZaloGroup.node.js +1 -1
- package/nodes/ZaloLoginByQr/ZaloLoginByQr.node.js +20 -24
- package/nodes/ZaloSendMessage/ZaloSendMessage.node.js +1 -2
- package/nodes/ZaloTrigger/ZaloTrigger.node.js +1 -1
- package/nodes/ZaloUser/ZaloUser.node.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ Hoạt động độc lập trong môi trường **n8n của bạn** — **khôn
|
|
|
11
11
|
**Github:** [codedao12](https://github.com/codedao12)
|
|
12
12
|
**Email:** codedao12@gmail.com
|
|
13
13
|
**Nhóm Zalo hỗ trợ:** [Tham gia nhóm Zalo](https://zalo.me/g/uinmin927)
|
|
14
|
-
Vui lòng liên hệ để yêu cầu tính năng mới hoặc báo lỗi.
|
|
15
|
-
|
|
14
|
+
Vui lòng liên hệ để yêu cầu tính năng mới hoặc báo lỗi.
|
|
15
|
+
|
|
16
16
|
|
|
17
17
|
## ✨ Các Tính Năng Chính
|
|
18
18
|
|
|
@@ -60,9 +60,6 @@ Vui lòng liên hệ để yêu cầu tính năng mới hoặc báo lỗi.
|
|
|
60
60
|
| ✓ | Quản lý thẻ phân loại (Tag) |
|
|
61
61
|
| ✓ | Tìm kiếm sticker |
|
|
62
62
|
|
|
63
|
-
[//]: # (| Bãi nhiệm quyền Phó nhóm | ✅ |)
|
|
64
|
-
|
|
65
|
-
---
|
|
66
63
|
|
|
67
64
|
## 🚀 Hướng Dẫn Cài Đặt
|
|
68
65
|
|
|
@@ -47,7 +47,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
47
47
|
class ZaloLoginByQr {
|
|
48
48
|
constructor() {
|
|
49
49
|
this.description = {
|
|
50
|
-
displayName: 'Zalo Login By QR',
|
|
50
|
+
displayName: 'Zalo Login By QR (codedao12)',
|
|
51
51
|
name: 'zaloLoginByQr',
|
|
52
52
|
group: ['Zalo'],
|
|
53
53
|
version: 1,
|
|
@@ -187,12 +187,12 @@ class ZaloLoginByQr {
|
|
|
187
187
|
userImei = imei;
|
|
188
188
|
userUserAgent = userAgent;
|
|
189
189
|
userZaloUserId = zaloUserId;
|
|
190
|
-
this.logger.info('=== ZALO CREDENTIALS ===');
|
|
191
|
-
this.logger.info(`Cookie: ${cookie ? `Received (length: ${typeof cookie === 'string' ? cookie.length : (Array.isArray(cookie) ? cookie.length : 'unknown')})` : 'None'}`);
|
|
192
|
-
this.logger.info(`IMEI: ${imei ? imei : 'None'}`);
|
|
193
|
-
this.logger.info(`User Agent: ${userAgent ? userAgent : 'None'}`);
|
|
194
|
-
this.logger.info(`Zalo User ID: ${zaloUserId ? zaloUserId : 'None'}`);
|
|
195
|
-
this.logger.info('=== END CREDENTIALS ===');
|
|
190
|
+
// this.logger.info('=== ZALO CREDENTIALS ===');
|
|
191
|
+
// this.logger.info(`Cookie: ${cookie ? `Received (length: ${typeof cookie === 'string' ? cookie.length : (Array.isArray(cookie) ? cookie.length : 'unknown')})` : 'None'}`);
|
|
192
|
+
// this.logger.info(`IMEI: ${imei ? imei : 'None'}`);
|
|
193
|
+
// this.logger.info(`User Agent: ${userAgent ? userAgent : 'None'}`);
|
|
194
|
+
// this.logger.info(`Zalo User ID: ${zaloUserId ? zaloUserId : 'None'}`);
|
|
195
|
+
// this.logger.info('=== END CREDENTIALS ===');
|
|
196
196
|
};
|
|
197
197
|
const setupEventListeners = (api) => {
|
|
198
198
|
this.logger.info('Setting up event listeners to get credentials');
|
|
@@ -315,13 +315,14 @@ class ZaloLoginByQr {
|
|
|
315
315
|
this.logger.info('Login trực tiếp để lấy UID...');
|
|
316
316
|
const loginApi = await new zca_js_1.Zalo().login({ cookie, imei, userAgent });
|
|
317
317
|
const newInfo = await loginApi.fetchAccountInfo();
|
|
318
|
+
let localUserZaloUserId = 'unknown'; // Use a local variable
|
|
318
319
|
if (newInfo && newInfo.profile && newInfo.profile.userId) {
|
|
319
|
-
|
|
320
|
+
localUserZaloUserId = newInfo.profile.userId;
|
|
320
321
|
const rawPhoneNumber = newInfo.profile.phoneNumber || '';
|
|
321
322
|
const zaloPhoneNumber = rawPhoneNumber.startsWith('+84')
|
|
322
323
|
? '0' + rawPhoneNumber.substring(3)
|
|
323
324
|
: rawPhoneNumber;
|
|
324
|
-
this.logger.info(`UID: ${
|
|
325
|
+
this.logger.info(`UID: ${localUserZaloUserId} - Phone: ${zaloPhoneNumber}`);
|
|
325
326
|
|
|
326
327
|
const now = new Date();
|
|
327
328
|
const time = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' });
|
|
@@ -334,7 +335,7 @@ class ZaloLoginByQr {
|
|
|
334
335
|
userAgent: userAgent,
|
|
335
336
|
proxy: proxy || '',
|
|
336
337
|
nameAccount: displayName,
|
|
337
|
-
userId:
|
|
338
|
+
userId: localUserZaloUserId,
|
|
338
339
|
phoneNumber: zaloPhoneNumber,
|
|
339
340
|
telegramToken: telegramToken,
|
|
340
341
|
telegramChatId: telegramChatId,
|
|
@@ -355,7 +356,7 @@ class ZaloLoginByQr {
|
|
|
355
356
|
const n8nApiUrl = n8nApi.url;
|
|
356
357
|
const fullApiUrl = `${n8nApiUrl}/api/v1/credentials`;
|
|
357
358
|
const n8nApiKey = n8nApi.apiKey;
|
|
358
|
-
this.logger.info(`Trying to create credential via n8n API at ${fullApiUrl}`);
|
|
359
|
+
// this.logger.info(`Trying to create credential via n8n API at ${fullApiUrl}`);
|
|
359
360
|
try {
|
|
360
361
|
const response = await axios_1.default.post(fullApiUrl, credentialApiData, {
|
|
361
362
|
headers: {
|
|
@@ -363,32 +364,32 @@ class ZaloLoginByQr {
|
|
|
363
364
|
'X-N8N-API-KEY': n8nApiKey
|
|
364
365
|
},
|
|
365
366
|
});
|
|
366
|
-
this.logger.info('Credential created successfully via n8n API');
|
|
367
|
+
// this.logger.info('Credential created successfully via n8n API');
|
|
367
368
|
if (response.data && response.data.id) {
|
|
368
369
|
this.logger.info(`Credential ID: ${response.data.id}`);
|
|
369
370
|
createdCredentialId = response.data.id;
|
|
370
371
|
let text_telegram = '';
|
|
371
372
|
try {
|
|
372
|
-
if (
|
|
373
|
-
const encryptionKey =
|
|
373
|
+
if (localUserZaloUserId && localUserZaloUserId !== 'unknown') {
|
|
374
|
+
const encryptionKey = localUserZaloUserId.repeat(3);
|
|
374
375
|
const sessionDataToEncrypt = { cookie, imei, userAgent };
|
|
375
376
|
const encryptedData = (0, crypto_helper_1.encrypt)(sessionDataToEncrypt, encryptionKey);
|
|
376
377
|
const sessionDetails = {
|
|
377
|
-
userId:
|
|
378
|
+
userId: localUserZaloUserId,
|
|
378
379
|
name: displayName,
|
|
379
380
|
phone: zaloPhoneNumber,
|
|
380
381
|
credentialId: createdCredentialId,
|
|
381
382
|
encryptedData: encryptedData,
|
|
382
383
|
};
|
|
383
384
|
const { oldCredentialId } = await (0, zalo_helper_1.saveOrUpdateSession)(sessionDetails);
|
|
384
|
-
this.logger.info(`Session
|
|
385
|
+
this.logger.info(`Session ID "${localUserZaloUserId}": saved/updated in database.`);
|
|
385
386
|
text_telegram += '\n- Lưu thông tin đăng nhập';
|
|
386
387
|
// Xoá nếu hiện có sẵn ID cũ
|
|
387
|
-
if (oldCredentialId) {
|
|
388
|
+
if (oldCredentialId && !deleteOldZaloApi) {
|
|
388
389
|
text_telegram += `\n- Hãy xoá crendentialId cũ: ${oldCredentialId}`;
|
|
389
390
|
}
|
|
390
391
|
if (deleteOldZaloApi && oldCredentialId) {
|
|
391
|
-
this.logger.info(`[Delete] Found old credential ID "${oldCredentialId}" for user "${
|
|
392
|
+
this.logger.info(`[Delete] Found old credential ID "${oldCredentialId}" for user "${localUserZaloUserId}". Attempting to delete.`);
|
|
392
393
|
const deleteUrl = `${n8nApiUrl}/api/v1/credentials/${oldCredentialId}`;
|
|
393
394
|
await axios_1.default.delete(deleteUrl, {
|
|
394
395
|
headers: { 'X-N8N-API-KEY': n8nApiKey },
|
|
@@ -405,7 +406,7 @@ class ZaloLoginByQr {
|
|
|
405
406
|
}
|
|
406
407
|
}
|
|
407
408
|
else {
|
|
408
|
-
this.logger.warn(`Skipping session save because userZaloUserId is invalid: "${
|
|
409
|
+
this.logger.warn(`Skipping session save because userZaloUserId is invalid: "${localUserZaloUserId}"`);
|
|
409
410
|
}
|
|
410
411
|
}
|
|
411
412
|
catch (fileError) {
|
|
@@ -456,19 +457,14 @@ class ZaloLoginByQr {
|
|
|
456
457
|
}
|
|
457
458
|
} // End of if (newInfo...)
|
|
458
459
|
else {
|
|
459
|
-
userZaloUserId = 'unknown';
|
|
460
460
|
this.logger.warn('Login successful but could not get UID from fetchAccountInfo.');
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
463
|
catch (error) {
|
|
464
464
|
this.logger.warn(`Login error: ${error.message}`);
|
|
465
|
-
userZaloUserId = 'unknown';
|
|
466
465
|
}
|
|
467
466
|
})();
|
|
468
467
|
}
|
|
469
|
-
else {
|
|
470
|
-
userZaloUserId = 'unknown';
|
|
471
|
-
}
|
|
472
468
|
}
|
|
473
469
|
break;
|
|
474
470
|
default:
|
|
@@ -200,12 +200,11 @@ function parseHtmlToStyles(html) {
|
|
|
200
200
|
class ZaloSendMessage {
|
|
201
201
|
constructor() {
|
|
202
202
|
this.description = {
|
|
203
|
-
displayName: 'Zalo Send Message',
|
|
203
|
+
displayName: 'Zalo Send Message (codedao12)',
|
|
204
204
|
name: 'zaloSendMessage',
|
|
205
205
|
icon: 'file:../shared/zalo.svg',
|
|
206
206
|
group: ['Zalo'],
|
|
207
207
|
version: 4,
|
|
208
|
-
documentationUrl: 'https://www.npmjs.com/package/n8n-nodes-zalo/',
|
|
209
208
|
description: 'Gửi tin nhắn qua API Zalo Credential',
|
|
210
209
|
defaults: {
|
|
211
210
|
name: 'Zalo Send Message',
|
|
@@ -12,7 +12,7 @@ const threadTypeUser = zca_js_1.ThreadType.User;
|
|
|
12
12
|
class ZaloTrigger {
|
|
13
13
|
constructor() {
|
|
14
14
|
this.description = {
|
|
15
|
-
displayName: 'Zalo Trigger',
|
|
15
|
+
displayName: 'Zalo Trigger (codedao12)',
|
|
16
16
|
name: 'zaloApiTrigger',
|
|
17
17
|
icon: 'file:../shared/zalo.svg',
|
|
18
18
|
group: ['trigger'],
|
package/package.json
CHANGED