hyperclaw 5.2.8 → 5.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.
- package/dist/a2ui-protocol-DEsfqO7h.js +75 -0
- package/dist/agents-routing-ChorJKFL.js +6 -0
- package/dist/agents-routing-Cpg20-1e.js +398 -0
- package/dist/api-key-validation-DgOBmp8Y.js +64 -0
- package/dist/api-keys-guide--73Bq0Ey.js +149 -0
- package/dist/audit-Dntx9fG9.js +445 -0
- package/dist/banner-B_rR7FPO.js +7 -0
- package/dist/banner-Bb7CderS.js +143 -0
- package/dist/banner-BbUkjcoX.js +7 -0
- package/dist/banner-DupxNjxh.js +143 -0
- package/dist/bounty-tools-Dn9Yq7V1.js +211 -0
- package/dist/browser-tools-CJ9M9o22.js +179 -0
- package/dist/browser-tools-CXxWxA1c.js +5 -0
- package/dist/chat-D1Zc73I5.js +513 -0
- package/dist/chat-TGA-UO46.js +536 -0
- package/dist/claw-tasks-ChqkHdFs.js +80 -0
- package/dist/config-Bzues-G2.js +7 -0
- package/dist/config-DGAAJ49A.js +261 -0
- package/dist/connector-1efnZgQN.js +566 -0
- package/dist/connector-B5q1_srT.js +286 -0
- package/dist/connector-BMFLJ4fr.js +508 -0
- package/dist/connector-BZYv9siY.js +189 -0
- package/dist/connector-B_XkXm-j.js +218 -0
- package/dist/connector-BkY1I6gf.js +189 -0
- package/dist/connector-C2Z3RN1z.js +350 -0
- package/dist/connector-C7aYvVzU.js +225 -0
- package/dist/connector-CXXYOyHw.js +164 -0
- package/dist/connector-Ca1J23HX.js +167 -0
- package/dist/connector-Cjqc656I.js +181 -0
- package/dist/connector-CluRienN.js +425 -0
- package/dist/connector-CuNz2eP-.js +305 -0
- package/dist/connector-DHL_oeHy.js +552 -0
- package/dist/connector-DJ79rd1L.js +173 -0
- package/dist/connector-DcLE6xCZ.js +239 -0
- package/dist/connector-DcyQTJnJ.js +162 -0
- package/dist/connector-DgyX9qSc.js +192 -0
- package/dist/connector-DnDXXZ7L.js +182 -0
- package/dist/connector-DqUslg-X.js +213 -0
- package/dist/connector-Duc-HmRZ.js +85 -0
- package/dist/connector-IV0QFer8.js +498 -0
- package/dist/connector-OnsLxE8G.js +194 -0
- package/dist/connector-UYu_TS0X.js +204 -0
- package/dist/connector-cCA5ffmp.js +340 -0
- package/dist/connector-fbNfx4_L.js +568 -0
- package/dist/connector-fi2vlwbO.js +276 -0
- package/dist/connector-l3LD8IDN.js +419 -0
- package/dist/cost-tracker-DCXDUzBI.js +103 -0
- package/dist/credentials-store-Bmm9e1SS.js +7 -0
- package/dist/credentials-store-D8ERbGR2.js +89 -0
- package/dist/cron-tasks-OQbgmenS.js +85 -0
- package/dist/daemon-BgT541y-.js +421 -0
- package/dist/daemon-aVX-WGz1.js +421 -0
- package/dist/daemon-iFmVBPXN.js +7 -0
- package/dist/daemon-iM7U3tDr.js +7 -0
- package/dist/delivery-Pko6sSkt.js +4 -0
- package/dist/delivery-hMHFRZwy.js +95 -0
- package/dist/destructive-gate-C2TrWsp2.js +101 -0
- package/dist/developer-keys-BWXHaWxY.js +127 -0
- package/dist/developer-keys-CzDxVczE.js +8 -0
- package/dist/device-auth-store-C1bCwXO2.js +7 -0
- package/dist/device-auth-store-DIZTOz4V.js +88 -0
- package/dist/doctor-C6nAGdH8.js +233 -0
- package/dist/doctor-mgWumA25.js +6 -0
- package/dist/engine-BGRTi0fo.js +327 -0
- package/dist/engine-BrDEACit.js +327 -0
- package/dist/engine-BvCEhaUn.js +7 -0
- package/dist/engine-DrsMsoLZ.js +7 -0
- package/dist/env-resolve-CHxjGo8u.js +151 -0
- package/dist/env-resolve-pIETNTpQ.js +10 -0
- package/dist/extraction-tools-BE6z_Yw5.js +91 -0
- package/dist/extraction-tools-CJsdyBST.js +5 -0
- package/dist/form_data-B2_0EoWj.js +8657 -0
- package/dist/gmail-watch-setup-1RGIHNdu.js +42 -0
- package/dist/health-BMUmUNoe.js +152 -0
- package/dist/health-C8n9RH5O.js +6 -0
- package/dist/heartbeat-engine-aRbab8a5.js +89 -0
- package/dist/hub-BJM2KXLO.js +6 -0
- package/dist/hub-Bb_dYECE.js +512 -0
- package/dist/hyperclawbot-CZ4DjvO-.js +516 -0
- package/dist/hyperclawbot-CgrV46DA.js +516 -0
- package/dist/inference-CFBkvLpE.js +2854 -0
- package/dist/inference-G4MbdErG.js +8 -0
- package/dist/knowledge-graph-9UNrsiIY.js +134 -0
- package/dist/loader-DIPs649t.js +410 -0
- package/dist/loader-Dq_cDlOW.js +6 -0
- package/dist/logger-CG38Idq4.js +86 -0
- package/dist/manager--wG9JdFW.js +120 -0
- package/dist/manager-BNc21xgG.js +6 -0
- package/dist/manager-DWJ7WZcY.js +250 -0
- package/dist/manager-DYfzqckn.js +35 -0
- package/dist/mcp-SsMEvl28.js +142 -0
- package/dist/mcp-loader-CVhiejBN.js +93 -0
- package/dist/mcp-loader-DLrp_oZJ.js +93 -0
- package/dist/memory-BCYvdqwo.js +273 -0
- package/dist/memory-BGgCBSx1.js +6 -0
- package/dist/memory-auto-Bh52cQJP.js +5 -0
- package/dist/memory-auto-BupvVwNd.js +306 -0
- package/dist/memory-integration-4oGqX6rr.js +91 -0
- package/dist/moltbook-B3DNdh40.js +81 -0
- package/dist/node-C4esBfbX.js +226 -0
- package/dist/nodes-registry-DLUZhEMS.js +52 -0
- package/dist/oauth-flow-BbLQTzZk.js +148 -0
- package/dist/oauth-provider-UZyG84s7.js +111 -0
- package/dist/observability-BtLyuxcz.js +89 -0
- package/dist/onboard-B3drurt-.js +3812 -0
- package/dist/onboard-CSJuvkMN.js +14 -0
- package/dist/onboard-DEwuHrMj.js +14 -0
- package/dist/onboard-eIxjVYKi.js +3812 -0
- package/dist/orchestrator-BXyIgAeH.js +189 -0
- package/dist/orchestrator-Cgj-8BbJ.js +189 -0
- package/dist/orchestrator-MLTc4NYu.js +6 -0
- package/dist/orchestrator-PLHfNTD6.js +6 -0
- package/dist/osint-Bsf6RGPv.js +283 -0
- package/dist/osint-CMyamX3_.js +283 -0
- package/dist/osint-chat-Ark94iFc.js +789 -0
- package/dist/osint-chat-D_6Fb27C.js +789 -0
- package/dist/pairing-2vAiDBjN.js +6 -0
- package/dist/pairing-B4NoBvyE.js +207 -0
- package/dist/pc-access-BLnc-DYp.js +858 -0
- package/dist/pc-access-CTNtG2LD.js +8 -0
- package/dist/pending-approval-C4ZaHHWl.js +22 -0
- package/dist/reminders-store-BixTWL1h.js +58 -0
- package/dist/renderer-B1ToXngl.js +228 -0
- package/dist/rules-Cqen1Mpt.js +106 -0
- package/dist/run-main.js +101 -95
- package/dist/runner-Cr1_mwnU.js +1274 -0
- package/dist/security-B4vH02lO.js +4 -0
- package/dist/security-HOOGCw5z.js +90 -0
- package/dist/server-B9rMYJwV.js +4 -0
- package/dist/server-CRhXiGI9.js +4 -0
- package/dist/server-DMC1wOsc.js +1365 -0
- package/dist/server-De4H45Ju.js +1365 -0
- package/dist/session-store-7sEPyV16.js +5 -0
- package/dist/session-store-Ce2QMSL_.js +141 -0
- package/dist/sessions-tools-CWr_pDtp.js +5 -0
- package/dist/sessions-tools-DKVu9aIN.js +95 -0
- package/dist/skill-loader-DK19Jm4e.js +7 -0
- package/dist/skill-loader-Dfs9VNM-.js +160 -0
- package/dist/skill-runtime-BeKh2rD_.js +5 -0
- package/dist/skill-runtime-CcpC2Zfc.js +104 -0
- package/dist/skill-runtime-CzsUymMA.js +104 -0
- package/dist/skill-runtime-DAP0Gs_7.js +5 -0
- package/dist/src-BxmkZ9RH.js +63 -0
- package/dist/src-CvJOtJlj.js +458 -0
- package/dist/src-DjTtmSRg.js +20 -0
- package/dist/src-cowbRb9x.js +63 -0
- package/dist/src-n_46LPDi.js +458 -0
- package/dist/sub-agent-tools-CIA8mqjv.js +39 -0
- package/dist/sub-agent-tools-q5JqEze_.js +39 -0
- package/dist/tool-policy-QXF3MMxu.js +189 -0
- package/dist/tts-elevenlabs-y6HGWWDS.js +64 -0
- package/dist/update-check-C4te7JmY.js +6 -0
- package/dist/update-check-GDue_it1.js +98 -0
- package/dist/vision-tools-CbVfyTZT.js +5 -0
- package/dist/vision-tools-DieVQp6s.js +51 -0
- package/dist/vision-u4kMThdo.js +167 -0
- package/dist/voice-transcription-DgON5qaF.js +170 -0
- package/dist/website-watch-tools-B8L_NgwT.js +5 -0
- package/dist/website-watch-tools-Drm5HjIX.js +176 -0
- package/package.json +1 -1
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
3
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
4
|
+
const path = require_chunk.__toESM(require("path"));
|
|
5
|
+
const os = require_chunk.__toESM(require("os"));
|
|
6
|
+
const events = require_chunk.__toESM(require("events"));
|
|
7
|
+
|
|
8
|
+
//#region extensions/whatsapp-baileys/src/connector.ts
|
|
9
|
+
const AUTH_DIR = path.default.join(os.default.homedir(), ".hyperclaw", "baileys-auth");
|
|
10
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "whatsapp-baileys-state.json");
|
|
11
|
+
var WhatsAppBaileysConnector = class extends events.EventEmitter {
|
|
12
|
+
config;
|
|
13
|
+
sock = null;
|
|
14
|
+
running = false;
|
|
15
|
+
qrCallback;
|
|
16
|
+
constructor(config = {}) {
|
|
17
|
+
super();
|
|
18
|
+
this.config = {
|
|
19
|
+
dmPolicy: "allowlist",
|
|
20
|
+
allowFrom: [],
|
|
21
|
+
approvedPairings: [],
|
|
22
|
+
pendingPairings: {},
|
|
23
|
+
...config
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
onQR(cb) {
|
|
27
|
+
this.qrCallback = cb;
|
|
28
|
+
}
|
|
29
|
+
async connect() {
|
|
30
|
+
try {
|
|
31
|
+
const makeWASocket$1 = require("@whiskeysockets/baileys");
|
|
32
|
+
const { useMultiFileAuthState: useMultiFileAuthState$1 } = require("@whiskeysockets/baileys");
|
|
33
|
+
} catch {
|
|
34
|
+
throw new Error("Baileys not installed. Run: npm install @whiskeysockets/baileys");
|
|
35
|
+
}
|
|
36
|
+
const makeWASocket = require("@whiskeysockets/baileys").default;
|
|
37
|
+
const { useMultiFileAuthState } = require("@whiskeysockets/baileys");
|
|
38
|
+
await fs_extra.default.ensureDir(AUTH_DIR);
|
|
39
|
+
const { state, saveCreds } = await useMultiFileAuthState(AUTH_DIR);
|
|
40
|
+
await this.loadState();
|
|
41
|
+
this.sock = makeWASocket({
|
|
42
|
+
auth: state,
|
|
43
|
+
printQRInTerminal: true,
|
|
44
|
+
generateHighQualityLinkPreview: false
|
|
45
|
+
});
|
|
46
|
+
this.sock.ev.on("creds.update", saveCreds);
|
|
47
|
+
this.sock.ev.on("connection.update", (upd) => {
|
|
48
|
+
if (upd.qr) this.qrCallback?.(upd.qr);
|
|
49
|
+
if (upd.connection === "open") {
|
|
50
|
+
console.log(chalk.default.green(" 🦅 WhatsApp Baileys: connected"));
|
|
51
|
+
this.emit("connected", {});
|
|
52
|
+
}
|
|
53
|
+
if (upd.connection === "close") this.emit("disconnected", upd);
|
|
54
|
+
});
|
|
55
|
+
this.sock.ev.on("messages.upsert", async ({ messages }) => {
|
|
56
|
+
for (const m of messages) {
|
|
57
|
+
if (m.key.fromMe) continue;
|
|
58
|
+
const msg = m.message;
|
|
59
|
+
if (!msg) continue;
|
|
60
|
+
let text = msg.conversation || msg.extendedTextMessage?.text || "";
|
|
61
|
+
const from = (m.key.remoteJid || "").replace(/@.*/, "");
|
|
62
|
+
if (msg.audioMessage || msg.pttMessage) {
|
|
63
|
+
let audioBuffer;
|
|
64
|
+
try {
|
|
65
|
+
const { downloadMediaMessage } = require("@whiskeysockets/baileys");
|
|
66
|
+
audioBuffer = await downloadMediaMessage(m, "buffer", {}, { reuploadRequest: this.sock?.updateMessageSent });
|
|
67
|
+
} catch {}
|
|
68
|
+
this.emit("message", {
|
|
69
|
+
id: m.key.id,
|
|
70
|
+
channelId: "whatsapp-baileys",
|
|
71
|
+
from,
|
|
72
|
+
chatId: m.key.remoteJid,
|
|
73
|
+
text: "[voice note]",
|
|
74
|
+
audioBuffer,
|
|
75
|
+
timestamp: new Date(parseInt(m.messageTimestamp || "0") * 1e3).toISOString(),
|
|
76
|
+
isDM: true
|
|
77
|
+
});
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (!text) continue;
|
|
81
|
+
const allowed = await this.checkDMPolicy(from, text);
|
|
82
|
+
if (!allowed) continue;
|
|
83
|
+
this.emit("message", {
|
|
84
|
+
id: m.key.id,
|
|
85
|
+
channelId: "whatsapp-baileys",
|
|
86
|
+
from,
|
|
87
|
+
chatId: m.key.remoteJid,
|
|
88
|
+
text,
|
|
89
|
+
timestamp: new Date(parseInt(m.messageTimestamp) * 1e3).toISOString(),
|
|
90
|
+
isDM: true
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
this.running = true;
|
|
95
|
+
}
|
|
96
|
+
async checkDMPolicy(from, text) {
|
|
97
|
+
if (this.config.dmPolicy === "none") return false;
|
|
98
|
+
if (this.config.dmPolicy === "open") return true;
|
|
99
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
100
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
101
|
+
await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.").catch(() => {});
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (this.config.dmPolicy === "pairing") {
|
|
105
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
106
|
+
const upper = text.trim().toUpperCase();
|
|
107
|
+
if (this.config.pendingPairings[upper]) {
|
|
108
|
+
this.config.approvedPairings.push(from);
|
|
109
|
+
delete this.config.pendingPairings[upper];
|
|
110
|
+
await this.saveState();
|
|
111
|
+
await this.sendMessage(from, "🦅 Paired!").catch(() => {});
|
|
112
|
+
this.emit("pairing:approved", {
|
|
113
|
+
userId: from,
|
|
114
|
+
channelId: "whatsapp-baileys"
|
|
115
|
+
});
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
119
|
+
this.config.pendingPairings[code] = from;
|
|
120
|
+
await this.saveState();
|
|
121
|
+
await this.sendMessage(from, `🦅 Code: ${code}\nApprove: hyperclaw pairing approve whatsapp-baileys ${code}`).catch(() => {});
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
async sendMessage(to, text) {
|
|
127
|
+
if (!this.sock) return;
|
|
128
|
+
const jid = to.includes("@") ? to : `${to}@s.whatsapp.net`;
|
|
129
|
+
await this.sock.sendMessage(jid, { text: text.slice(0, 4096) });
|
|
130
|
+
}
|
|
131
|
+
disconnect() {
|
|
132
|
+
this.running = false;
|
|
133
|
+
this.sock?.end?.();
|
|
134
|
+
this.sock = null;
|
|
135
|
+
}
|
|
136
|
+
approvePairing(code) {
|
|
137
|
+
const upper = code.toUpperCase();
|
|
138
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
139
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
140
|
+
delete this.config.pendingPairings[upper];
|
|
141
|
+
this.saveState();
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
async loadState() {
|
|
145
|
+
try {
|
|
146
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
147
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
148
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
149
|
+
} catch {}
|
|
150
|
+
}
|
|
151
|
+
async saveState() {
|
|
152
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
153
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
154
|
+
p: this.config.pendingPairings,
|
|
155
|
+
a: this.config.approvedPairings
|
|
156
|
+
}, { spaces: 2 });
|
|
157
|
+
}
|
|
158
|
+
isRunning() {
|
|
159
|
+
return this.running;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
exports.WhatsAppBaileysConnector = WhatsAppBaileysConnector;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
3
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
4
|
+
const path = require_chunk.__toESM(require("path"));
|
|
5
|
+
const os = require_chunk.__toESM(require("os"));
|
|
6
|
+
const https = require_chunk.__toESM(require("https"));
|
|
7
|
+
const events = require_chunk.__toESM(require("events"));
|
|
8
|
+
|
|
9
|
+
//#region extensions/zalo-personal/src/connector.ts
|
|
10
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "zalo-personal-state.json");
|
|
11
|
+
function zaloWebReq(cookie, method, endpoint, body) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
14
|
+
const req = https.default.request({
|
|
15
|
+
hostname: "chat.zalo.me",
|
|
16
|
+
port: 443,
|
|
17
|
+
path: `/api${endpoint}`,
|
|
18
|
+
method,
|
|
19
|
+
headers: {
|
|
20
|
+
"Cookie": cookie,
|
|
21
|
+
"Referer": "https://chat.zalo.me/",
|
|
22
|
+
"User-Agent": "Mozilla/5.0 (compatible; HyperClaw/4.0)",
|
|
23
|
+
...payload ? {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
26
|
+
} : {}
|
|
27
|
+
}
|
|
28
|
+
}, (res) => {
|
|
29
|
+
let data = "";
|
|
30
|
+
res.on("data", (c) => data += c);
|
|
31
|
+
res.on("end", () => {
|
|
32
|
+
try {
|
|
33
|
+
resolve(JSON.parse(data));
|
|
34
|
+
} catch {
|
|
35
|
+
resolve({ raw: data });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
req.on("error", reject);
|
|
40
|
+
if (payload) req.write(payload);
|
|
41
|
+
req.end();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
var ZaloPersonalConnector = class extends events.EventEmitter {
|
|
45
|
+
config;
|
|
46
|
+
running = false;
|
|
47
|
+
ws = null;
|
|
48
|
+
userId = "";
|
|
49
|
+
constructor(config) {
|
|
50
|
+
super();
|
|
51
|
+
this.config = {
|
|
52
|
+
imei: require("crypto").randomUUID(),
|
|
53
|
+
dmPolicy: "allowlist",
|
|
54
|
+
allowFrom: [],
|
|
55
|
+
approvedPairings: [],
|
|
56
|
+
pendingPairings: {},
|
|
57
|
+
...config
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async connect() {
|
|
61
|
+
const profile = await zaloWebReq(this.config.cookie, "GET", "/profile");
|
|
62
|
+
this.userId = profile?.data?.userId || profile?.userId || "";
|
|
63
|
+
await this.loadState();
|
|
64
|
+
this.running = true;
|
|
65
|
+
console.log(chalk.default.green(` 🦅 Zalo Personal: ${profile?.data?.displayName || this.userId} connected`));
|
|
66
|
+
this.emit("connected", { userId: this.userId });
|
|
67
|
+
this.startPolling();
|
|
68
|
+
}
|
|
69
|
+
async startPolling() {
|
|
70
|
+
while (this.running) try {
|
|
71
|
+
const msgs = await zaloWebReq(this.config.cookie, "GET", `/message/fetchlatestmsg?last_msg_id=0&limit=20`);
|
|
72
|
+
for (const msg of msgs?.data?.msgs || []) {
|
|
73
|
+
if (msg.fromUid === this.userId) continue;
|
|
74
|
+
if (!msg.msgId || !msg.content) continue;
|
|
75
|
+
const from = msg.fromUid;
|
|
76
|
+
const text = msg.content;
|
|
77
|
+
const allowed = await this.checkDMPolicy(from, text);
|
|
78
|
+
if (!allowed) continue;
|
|
79
|
+
this.emit("message", {
|
|
80
|
+
id: msg.msgId,
|
|
81
|
+
channelId: "zalo-personal",
|
|
82
|
+
from,
|
|
83
|
+
chatId: msg.toUid || from,
|
|
84
|
+
text,
|
|
85
|
+
timestamp: new Date(parseInt(msg.ts || "0")).toISOString(),
|
|
86
|
+
isDM: true
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
await new Promise((r) => setTimeout(r, 3e3));
|
|
90
|
+
} catch (e) {
|
|
91
|
+
if (this.running) {
|
|
92
|
+
console.log(chalk.default.yellow(` ⚠ Zalo Personal: ${e.message}`));
|
|
93
|
+
await new Promise((r) => setTimeout(r, 5e3));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async checkDMPolicy(from, text) {
|
|
98
|
+
if (this.config.dmPolicy === "none") return false;
|
|
99
|
+
if (this.config.dmPolicy === "open") return true;
|
|
100
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
101
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
102
|
+
await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.");
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (this.config.dmPolicy === "pairing") {
|
|
106
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
107
|
+
const upper = text.trim().toUpperCase();
|
|
108
|
+
if (this.config.pendingPairings[upper]) {
|
|
109
|
+
this.config.approvedPairings.push(from);
|
|
110
|
+
delete this.config.pendingPairings[upper];
|
|
111
|
+
await this.saveState();
|
|
112
|
+
await this.sendMessage(from, "🦅 Paired!");
|
|
113
|
+
this.emit("pairing:approved", {
|
|
114
|
+
userId: from,
|
|
115
|
+
channelId: "zalo-personal"
|
|
116
|
+
});
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
120
|
+
this.config.pendingPairings[code] = from;
|
|
121
|
+
await this.saveState();
|
|
122
|
+
await this.sendMessage(from, `🦅 Mã ghép đôi: ${code}\nXác nhận: hyperclaw pairing approve zalo-personal ${code}`);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
async sendMessage(toUid, text) {
|
|
128
|
+
await zaloWebReq(this.config.cookie, "POST", "/message/sendmsg", {
|
|
129
|
+
toid: toUid,
|
|
130
|
+
msg: text.slice(0, 2e3),
|
|
131
|
+
imei: this.config.imei,
|
|
132
|
+
type: 1
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
disconnect() {
|
|
136
|
+
this.running = false;
|
|
137
|
+
this.ws?.close();
|
|
138
|
+
}
|
|
139
|
+
approvePairing(code) {
|
|
140
|
+
const upper = code.toUpperCase();
|
|
141
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
142
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
143
|
+
delete this.config.pendingPairings[upper];
|
|
144
|
+
this.saveState();
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
async loadState() {
|
|
148
|
+
try {
|
|
149
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
150
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
151
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
152
|
+
} catch {}
|
|
153
|
+
}
|
|
154
|
+
async saveState() {
|
|
155
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
156
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
157
|
+
p: this.config.pendingPairings,
|
|
158
|
+
a: this.config.approvedPairings
|
|
159
|
+
}, { spaces: 2 });
|
|
160
|
+
}
|
|
161
|
+
isRunning() {
|
|
162
|
+
return this.running;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
//#endregion
|
|
167
|
+
exports.ZaloPersonalConnector = ZaloPersonalConnector;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
3
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
4
|
+
const path = require_chunk.__toESM(require("path"));
|
|
5
|
+
const os = require_chunk.__toESM(require("os"));
|
|
6
|
+
const crypto = require_chunk.__toESM(require("crypto"));
|
|
7
|
+
const https = require_chunk.__toESM(require("https"));
|
|
8
|
+
const events = require_chunk.__toESM(require("events"));
|
|
9
|
+
|
|
10
|
+
//#region extensions/twitter/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "twitter-state.json");
|
|
12
|
+
function oauthSign(method, url, config) {
|
|
13
|
+
const nonce = crypto.default.randomBytes(16).toString("hex");
|
|
14
|
+
const ts = Math.floor(Date.now() / 1e3).toString();
|
|
15
|
+
const op = {
|
|
16
|
+
oauth_consumer_key: config.apiKey,
|
|
17
|
+
oauth_nonce: nonce,
|
|
18
|
+
oauth_signature_method: "HMAC-SHA1",
|
|
19
|
+
oauth_timestamp: ts,
|
|
20
|
+
oauth_token: config.accessToken,
|
|
21
|
+
oauth_version: "1.0"
|
|
22
|
+
};
|
|
23
|
+
const sorted = Object.keys(op).sort().map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(op[k])}`).join("&");
|
|
24
|
+
const base = `${method}&${encodeURIComponent(url)}&${encodeURIComponent(sorted)}`;
|
|
25
|
+
const key = `${encodeURIComponent(config.apiSecret)}&${encodeURIComponent(config.accessTokenSecret)}`;
|
|
26
|
+
op.oauth_signature = crypto.default.createHmac("sha1", key).update(base).digest("base64");
|
|
27
|
+
return "OAuth " + Object.keys(op).sort().map((k) => `${encodeURIComponent(k)}="${encodeURIComponent(op[k])}"`).join(", ");
|
|
28
|
+
}
|
|
29
|
+
function xReq(method, url, body, auth) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
32
|
+
const u = new URL(url);
|
|
33
|
+
const req = https.default.request({
|
|
34
|
+
hostname: u.hostname,
|
|
35
|
+
path: u.pathname + u.search,
|
|
36
|
+
method,
|
|
37
|
+
headers: {
|
|
38
|
+
"Authorization": auth,
|
|
39
|
+
...payload ? {
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
42
|
+
} : {}
|
|
43
|
+
}
|
|
44
|
+
}, (res) => {
|
|
45
|
+
let data = "";
|
|
46
|
+
res.on("data", (c) => data += c);
|
|
47
|
+
res.on("end", () => {
|
|
48
|
+
try {
|
|
49
|
+
resolve(JSON.parse(data));
|
|
50
|
+
} catch {
|
|
51
|
+
resolve({ raw: data });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
req.on("error", reject);
|
|
56
|
+
if (payload) req.write(payload);
|
|
57
|
+
req.end();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
var TwitterConnector = class extends events.EventEmitter {
|
|
61
|
+
config;
|
|
62
|
+
running = false;
|
|
63
|
+
myUserId = "";
|
|
64
|
+
constructor(config) {
|
|
65
|
+
super();
|
|
66
|
+
this.config = {
|
|
67
|
+
dmPolicy: "allowlist",
|
|
68
|
+
allowFrom: [],
|
|
69
|
+
approvedPairings: [],
|
|
70
|
+
pendingPairings: {},
|
|
71
|
+
...config
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async connect() {
|
|
75
|
+
const url = "https://api.twitter.com/2/users/me";
|
|
76
|
+
const me = await xReq("GET", url, null, oauthSign("GET", url, this.config));
|
|
77
|
+
this.myUserId = me.data?.id || "";
|
|
78
|
+
await this.loadState();
|
|
79
|
+
this.running = true;
|
|
80
|
+
console.log(chalk.default.green(` 🦅 Twitter/X: @${me.data?.username} connected`));
|
|
81
|
+
this.emit("connected", {
|
|
82
|
+
userId: me.data?.id,
|
|
83
|
+
username: me.data?.username
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
disconnect() {
|
|
87
|
+
this.running = false;
|
|
88
|
+
}
|
|
89
|
+
handleCRC(crcToken) {
|
|
90
|
+
const hash = crypto.default.createHmac("sha256", this.config.apiSecret).update(crcToken).digest("base64");
|
|
91
|
+
return JSON.stringify({ response_token: `sha256=${hash}` });
|
|
92
|
+
}
|
|
93
|
+
async handleWebhook(body) {
|
|
94
|
+
let payload;
|
|
95
|
+
try {
|
|
96
|
+
payload = JSON.parse(body);
|
|
97
|
+
} catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
for (const event of payload.direct_message_events || []) {
|
|
101
|
+
if (event.type !== "message_create") continue;
|
|
102
|
+
const senderId = event.message_create?.sender_id;
|
|
103
|
+
if (senderId === this.myUserId) continue;
|
|
104
|
+
const text = event.message_create?.message_data?.text;
|
|
105
|
+
if (!text) continue;
|
|
106
|
+
const allowed = await this.checkDMPolicy(senderId, text);
|
|
107
|
+
if (!allowed) continue;
|
|
108
|
+
this.emit("message", {
|
|
109
|
+
id: event.id,
|
|
110
|
+
channelId: "twitter",
|
|
111
|
+
from: senderId,
|
|
112
|
+
chatId: senderId,
|
|
113
|
+
text,
|
|
114
|
+
timestamp: new Date(parseInt(event.created_timestamp)).toISOString(),
|
|
115
|
+
isDM: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async checkDMPolicy(from, text) {
|
|
120
|
+
if (this.config.dmPolicy === "none") return false;
|
|
121
|
+
if (this.config.dmPolicy === "open") return true;
|
|
122
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
123
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
124
|
+
await this.sendDM(from, "🦅 HyperClaw: Not on allowlist.");
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (this.config.dmPolicy === "pairing") {
|
|
128
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
129
|
+
const upper = text.trim().toUpperCase();
|
|
130
|
+
if (this.config.pendingPairings[upper]) {
|
|
131
|
+
this.config.approvedPairings.push(from);
|
|
132
|
+
delete this.config.pendingPairings[upper];
|
|
133
|
+
await this.saveState();
|
|
134
|
+
await this.sendDM(from, "🦅 Paired!");
|
|
135
|
+
this.emit("pairing:approved", {
|
|
136
|
+
userId: from,
|
|
137
|
+
channelId: "twitter"
|
|
138
|
+
});
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
142
|
+
this.config.pendingPairings[code] = from;
|
|
143
|
+
await this.saveState();
|
|
144
|
+
await this.sendDM(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve twitter ${code}`);
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
async sendDM(recipientId, text) {
|
|
150
|
+
const url = `https://api.twitter.com/2/dm_conversations/with/${recipientId}/messages`;
|
|
151
|
+
await xReq("POST", url, { text: text.slice(0, 1e4) }, oauthSign("POST", url, this.config));
|
|
152
|
+
}
|
|
153
|
+
approvePairing(code) {
|
|
154
|
+
const upper = code.toUpperCase();
|
|
155
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
156
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
157
|
+
delete this.config.pendingPairings[upper];
|
|
158
|
+
this.saveState();
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
async loadState() {
|
|
162
|
+
try {
|
|
163
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
164
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
165
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
166
|
+
} catch {}
|
|
167
|
+
}
|
|
168
|
+
async saveState() {
|
|
169
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
170
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
171
|
+
p: this.config.pendingPairings,
|
|
172
|
+
a: this.config.approvedPairings
|
|
173
|
+
}, { spaces: 2 });
|
|
174
|
+
}
|
|
175
|
+
isRunning() {
|
|
176
|
+
return this.running;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
exports.TwitterConnector = TwitterConnector;
|