zalo-agent-cli 1.1.0 → 1.3.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.
@@ -124,14 +124,28 @@ setInterval(async()=>{
124
124
 
125
125
  server.on("listening", async () => {
126
126
  const actualPort = server.address().port;
127
- info(`QR available at: http://localhost:${actualPort}/qr`);
127
+ const jsonMode = process.env.ZALO_JSON_MODE === "1";
128
+ let publicIp = null;
129
+
128
130
  // Auto-detect public IP for VPS users
129
131
  try {
130
132
  const res = await nodefetch("https://api.ipify.org", { timeout: 3000 });
131
- const ip = (await res.text()).trim();
132
- if (ip) info(`On VPS, open: http://${ip}:${actualPort}/qr`);
133
- } catch {
134
- info(`On VPS, open: http://<your-server-ip>:${actualPort}/qr`);
133
+ publicIp = (await res.text()).trim() || null;
134
+ } catch {}
135
+
136
+ if (jsonMode) {
137
+ console.log(JSON.stringify({
138
+ event: "qr_server",
139
+ port: actualPort,
140
+ localUrl: `http://localhost:${actualPort}/qr`,
141
+ publicUrl: publicIp ? `http://${publicIp}:${actualPort}/qr` : null,
142
+ }));
143
+ } else {
144
+ info(`QR available at: http://localhost:${actualPort}/qr`);
145
+ if (publicIp) info(`On VPS, open: http://${publicIp}:${actualPort}/qr`);
146
+ else info(`On VPS, open: http://<your-server-ip>:${actualPort}/qr`);
147
+ info(`If firewall blocks, run: sudo ufw allow ${actualPort}/tcp`);
148
+ info(`Or copy QR file: scp user@vps:~/.zalo-agent/qr.png ./qr.png`);
135
149
  }
136
150
  });
137
151