zalo-agent-cli 1.0.1 → 1.0.4
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/package.json +5 -1
- package/src/commands/friend.js +32 -13
- package/src/index.js +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zalo-agent-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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
|
|
package/src/index.js
CHANGED
|
@@ -5,8 +5,14 @@
|
|
|
5
5
|
* Entry point: registers all command groups via Commander.js.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
8
11
|
import { Command } from "commander";
|
|
9
12
|
import { registerLoginCommands } from "./commands/login.js";
|
|
13
|
+
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf8"));
|
|
10
16
|
import { registerMsgCommands } from "./commands/msg.js";
|
|
11
17
|
import { registerFriendCommands } from "./commands/friend.js";
|
|
12
18
|
import { registerGroupCommands } from "./commands/group.js";
|
|
@@ -19,7 +25,7 @@ const program = new Command();
|
|
|
19
25
|
program
|
|
20
26
|
.name("zalo-agent")
|
|
21
27
|
.description("CLI tool for Zalo automation — multi-account, proxy, bank transfers, QR payments")
|
|
22
|
-
.version(
|
|
28
|
+
.version(pkg.version)
|
|
23
29
|
.option("--json", "Output results as JSON (machine-readable)")
|
|
24
30
|
.hook("preAction", async (thisCommand) => {
|
|
25
31
|
// Suppress zca-js internal logs in JSON mode to keep stdout clean for piping
|