zalo-agent-cli 1.0.0 → 1.0.3
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 +4 -0
- package/package.json +5 -1
- package/src/commands/friend.js +32 -13
- package/src/utils/qr-http-server.js +44 -12
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zalo-agent-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "CLI tool for Zalo automation — multi-account, proxy support, bank transfers, QR payments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"vietqr",
|
|
30
30
|
"zca-js"
|
|
31
31
|
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/PhucMPham/zalo-agent-cli"
|
|
35
|
+
},
|
|
32
36
|
"license": "MIT",
|
|
33
37
|
"engines": {
|
|
34
38
|
"node": ">=20"
|
package/src/commands/friend.js
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
import { getApi } from "../core/zalo-client.js";
|
|
6
6
|
import { success, error, info, output } from "../utils/output.js";
|
|
7
7
|
|
|
8
|
+
/** Extract numeric error code from zca-js error message string. */
|
|
9
|
+
function extractErrorCode(msg) {
|
|
10
|
+
const match = String(msg).match(/\((\-?\d+)\)/);
|
|
11
|
+
return match ? Number(match[1]) : null;
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
export function registerFriendCommands(program) {
|
|
9
15
|
const friend = program.command("friend").description("Manage friends and contacts");
|
|
10
16
|
|
|
@@ -45,13 +51,17 @@ export function registerFriendCommands(program) {
|
|
|
45
51
|
.action(async (query) => {
|
|
46
52
|
try {
|
|
47
53
|
const result = await getApi().findUser(query);
|
|
54
|
+
if (!result || (!result.uid && !result?.data?.uid)) {
|
|
55
|
+
error(`No Zalo user found for "${query}". User may not exist, has disabled phone search, or phone is not registered on Zalo.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
48
58
|
output(result, program.opts().json, () => {
|
|
49
59
|
const u = result?.uid ? result : result?.data || result;
|
|
50
60
|
info(`User ID: ${u.uid || "?"}`);
|
|
51
|
-
info(`Name: ${u.displayName || u.zaloName || "?"}`);
|
|
61
|
+
info(`Name: ${u.displayName || u.zaloName || u.display_name || u.zalo_name || "?"}`);
|
|
52
62
|
});
|
|
53
63
|
} catch (e) {
|
|
54
|
-
error(e.message);
|
|
64
|
+
error(`Find user failed: ${e.message}`);
|
|
55
65
|
}
|
|
56
66
|
});
|
|
57
67
|
|
|
@@ -79,10 +89,19 @@ export function registerFriendCommands(program) {
|
|
|
79
89
|
.option("-m, --msg <text>", "Message to include", "")
|
|
80
90
|
.action(async (userId, opts) => {
|
|
81
91
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
// zca-js API signature: sendFriendRequest(msg, userId)
|
|
93
|
+
const result = await getApi().sendFriendRequest(opts.msg, userId);
|
|
94
|
+
output(result, program.opts().json, () => success(`Friend request sent to ${userId}`));
|
|
84
95
|
} catch (e) {
|
|
85
|
-
error
|
|
96
|
+
// Map Zalo error codes to actionable messages
|
|
97
|
+
const code = e.code || extractErrorCode(e.message);
|
|
98
|
+
const errMap = {
|
|
99
|
+
225: `Already friends with ${userId}. Use "friend list" to verify.`,
|
|
100
|
+
215: `User ${userId} may have blocked you or is unreachable.`,
|
|
101
|
+
222: `User ${userId} already sent you a friend request. Use "friend accept ${userId}" instead.`,
|
|
102
|
+
"-1": `Invalid userId "${userId}". Use "friend find <phone>" to get the correct userId first.`,
|
|
103
|
+
};
|
|
104
|
+
error(errMap[code] || `Friend request failed (code ${code}): ${e.message}`);
|
|
86
105
|
}
|
|
87
106
|
});
|
|
88
107
|
|
|
@@ -92,9 +111,9 @@ export function registerFriendCommands(program) {
|
|
|
92
111
|
.action(async (userId) => {
|
|
93
112
|
try {
|
|
94
113
|
const result = await getApi().acceptFriendRequest(userId);
|
|
95
|
-
output(result, program.opts().json, () => success(
|
|
114
|
+
output(result, program.opts().json, () => success(`Accepted friend request from ${userId}`));
|
|
96
115
|
} catch (e) {
|
|
97
|
-
error(e.message);
|
|
116
|
+
error(`Accept friend request failed for ${userId}: ${e.message}`);
|
|
98
117
|
}
|
|
99
118
|
});
|
|
100
119
|
|
|
@@ -104,9 +123,9 @@ export function registerFriendCommands(program) {
|
|
|
104
123
|
.action(async (userId) => {
|
|
105
124
|
try {
|
|
106
125
|
const result = await getApi().removeFriend(userId);
|
|
107
|
-
output(result, program.opts().json, () => success(
|
|
126
|
+
output(result, program.opts().json, () => success(`Removed friend ${userId}`));
|
|
108
127
|
} catch (e) {
|
|
109
|
-
error(e.message);
|
|
128
|
+
error(`Remove friend failed for ${userId}: ${e.message}`);
|
|
110
129
|
}
|
|
111
130
|
});
|
|
112
131
|
|
|
@@ -116,9 +135,9 @@ export function registerFriendCommands(program) {
|
|
|
116
135
|
.action(async (userId) => {
|
|
117
136
|
try {
|
|
118
137
|
const result = await getApi().blockUser(userId);
|
|
119
|
-
output(result, program.opts().json, () => success(
|
|
138
|
+
output(result, program.opts().json, () => success(`Blocked user ${userId}`));
|
|
120
139
|
} catch (e) {
|
|
121
|
-
error(e.message);
|
|
140
|
+
error(`Block user failed for ${userId}: ${e.message}`);
|
|
122
141
|
}
|
|
123
142
|
});
|
|
124
143
|
|
|
@@ -128,9 +147,9 @@ export function registerFriendCommands(program) {
|
|
|
128
147
|
.action(async (userId) => {
|
|
129
148
|
try {
|
|
130
149
|
const result = await getApi().unblockUser(userId);
|
|
131
|
-
output(result, program.opts().json, () => success(
|
|
150
|
+
output(result, program.opts().json, () => success(`Unblocked user ${userId}`));
|
|
132
151
|
} catch (e) {
|
|
133
|
-
error(e.message);
|
|
152
|
+
error(`Unblock user failed for ${userId}: ${e.message}`);
|
|
134
153
|
}
|
|
135
154
|
});
|
|
136
155
|
|
|
@@ -29,28 +29,60 @@ export function startQrServer(qrImagePath, port = 18927, tryPorts = [18927, 8080
|
|
|
29
29
|
}
|
|
30
30
|
const img = readFileSync(qrImagePath);
|
|
31
31
|
const b64 = img.toString("base64");
|
|
32
|
+
// Embed mascot inline (read from assets if available, else skip)
|
|
33
|
+
let mascotB64 = "";
|
|
34
|
+
try {
|
|
35
|
+
const { resolve: resolvePath } = await import("path");
|
|
36
|
+
const { fileURLToPath } = await import("url");
|
|
37
|
+
const { dirname } = await import("path");
|
|
38
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
39
|
+
const mascotPath = resolvePath(dir, "../../assets/mascot.png");
|
|
40
|
+
if (existsSync(mascotPath)) {
|
|
41
|
+
mascotB64 = readFileSync(mascotPath).toString("base64");
|
|
42
|
+
}
|
|
43
|
+
} catch {}
|
|
44
|
+
const mascotImg = mascotB64
|
|
45
|
+
? `<img src="data:image/png;base64,${mascotB64}" class="mascot" alt="zalo-agent"/>`
|
|
46
|
+
: "";
|
|
32
47
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
33
48
|
res.end(`<!DOCTYPE html>
|
|
34
|
-
<html><head><meta charset="utf-8"><title>Zalo QR Login</title>
|
|
49
|
+
<html><head><meta charset="utf-8"><title>Zalo Agent — QR Login</title>
|
|
35
50
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
36
51
|
<style>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
*{box-sizing:border-box}
|
|
53
|
+
body{display:flex;justify-content:center;align-items:center;min-height:100vh;margin:0;
|
|
54
|
+
background:linear-gradient(135deg,#0a1628 0%,#111d33 50%,#0d1f3c 100%);font-family:system-ui,-apple-system,sans-serif}
|
|
55
|
+
.card{text-align:center;padding:2.5rem 2rem;background:rgba(17,29,51,0.9);
|
|
56
|
+
border-radius:20px;max-width:420px;width:90%;
|
|
57
|
+
border:1px solid rgba(59,130,246,0.2);backdrop-filter:blur(10px);
|
|
58
|
+
box-shadow:0 20px 60px rgba(0,0,0,0.5),0 0 40px rgba(59,130,246,0.1)}
|
|
59
|
+
.mascot{width:80px;height:80px;border-radius:50%;margin-bottom:0.5rem;
|
|
60
|
+
border:2px solid rgba(59,130,246,0.4);box-shadow:0 0 20px rgba(59,130,246,0.2)}
|
|
61
|
+
h1{color:#e2e8f0;font-size:1.1rem;font-weight:600;margin:0.5rem 0}
|
|
62
|
+
.brand{color:#3b82f6;font-size:0.8rem;margin-bottom:1.5rem;opacity:0.8}
|
|
63
|
+
.qr-img{width:260px;height:260px;border-radius:12px;border:3px solid rgba(59,130,246,0.3);
|
|
64
|
+
box-shadow:0 0 30px rgba(59,130,246,0.15)}
|
|
65
|
+
.hint{color:#94a3b8;font-size:0.85rem;margin-top:1.2rem;line-height:1.5}
|
|
66
|
+
.hint strong{color:#60a5fa}
|
|
67
|
+
.success-text{color:#4ade80;font-size:1.3rem;font-weight:bold}
|
|
42
68
|
.hidden{display:none}
|
|
69
|
+
.footer{color:#475569;font-size:0.7rem;margin-top:1.5rem}
|
|
70
|
+
.footer a{color:#3b82f6;text-decoration:none}
|
|
43
71
|
</style></head>
|
|
44
72
|
<body><div class="card">
|
|
45
73
|
<div id="qr-view">
|
|
46
|
-
|
|
47
|
-
<
|
|
48
|
-
<p
|
|
74
|
+
${mascotImg}
|
|
75
|
+
<h1>Zalo Agent CLI</h1>
|
|
76
|
+
<p class="brand">QR Code Login</p>
|
|
77
|
+
<img src="data:image/png;base64,${b64}" class="qr-img" alt="QR Code"/>
|
|
78
|
+
<p class="hint">Open <strong>Zalo app</strong> > <strong>QR Scanner</strong> to scan</p>
|
|
79
|
+
<p class="footer">Powered by <a href="https://github.com/PhucMPham/zalo-agent-cli">zalo-agent-cli</a></p>
|
|
49
80
|
</div>
|
|
50
81
|
<div id="success-view" class="hidden">
|
|
51
|
-
|
|
52
|
-
<
|
|
53
|
-
<p>
|
|
82
|
+
${mascotImg}
|
|
83
|
+
<h1 style="color:#4ade80;font-size:1.5rem;margin:1rem 0">Login Successful!</h1>
|
|
84
|
+
<p class="success-text">You can close this page now.</p>
|
|
85
|
+
<p class="hint">The CLI is ready to use.</p>
|
|
54
86
|
</div>
|
|
55
87
|
</div>
|
|
56
88
|
<script>
|