zalo-agent-cli 1.0.5 → 1.0.6
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 +1 -1
- package/src/commands/friend.js +3 -1
- package/src/commands/msg.js +50 -2
package/package.json
CHANGED
package/src/commands/friend.js
CHANGED
|
@@ -52,7 +52,9 @@ export function registerFriendCommands(program) {
|
|
|
52
52
|
try {
|
|
53
53
|
const result = await getApi().findUser(query);
|
|
54
54
|
if (!result || (!result.uid && !result?.data?.uid)) {
|
|
55
|
-
error(
|
|
55
|
+
error(
|
|
56
|
+
`No Zalo user found for "${query}". User may not exist, has disabled phone search, or phone is not registered on Zalo.`,
|
|
57
|
+
);
|
|
56
58
|
return;
|
|
57
59
|
}
|
|
58
60
|
output(result, program.opts().json, () => {
|
package/src/commands/msg.js
CHANGED
|
@@ -190,12 +190,60 @@ export function registerMsgCommands(program) {
|
|
|
190
190
|
msg.command("react <msgId> <threadId> <reaction>")
|
|
191
191
|
.description("React to a message with an emoji")
|
|
192
192
|
.option("-t, --type <n>", "Thread type: 0=User, 1=Group", "0")
|
|
193
|
+
.option("-c, --cli-msg-id <id>", "Client message ID (defaults to msgId)")
|
|
193
194
|
.action(async (msgId, threadId, reaction, opts) => {
|
|
194
195
|
try {
|
|
195
|
-
|
|
196
|
+
// zca-js addReaction(icon, dest) — dest needs msgId + cliMsgId
|
|
197
|
+
const dest = {
|
|
198
|
+
data: { msgId, cliMsgId: opts.cliMsgId || msgId },
|
|
199
|
+
threadId,
|
|
200
|
+
type: Number(opts.type),
|
|
201
|
+
};
|
|
202
|
+
const result = await getApi().addReaction(reaction, dest);
|
|
196
203
|
output(result, program.opts().json, () => success(`Reacted with '${reaction}'`));
|
|
197
204
|
} catch (e) {
|
|
198
|
-
error(e.message);
|
|
205
|
+
error(`React failed: ${e.message}`);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
msg.command("listen")
|
|
210
|
+
.description("Listen for incoming messages (Ctrl+C to stop)")
|
|
211
|
+
.action(async () => {
|
|
212
|
+
try {
|
|
213
|
+
const api = getApi();
|
|
214
|
+
info("Listening for messages... Press Ctrl+C to stop.");
|
|
215
|
+
info("Note: Only one web listener per account. Browser Zalo will disconnect.");
|
|
216
|
+
|
|
217
|
+
api.listener.on("message", (msg) => {
|
|
218
|
+
const content = typeof msg.data.content === "string" ? msg.data.content : "[non-text]";
|
|
219
|
+
const data = {
|
|
220
|
+
msgId: msg.data.msgId,
|
|
221
|
+
cliMsgId: msg.data.cliMsgId,
|
|
222
|
+
threadId: msg.threadId,
|
|
223
|
+
type: msg.type,
|
|
224
|
+
isSelf: msg.isSelf,
|
|
225
|
+
content,
|
|
226
|
+
};
|
|
227
|
+
if (program.opts().json) {
|
|
228
|
+
console.log(JSON.stringify(data));
|
|
229
|
+
} else {
|
|
230
|
+
const dir = msg.isSelf ? "→" : "←";
|
|
231
|
+
console.log(` ${dir} [${msg.threadId}] ${content} (msgId: ${msg.data.msgId})`);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
api.listener.start();
|
|
236
|
+
|
|
237
|
+
// Keep alive until Ctrl+C
|
|
238
|
+
await new Promise((resolve) => {
|
|
239
|
+
process.on("SIGINT", () => {
|
|
240
|
+
api.listener.stop();
|
|
241
|
+
info("Listener stopped.");
|
|
242
|
+
resolve();
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
} catch (e) {
|
|
246
|
+
error(`Listen failed: ${e.message}`);
|
|
199
247
|
}
|
|
200
248
|
});
|
|
201
249
|
|