hyperclaw 4.0.1 → 5.0.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/README.md +58 -4
- package/dist/a2ui-protocol-CT_jDEU9.js +75 -0
- package/dist/a2ui-protocol-CfBI44-Q.js +75 -0
- package/dist/agents-routing-683Q2JGp.js +129 -0
- package/dist/agents-routing-BpZBswBH.js +4 -0
- package/dist/agents-routing-ChHiZp36.js +327 -0
- package/dist/agents-routing-ChqZ6l2S.js +4 -0
- package/dist/api-keys-guide-BCcOl0Q7.js +149 -0
- package/dist/api-keys-guide-Dq5Obbp4.js +149 -0
- package/dist/audit-BYxPlnTQ.js +248 -0
- package/dist/audit-BaIiyWFu.js +441 -0
- package/dist/bounty-tools-C6LyzxM-.js +211 -0
- package/dist/bounty-tools-DWudyZie.js +211 -0
- package/dist/browser-tools-BsTeGMnX.js +5 -0
- package/dist/browser-tools-CQBSbIuO.js +5 -0
- package/dist/browser-tools-D8_rLe2p.js +179 -0
- package/dist/browser-tools-YQmwRLLM.js +179 -0
- package/dist/claw-tasks-BRLUvFRD.js +80 -0
- package/dist/claw-tasks-CgTsiNE8.js +80 -0
- package/dist/connector-3HnyH8fn.js +167 -0
- package/dist/connector-5N0-X_xs.js +194 -0
- package/dist/connector-6PMZo5Ky.js +189 -0
- package/dist/connector-B3v0qcXg.js +425 -0
- package/dist/connector-B6eoF3DD.js +181 -0
- package/dist/connector-B8R3iBY1.js +280 -0
- package/dist/connector-B9tLG8UZ.js +196 -0
- package/dist/connector-BAM-08NN.js +189 -0
- package/dist/connector-BC8FIVu4.js +181 -0
- package/dist/connector-BDmwwaVc.js +213 -0
- package/dist/connector-BGjbBy69.js +225 -0
- package/dist/connector-BO2SRzfG.js +218 -0
- package/dist/connector-BOlqjXWP.js +182 -0
- package/dist/connector-BP8zsbP8.js +189 -0
- package/dist/connector-BPoSevxp.js +286 -0
- package/dist/connector-BRHj773i.js +163 -0
- package/dist/connector-BToxU-jV.js +267 -0
- package/dist/connector-BfXky0L3.js +167 -0
- package/dist/connector-BiiSJpx3.js +192 -0
- package/dist/connector-BliDVsJQ.js +239 -0
- package/dist/connector-BnDmIhIu.js +85 -0
- package/dist/connector-Bv6s9oP7.js +88 -0
- package/dist/connector-By5wWGTR.js +343 -0
- package/dist/connector-C1BaFFgN.js +213 -0
- package/dist/connector-C1HSoUyk.js +189 -0
- package/dist/connector-CKQHZOXg.js +568 -0
- package/dist/connector-CRRWY5Wv.js +167 -0
- package/dist/connector-CRl-iidy.js +239 -0
- package/dist/connector-CXPQVGyI.js +85 -0
- package/dist/connector-Cdk1CXKi.js +194 -0
- package/dist/connector-Ci9glMD-.js +340 -0
- package/dist/connector-CjtZIEDj.js +181 -0
- package/dist/connector-Ck6JtOsX.js +531 -0
- package/dist/connector-CwlgFgjx.js +181 -0
- package/dist/connector-D8Kelee0.js +286 -0
- package/dist/connector-DAnRJ0oP.js +162 -0
- package/dist/connector-DFchk6l7.js +178 -0
- package/dist/connector-DKw7tRAy.js +192 -0
- package/dist/connector-DRv1ahC_.js +2 -2
- package/dist/connector-DU63KW94.js +165 -0
- package/dist/connector-DXTp5PE8.js +508 -0
- package/dist/connector-Dbvb1Cj9.js +280 -0
- package/dist/connector-DcZdQcgR.js +173 -0
- package/dist/connector-Dih6dUPP.js +173 -0
- package/dist/connector-DqTH_tPX.js +182 -0
- package/dist/connector-DrnEiiyP.js +419 -0
- package/dist/connector-DtR5GGTX.js +167 -0
- package/dist/connector-DxKL8VvZ.js +182 -0
- package/dist/connector-T_YdZtzv.js +162 -0
- package/dist/connector-Tky_qS_K.js +350 -0
- package/dist/connector-ZSc3oTTy.js +305 -0
- package/dist/connector-i4gOS9xL.js +154 -0
- package/dist/connector-rHXE1ZD2.js +167 -0
- package/dist/connector-sW5yhU1m.js +498 -0
- package/dist/connector-u3ICd3Ic.js +552 -0
- package/dist/connector-wdUXChwa.js +172 -0
- package/dist/cost-tracker-DD9wtWsr.js +103 -0
- package/dist/cost-tracker-pVE15Yq4.js +103 -0
- package/dist/credentials-store-BvnMPJwi.js +4 -0
- package/dist/credentials-store-C6ir0Dae.js +4 -0
- package/dist/credentials-store-H13LqOwJ.js +77 -0
- package/dist/credentials-store-sb-TRLwR.js +77 -0
- package/dist/cron-tasks-Bli7Kzd2.js +82 -0
- package/dist/cron-tasks-BvDFNyiE.js +82 -0
- package/dist/daemon-Bg4GtCmc.js +318 -0
- package/dist/daemon-DhmwY8k4.js +5 -0
- package/dist/delivery-BmIYy9VQ.js +4 -0
- package/dist/delivery-D5Z98EVq.js +95 -0
- package/dist/delivery-DCOXhXEO.js +5 -0
- package/dist/delivery-pWUPBp1F.js +95 -0
- package/dist/destructive-gate-D6vWOdEl.js +101 -0
- package/dist/destructive-gate-m-dWqUFg.js +101 -0
- package/dist/developer-keys-CPWT7Q6S.js +8 -0
- package/dist/developer-keys-DrrcUqFa.js +127 -0
- package/dist/developer-keys-JaJK3T27.js +127 -0
- package/dist/developer-keys-kyqmtWK3.js +8 -0
- package/dist/doctor-3oi89QIc.js +175 -0
- package/dist/doctor-BvCe8BBk.js +230 -0
- package/dist/doctor-Cf1XSfp9.js +4 -0
- package/dist/doctor-CxyPLYsJ.js +6 -0
- package/dist/engine-B4eMiTgl.js +7 -0
- package/dist/engine-B8M7dYul.js +7 -0
- package/dist/engine-BhT-1M9W.js +256 -0
- package/dist/engine-CEDSqXfw.js +256 -0
- package/dist/engine-D49jnSd_.js +256 -0
- package/dist/engine-Da4JMNpI.js +7 -0
- package/dist/env-resolve-CiXbWYwe.js +10 -0
- package/dist/env-resolve-CmGWhWXJ.js +115 -0
- package/dist/env-resolve-DWOQ45jG.js +9 -0
- package/dist/env-resolve-szSWl0UF.js +94 -0
- package/dist/extraction-tools-D3qDFBJ1.js +91 -0
- package/dist/extraction-tools-DLr_AEwq.js +5 -0
- package/dist/extraction-tools-HOZstZ0y.js +91 -0
- package/dist/extraction-tools-m4lmAv7l.js +5 -0
- package/dist/form_data-B_hIUrxU.js +8657 -0
- package/dist/form_data-Cz040rio.js +8657 -0
- package/dist/gmail-watch-setup-Czt8rXaX.js +40 -0
- package/dist/gmail-watch-setup-Du7DVV7S.js +40 -0
- package/dist/health-B-asI__D.js +6 -0
- package/dist/health-Ds2YlpTB.js +152 -0
- package/dist/heartbeat-engine-BYT5ayQH.js +83 -0
- package/dist/heartbeat-engine-CRqfPcFM.js +83 -0
- package/dist/hub-D0XwdjM-.js +515 -0
- package/dist/hub-DTsqe5Bt.js +6 -0
- package/dist/hub-FrPTA33j.js +515 -0
- package/dist/hub-LiD5Iztb.js +6 -0
- package/dist/hyperclawbot-D9KCtc4P.js +480 -0
- package/dist/hyperclawbot-Dw27pJo4.js +480 -0
- package/dist/hyperclawbot-zvczQgKx.js +505 -0
- package/dist/inference-BKVkBREb.js +6 -0
- package/dist/inference-CTWJeX9Q.js +922 -0
- package/dist/inference-DCXH4Q3x.js +922 -0
- package/dist/inference-ix607p7k.js +6 -0
- package/dist/knowledge-graph-DqA-Fztl.js +131 -0
- package/dist/knowledge-graph-iBG76fvm.js +131 -0
- package/dist/loader-CC45xGpC.js +4 -0
- package/dist/loader-CISCqBto.js +400 -0
- package/dist/loader-CYMQ8VOS.js +4 -0
- package/dist/loader-CnEdOyjT.js +400 -0
- package/dist/logger-8tEtAd3y.js +83 -0
- package/dist/logger-ybOp7VOC.js +83 -0
- package/dist/manager-03ipO9R0.js +105 -0
- package/dist/manager-BpDfbDjg.js +117 -0
- package/dist/manager-Bxl0sqlh.js +4 -0
- package/dist/manager-CPjeRe-6.js +4 -0
- package/dist/manager-CrVDn6eN.js +6 -0
- package/dist/manager-Cwzj7w5R.js +105 -0
- package/dist/manager-DLmZI-9R.js +6 -0
- package/dist/manager-DSGhn5i3.js +117 -0
- package/dist/manager-DgyF52mg.js +218 -0
- package/dist/manager-Dm8nrMFx.js +40 -0
- package/dist/manager-FCgF1plu.js +218 -0
- package/dist/manager-rgCsaWT1.js +40 -0
- package/dist/mcp-B_9Ber63.js +139 -0
- package/dist/mcp-CfoSU4Uz.js +139 -0
- package/dist/mcp-loader-DSM5UiFG.js +94 -0
- package/dist/mcp-loader-DkRBsLpk.js +94 -0
- package/dist/mcp-loader-j5ZLLw5O.js +94 -0
- package/dist/memory-BI1kPkAN.js +4 -0
- package/dist/memory-BVFGkxxK.js +270 -0
- package/dist/memory-BlHL7JCO.js +4 -0
- package/dist/memory-DsS_eFvJ.js +270 -0
- package/dist/memory-auto-Bc7euou4.js +306 -0
- package/dist/memory-auto-BkvtSFUw.js +5 -0
- package/dist/memory-auto-Bnz_-1wP.js +306 -0
- package/dist/memory-auto-DPfbkMVt.js +5 -0
- package/dist/memory-integration-DZExqWr4.js +91 -0
- package/dist/memory-integration-cSYkZyEo.js +91 -0
- package/dist/moltbook-B6ZeGN5_.js +81 -0
- package/dist/moltbook-BtLDZTfM.js +81 -0
- package/dist/node-Dw2Gi-cP.js +222 -0
- package/dist/node-pwL6O_KX.js +222 -0
- package/dist/nodes-registry-B8dmrlLv.js +52 -0
- package/dist/nodes-registry-CsPm_-CJ.js +52 -0
- package/dist/oauth-flow-CpWlgvNB.js +150 -0
- package/dist/oauth-flow-DQPvMHRH.js +150 -0
- package/dist/oauth-provider-BZb6qOw5.js +110 -0
- package/dist/oauth-provider-Uo4Nib_c.js +110 -0
- package/dist/observability-B43YvNQV.js +89 -0
- package/dist/observability-BV-Yx0V9.js +89 -0
- package/dist/onboard-0WoDxbv_.js +10 -0
- package/dist/onboard-BXNXCQp4.js +4070 -0
- package/dist/onboard-Bd_wsYdi.js +4086 -0
- package/dist/onboard-CAN7x3me.js +3026 -0
- package/dist/onboard-DnegOHMh.js +4 -4
- package/dist/onboard-RYtDlYBw.js +9 -0
- package/dist/onboard-aTwlQs-4.js +9 -0
- package/dist/orchestrator-BSp2M5EU.js +189 -0
- package/dist/orchestrator-C7ko5tWa.js +6 -0
- package/dist/orchestrator-DfPkIx2Z.js +6 -0
- package/dist/orchestrator-DmnEvMaL.js +189 -0
- package/dist/orchestrator-NJQsmiBE.js +189 -0
- package/dist/orchestrator-RI3bpqqc.js +6 -0
- package/dist/pairing-6iM27aD8.js +196 -0
- package/dist/pairing-DU0_J28n.js +87 -0
- package/dist/pairing-DWllbSbO.js +4 -0
- package/dist/pairing-dGoiGepK.js +4 -0
- package/dist/pc-access-CgCsYrpt.js +8 -0
- package/dist/pc-access-Ly-uA8mn.js +8 -0
- package/dist/pc-access-NxBvTrRj.js +819 -0
- package/dist/pc-access-_iH2aorG.js +819 -0
- package/dist/pending-approval-CUXjysAo.js +22 -0
- package/dist/pending-approval-DIHvwwWS.js +22 -0
- package/dist/puppeteer-2o3QOwAy.js +2 -2
- package/dist/puppeteer-BYTMp3BI.js +2 -2
- package/dist/puppeteer-DQ45qwWk.js +2 -2
- package/dist/reminders-store-D79qdfN0.js +58 -0
- package/dist/reminders-store-Drjed_-h.js +58 -0
- package/dist/renderer-BVQrd0_g.js +225 -0
- package/dist/renderer-pqlDRKbH.js +225 -0
- package/dist/rules-BE4GV6cV.js +103 -0
- package/dist/rules-BooT_qFP.js +103 -0
- package/dist/run-main.js +1649 -1227
- package/dist/runner-D1rjuMTJ.js +810 -0
- package/dist/runner-DatMMYYE.js +1271 -0
- package/dist/sdk/index.js +2 -2
- package/dist/sdk/index.mjs +2 -2
- package/dist/security-BqNyT4ID.js +4 -0
- package/dist/security-C-5URby1.js +73 -0
- package/dist/security-_xve79aq.js +4 -0
- package/dist/security-tpgqPWWH.js +73 -0
- package/dist/server-0kgyELx4.js +1047 -0
- package/dist/server-BIuTobTC.js +4 -0
- package/dist/server-BRlCEjyT.js +1047 -0
- package/dist/server-CCI1hv45.js +2 -2
- package/dist/server-D4wVHiX9.js +4 -0
- package/dist/server-DU9POoWc.js +4 -0
- package/dist/server-Dh3JlBFB.js +1255 -0
- package/dist/session-store-BUiPz0Vv.js +5 -0
- package/dist/session-store-CujxByI6.js +113 -0
- package/dist/session-store-is4B6qmD.js +113 -0
- package/dist/session-store-qpJUg2M1.js +5 -0
- package/dist/sessions-tools-CB2qbwIk.js +5 -0
- package/dist/sessions-tools-CbUTFe4i.js +5 -0
- package/dist/sessions-tools-CeqD7iil.js +95 -0
- package/dist/sessions-tools-DHMaTZIs.js +95 -0
- package/dist/skill-loader-BaNLVmJy.js +7 -0
- package/dist/skill-loader-BkceKkIg.js +7 -0
- package/dist/skill-loader-DhgIwK4J.js +159 -0
- package/dist/skill-loader-HgpF6Vqs.js +159 -0
- package/dist/skill-runtime--LqxWrp5.js +102 -0
- package/dist/skill-runtime-C5l0Tgt-.js +5 -0
- package/dist/skill-runtime-CJN24QPW.js +102 -0
- package/dist/skill-runtime-DsXK_HYG.js +102 -0
- package/dist/skill-runtime-IVTiqrMR.js +5 -0
- package/dist/skill-runtime-w1ig_lcw.js +5 -0
- package/dist/src-BEVLgaF1.js +63 -0
- package/dist/src-Bgu_OxTQ.js +458 -0
- package/dist/src-Bq-oKt7Z.js +458 -0
- package/dist/src-BxPHKO5x.js +63 -0
- package/dist/src-DIc-L2IG.js +20 -0
- package/dist/src-DWCUhnD4.js +20 -0
- package/dist/src-cfRTjFef.js +63 -0
- package/dist/src-g_rNx5rh.js +458 -0
- package/dist/sub-agent-tools-BD9DF8_g.js +39 -0
- package/dist/sub-agent-tools-CHQoHz9c.js +39 -0
- package/dist/sub-agent-tools-V7b3T9_s.js +39 -0
- package/dist/theme-DcxwcUgZ.js +180 -0
- package/dist/theme-cx0fkgWC.js +8 -0
- package/dist/tool-policy-CNT-mF2Z.js +189 -0
- package/dist/tool-policy-DNvNRnve.js +189 -0
- package/dist/tts-elevenlabs-BRosZv-f.js +61 -0
- package/dist/tts-elevenlabs-BUOGKL-k.js +61 -0
- package/dist/update-check-BD4qH7Am.js +81 -0
- package/dist/update-check-C2Dz85wJ.js +81 -0
- package/dist/vision-BMmiIKy7.js +121 -0
- package/dist/vision-DRq-f-Dj.js +121 -0
- package/dist/vision-tools-CFZEpQKm.js +5 -0
- package/dist/vision-tools-CQnBI9aa.js +51 -0
- package/dist/vision-tools-DVuYc17I.js +51 -0
- package/dist/vision-tools-U3YC4L-g.js +5 -0
- package/dist/voice-transcription-B555DbWR.js +138 -0
- package/dist/voice-transcription-CgWq54hn.js +138 -0
- package/dist/website-watch-tools-Bk_TnwuE.js +5 -0
- package/dist/website-watch-tools-DFMrJU-R.js +139 -0
- package/dist/website-watch-tools-DraMPxdl.js +139 -0
- package/dist/website-watch-tools-Du3W5sN7.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const fs_extra = require_chunk.__toESM(require("fs-extra"));
|
|
3
|
+
const path = require_chunk.__toESM(require("path"));
|
|
4
|
+
const os = require_chunk.__toESM(require("os"));
|
|
5
|
+
const child_process = require_chunk.__toESM(require("child_process"));
|
|
6
|
+
const events = require_chunk.__toESM(require("events"));
|
|
7
|
+
|
|
8
|
+
//#region extensions/imessage-native/src/connector.ts
|
|
9
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "imessage-native-state.json");
|
|
10
|
+
const PAIRING_TTL_MS = 60 * 60 * 1e3;
|
|
11
|
+
var IMessageNativeConnector = class extends events.EventEmitter {
|
|
12
|
+
config;
|
|
13
|
+
rpcProc = null;
|
|
14
|
+
running = false;
|
|
15
|
+
lastMessageTs = 0;
|
|
16
|
+
rpcSeq = 1;
|
|
17
|
+
pending = /* @__PURE__ */ new Map();
|
|
18
|
+
buf = "";
|
|
19
|
+
constructor(config = {}) {
|
|
20
|
+
super();
|
|
21
|
+
this.config = {
|
|
22
|
+
cliPath: config.cliPath || process.env.IMSG_PATH || "imsg",
|
|
23
|
+
dbPath: config.dbPath || path.default.join(os.default.homedir(), "Library", "Messages", "chat.db"),
|
|
24
|
+
dmPolicy: config.dmPolicy ?? "pairing",
|
|
25
|
+
allowFrom: config.allowFrom ?? [],
|
|
26
|
+
approvedPairings: config.approvedPairings ?? [],
|
|
27
|
+
pendingPairings: config.pendingPairings ?? {},
|
|
28
|
+
pendingPairingTs: config.pendingPairingTs ?? {}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async connect() {
|
|
32
|
+
if (process.platform !== "darwin") throw new Error("imessage-native is macOS only. For new deployments use BlueBubbles.");
|
|
33
|
+
await this.loadState();
|
|
34
|
+
this.running = true;
|
|
35
|
+
this.emit("connected", {});
|
|
36
|
+
this.startRpc();
|
|
37
|
+
}
|
|
38
|
+
startRpc() {
|
|
39
|
+
if (!this.running) return;
|
|
40
|
+
const bin = this.config.cliPath;
|
|
41
|
+
const args = ["rpc"];
|
|
42
|
+
if (this.config.dbPath) args.push("--db", this.config.dbPath);
|
|
43
|
+
this.rpcProc = (0, child_process.spawn)(bin, args, { stdio: [
|
|
44
|
+
"pipe",
|
|
45
|
+
"pipe",
|
|
46
|
+
"pipe"
|
|
47
|
+
] });
|
|
48
|
+
this.rpcProc.stdout?.on("data", (chunk) => {
|
|
49
|
+
this.buf += chunk.toString();
|
|
50
|
+
const lines = this.buf.split("\n");
|
|
51
|
+
this.buf = lines.pop() || "";
|
|
52
|
+
for (const line of lines) {
|
|
53
|
+
if (!line.trim()) continue;
|
|
54
|
+
try {
|
|
55
|
+
this.handleRpcLine(JSON.parse(line));
|
|
56
|
+
} catch {}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
this.rpcProc.stderr?.on("data", () => {});
|
|
60
|
+
this.rpcProc.on("error", () => {});
|
|
61
|
+
this.rpcProc.on("exit", (code) => {
|
|
62
|
+
this.rpcProc = null;
|
|
63
|
+
this.buf = "";
|
|
64
|
+
for (const [, cb] of this.pending) cb.reject(new Error("imsg rpc exited"));
|
|
65
|
+
this.pending.clear();
|
|
66
|
+
if (this.running && code !== 0) setTimeout(() => this.startRpc(), 5e3);
|
|
67
|
+
});
|
|
68
|
+
this.rpcSend("messages.watch", {}).catch(() => {});
|
|
69
|
+
}
|
|
70
|
+
handleRpcLine(msg) {
|
|
71
|
+
if (!msg.id && msg.method === "message" && msg.params) {
|
|
72
|
+
this.onIncomingMessage(msg.params);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (msg.id != null) {
|
|
76
|
+
const cb = this.pending.get(msg.id);
|
|
77
|
+
if (!cb) return;
|
|
78
|
+
this.pending.delete(msg.id);
|
|
79
|
+
if (msg.error) cb.reject(new Error(msg.error.message));
|
|
80
|
+
else cb.resolve(msg.result);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
onIncomingMessage(params) {
|
|
84
|
+
if (params.isFromMe) return;
|
|
85
|
+
const handle = params.handle?.address || params.sender || params.chatId || params.from;
|
|
86
|
+
const text = params.text || params.body || params.message;
|
|
87
|
+
if (!handle || !text) return;
|
|
88
|
+
const ts = params.dateCreated || params.timestamp || Date.now();
|
|
89
|
+
if (ts <= this.lastMessageTs) return;
|
|
90
|
+
this.lastMessageTs = ts;
|
|
91
|
+
this.saveState();
|
|
92
|
+
this.checkDMPolicyAndEmit(handle, text);
|
|
93
|
+
}
|
|
94
|
+
pruneExpiredCodes() {
|
|
95
|
+
const now = Date.now();
|
|
96
|
+
const ts = this.config.pendingPairingTs;
|
|
97
|
+
for (const code of Object.keys(ts)) if (now - ts[code] > PAIRING_TTL_MS) {
|
|
98
|
+
delete this.config.pendingPairings[code];
|
|
99
|
+
delete ts[code];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async checkDMPolicyAndEmit(from, text) {
|
|
103
|
+
if (this.config.dmPolicy === "disabled") return;
|
|
104
|
+
if (this.config.dmPolicy === "open") {
|
|
105
|
+
this.emit("message", {
|
|
106
|
+
chatId: from,
|
|
107
|
+
text
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
112
|
+
if (this.config.allowFrom.includes(from)) this.emit("message", {
|
|
113
|
+
chatId: from,
|
|
114
|
+
text
|
|
115
|
+
});
|
|
116
|
+
else await this.sendMessage(from, "HyperClaw: Not on allowlist.");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.pruneExpiredCodes();
|
|
120
|
+
if (this.config.approvedPairings.includes(from)) {
|
|
121
|
+
this.emit("message", {
|
|
122
|
+
chatId: from,
|
|
123
|
+
text
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const code = (text.trim().toUpperCase().match(/[A-Z0-9]{6}/) || [])[0];
|
|
128
|
+
if (code && this.config.pendingPairings[code]) {
|
|
129
|
+
this.config.approvedPairings.push(from);
|
|
130
|
+
delete this.config.pendingPairings[code];
|
|
131
|
+
delete this.config.pendingPairingTs[code];
|
|
132
|
+
await this.saveState();
|
|
133
|
+
await this.sendMessage(from, "Paired!");
|
|
134
|
+
this.emit("pairing:approved", {
|
|
135
|
+
userId: from,
|
|
136
|
+
channelId: "imessage-native"
|
|
137
|
+
});
|
|
138
|
+
this.emit("message", {
|
|
139
|
+
chatId: from,
|
|
140
|
+
text
|
|
141
|
+
});
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const newCode = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
145
|
+
this.config.pendingPairings[newCode] = from;
|
|
146
|
+
this.config.pendingPairingTs[newCode] = Date.now();
|
|
147
|
+
await this.saveState();
|
|
148
|
+
await this.sendMessage(from, `Pairing code: ${newCode}\nApprove: hyperclaw pairing approve imessage-native ${newCode}\n(expires in 1 hour)`);
|
|
149
|
+
}
|
|
150
|
+
async sendMessage(chatId, text) {
|
|
151
|
+
const to = String(chatId).trim();
|
|
152
|
+
if (!to) return;
|
|
153
|
+
if (!this.rpcProc) throw new Error("imsg rpc not running");
|
|
154
|
+
await this.rpcSend("messages.send", {
|
|
155
|
+
to,
|
|
156
|
+
text
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
rpcSend(method, params) {
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
if (!this.rpcProc?.stdin) {
|
|
162
|
+
reject(new Error("imsg rpc stdin unavailable"));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const id = this.rpcSeq++;
|
|
166
|
+
const req = {
|
|
167
|
+
jsonrpc: "2.0",
|
|
168
|
+
id,
|
|
169
|
+
method,
|
|
170
|
+
params
|
|
171
|
+
};
|
|
172
|
+
this.pending.set(id, {
|
|
173
|
+
resolve,
|
|
174
|
+
reject
|
|
175
|
+
});
|
|
176
|
+
this.rpcProc.stdin.write(JSON.stringify(req) + "\n");
|
|
177
|
+
const timer = setTimeout(() => {
|
|
178
|
+
if (this.pending.has(id)) {
|
|
179
|
+
this.pending.delete(id);
|
|
180
|
+
reject(new Error(`imsg rpc timeout for method ${method}`));
|
|
181
|
+
}
|
|
182
|
+
}, 15e3);
|
|
183
|
+
const orig = this.pending.get(id);
|
|
184
|
+
this.pending.set(id, {
|
|
185
|
+
resolve: (v) => {
|
|
186
|
+
clearTimeout(timer);
|
|
187
|
+
orig.resolve(v);
|
|
188
|
+
},
|
|
189
|
+
reject: (e) => {
|
|
190
|
+
clearTimeout(timer);
|
|
191
|
+
orig.reject(e);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
disconnect() {
|
|
197
|
+
this.running = false;
|
|
198
|
+
this.rpcProc?.kill();
|
|
199
|
+
this.rpcProc = null;
|
|
200
|
+
this.buf = "";
|
|
201
|
+
for (const [, cb] of this.pending) cb.reject(new Error("disconnected"));
|
|
202
|
+
this.pending.clear();
|
|
203
|
+
}
|
|
204
|
+
async loadState() {
|
|
205
|
+
try {
|
|
206
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
207
|
+
this.lastMessageTs = s.lastTs || 0;
|
|
208
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
209
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
210
|
+
if (s.pts) this.config.pendingPairingTs = s.pts;
|
|
211
|
+
} catch {}
|
|
212
|
+
}
|
|
213
|
+
async saveState() {
|
|
214
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
215
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
216
|
+
lastTs: this.lastMessageTs,
|
|
217
|
+
p: this.config.pendingPairings,
|
|
218
|
+
a: this.config.approvedPairings,
|
|
219
|
+
pts: this.config.pendingPairingTs
|
|
220
|
+
}, { spaces: 2 });
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
//#endregion
|
|
225
|
+
exports.IMessageNativeConnector = IMessageNativeConnector;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-jS-bbMI5.js');
|
|
2
|
+
const chalk = require_chunk.__toESM(require("chalk"));
|
|
3
|
+
const events = require_chunk.__toESM(require("events"));
|
|
4
|
+
const irc = require_chunk.__toESM(require("irc"));
|
|
5
|
+
|
|
6
|
+
//#region extensions/irc/src/connector.ts
|
|
7
|
+
function resolveEnvConfig(cfg) {
|
|
8
|
+
return {
|
|
9
|
+
server: cfg.server || process.env["IRC_HOST"] || "",
|
|
10
|
+
port: cfg.port ?? (process.env["IRC_PORT"] ? parseInt(process.env["IRC_PORT"], 10) : void 0),
|
|
11
|
+
tls: cfg.tls ?? (process.env["IRC_TLS"] === "true" || process.env["IRC_TLS"] === "1"),
|
|
12
|
+
nick: cfg.nick || process.env["IRC_NICK"] || "hyperclaw-bot",
|
|
13
|
+
username: cfg.username || process.env["IRC_USERNAME"],
|
|
14
|
+
realname: cfg.realname || process.env["IRC_REALNAME"],
|
|
15
|
+
password: cfg.password || process.env["IRC_PASSWORD"],
|
|
16
|
+
channels: cfg.channels?.length ? cfg.channels : process.env["IRC_CHANNELS"]?.split(",").map((c) => c.trim()).filter(Boolean) ?? [],
|
|
17
|
+
nickserv: cfg.nickserv ?? (process.env["IRC_NICKSERV_PASSWORD"] ? {
|
|
18
|
+
enabled: true,
|
|
19
|
+
service: "NickServ",
|
|
20
|
+
password: process.env["IRC_NICKSERV_PASSWORD"],
|
|
21
|
+
registerEmail: process.env["IRC_NICKSERV_REGISTER_EMAIL"]
|
|
22
|
+
} : void 0),
|
|
23
|
+
dmPolicy: cfg.dmPolicy ?? "pairing",
|
|
24
|
+
allowFrom: cfg.allowFrom ?? [],
|
|
25
|
+
groupPolicy: cfg.groupPolicy ?? "allowlist",
|
|
26
|
+
groupAllowFrom: cfg.groupAllowFrom ?? [],
|
|
27
|
+
groups: cfg.groups ?? {},
|
|
28
|
+
dangerouslyAllowNameMatching: cfg.dangerouslyAllowNameMatching ?? false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Match a sender (nick!user@host or bare nick) against an allowFrom entry. */
|
|
32
|
+
function matchSender(sender, pattern, allowBareNick) {
|
|
33
|
+
if (pattern === "*") return true;
|
|
34
|
+
if (pattern.startsWith("id:")) {
|
|
35
|
+
const id = pattern.slice(3);
|
|
36
|
+
return sender === id || sender.startsWith(id + "!");
|
|
37
|
+
}
|
|
38
|
+
if (pattern === sender) return true;
|
|
39
|
+
if (allowBareNick) {
|
|
40
|
+
const nick = sender.split("!")[0];
|
|
41
|
+
return nick === pattern;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
function senderAllowed(sender, allowList, allowBareNick) {
|
|
46
|
+
if (!allowList.length) return false;
|
|
47
|
+
return allowList.some((p) => matchSender(sender, p, allowBareNick));
|
|
48
|
+
}
|
|
49
|
+
/** Return the first matching ToolsBySender policy for a sender. */
|
|
50
|
+
function resolveToolsBySender(sender, toolsBySender, allowBareNick) {
|
|
51
|
+
for (const [pattern, policy] of Object.entries(toolsBySender)) {
|
|
52
|
+
const pat = pattern.startsWith("id:") ? pattern : `id:${pattern}`;
|
|
53
|
+
if (matchSender(sender, pat === "id:*" ? "*" : pat, allowBareNick)) return policy;
|
|
54
|
+
}
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
/** Resolve effective tool policy for a sender in a channel. */
|
|
58
|
+
function resolveToolPolicy(sender, channelCfg, allowBareNick) {
|
|
59
|
+
if (!channelCfg) return void 0;
|
|
60
|
+
if (channelCfg.toolsBySender) {
|
|
61
|
+
const byS = resolveToolsBySender(sender, channelCfg.toolsBySender, allowBareNick);
|
|
62
|
+
if (byS) return byS;
|
|
63
|
+
}
|
|
64
|
+
return channelCfg.tools;
|
|
65
|
+
}
|
|
66
|
+
/** Find the best group config for a channel name. */
|
|
67
|
+
function getGroupConfig(channel, groups) {
|
|
68
|
+
return groups[channel] ?? groups["*"];
|
|
69
|
+
}
|
|
70
|
+
var IrcConnector = class extends events.EventEmitter {
|
|
71
|
+
client = null;
|
|
72
|
+
config;
|
|
73
|
+
constructor(rawConfig) {
|
|
74
|
+
super();
|
|
75
|
+
this.config = resolveEnvConfig(rawConfig);
|
|
76
|
+
}
|
|
77
|
+
async connect() {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const cfg = this.config;
|
|
80
|
+
const useTls = cfg.tls ?? false;
|
|
81
|
+
const port = cfg.port ?? (useTls ? 6697 : 6667);
|
|
82
|
+
const channels = (cfg.channels ?? []).map((c) => c.startsWith("#") ? c : `#${c}`);
|
|
83
|
+
this.client = new irc.default.Client(cfg.server, cfg.nick, {
|
|
84
|
+
port,
|
|
85
|
+
secure: useTls,
|
|
86
|
+
channels,
|
|
87
|
+
userName: cfg.username ?? cfg.nick,
|
|
88
|
+
realName: cfg.realname ?? "HyperClaw IRC Bot",
|
|
89
|
+
password: cfg.password,
|
|
90
|
+
autoConnect: true,
|
|
91
|
+
debug: false,
|
|
92
|
+
showErrors: true,
|
|
93
|
+
stripColors: true
|
|
94
|
+
});
|
|
95
|
+
this.client.on("registered", () => {
|
|
96
|
+
console.log(chalk.default.green(` 🦅 IRC: ${cfg.nick} on ${cfg.server}:${port}${useTls ? " (TLS)" : ""} connected`));
|
|
97
|
+
this._handleNickServ();
|
|
98
|
+
this.emit("connected", {
|
|
99
|
+
server: cfg.server,
|
|
100
|
+
nick: cfg.nick,
|
|
101
|
+
port,
|
|
102
|
+
tls: useTls
|
|
103
|
+
});
|
|
104
|
+
resolve();
|
|
105
|
+
});
|
|
106
|
+
this.client.on("error", (err) => {
|
|
107
|
+
console.log(chalk.default.yellow(` ⚠ IRC error: ${err.message}`));
|
|
108
|
+
reject(err);
|
|
109
|
+
});
|
|
110
|
+
this.client.on("message", (from, to, message) => {
|
|
111
|
+
const isChannel = to.startsWith("#");
|
|
112
|
+
if (isChannel) this._handleChannelMessage(from, to, message);
|
|
113
|
+
else this._handleDm(from, message);
|
|
114
|
+
});
|
|
115
|
+
this.client.on("pm", (from, message) => {
|
|
116
|
+
this._handleDm(from, message);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
_handleNickServ() {
|
|
121
|
+
const ns = this.config.nickserv;
|
|
122
|
+
if (!ns?.enabled) return;
|
|
123
|
+
const service = ns.service ?? "NickServ";
|
|
124
|
+
const nsPassword = ns.password ?? process.env["IRC_NICKSERV_PASSWORD"];
|
|
125
|
+
if (ns.register && ns.registerEmail) {
|
|
126
|
+
console.log(chalk.default.gray(` IRC NickServ: attempting REGISTER`));
|
|
127
|
+
this.client.say(service, `REGISTER ${nsPassword} ${ns.registerEmail}`);
|
|
128
|
+
} else if (nsPassword) {
|
|
129
|
+
console.log(chalk.default.gray(` IRC NickServ: identifying`));
|
|
130
|
+
this.client.say(service, `IDENTIFY ${nsPassword}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
_handleChannelMessage(from, channel, message) {
|
|
134
|
+
const cfg = this.config;
|
|
135
|
+
const text = message.trim();
|
|
136
|
+
if (!text) return;
|
|
137
|
+
const groupCfg = getGroupConfig(channel, cfg.groups ?? {});
|
|
138
|
+
if (cfg.groupPolicy === "allowlist") {
|
|
139
|
+
const defined = cfg.groups && (cfg.groups[channel] !== void 0 || cfg.groups["*"] !== void 0);
|
|
140
|
+
if (!defined) {
|
|
141
|
+
console.log(chalk.default.gray(` irc: drop channel ${channel} (groupPolicy=allowlist, not in groups)`));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const allowBareNick = cfg.dangerouslyAllowNameMatching ?? false;
|
|
146
|
+
const perChannelAllow = groupCfg?.allowFrom ?? [];
|
|
147
|
+
const globalGroupAllow = cfg.groupAllowFrom ?? [];
|
|
148
|
+
const effectiveAllow = perChannelAllow.length ? perChannelAllow : globalGroupAllow;
|
|
149
|
+
if (effectiveAllow.length && !senderAllowed(from, effectiveAllow, allowBareNick)) {
|
|
150
|
+
console.log(chalk.default.gray(` irc: drop group sender ${from} (policy=allowlist)`));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const requireMention = groupCfg?.requireMention ?? true;
|
|
154
|
+
if (requireMention) {
|
|
155
|
+
const mentionPatterns = [
|
|
156
|
+
cfg.nick,
|
|
157
|
+
`${cfg.nick}:`,
|
|
158
|
+
`@${cfg.nick}`,
|
|
159
|
+
`${cfg.nick},`
|
|
160
|
+
];
|
|
161
|
+
const mentioned = mentionPatterns.some((p) => text.toLowerCase().startsWith(p.toLowerCase()));
|
|
162
|
+
if (!mentioned) {
|
|
163
|
+
console.log(chalk.default.gray(` irc: drop channel ${channel} (missing-mention)`));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const toolPolicy = resolveToolPolicy(from, groupCfg, allowBareNick);
|
|
168
|
+
const payload = {
|
|
169
|
+
chatId: channel,
|
|
170
|
+
text,
|
|
171
|
+
from,
|
|
172
|
+
to: channel,
|
|
173
|
+
isChannel: true,
|
|
174
|
+
...toolPolicy ? { toolPolicy } : {}
|
|
175
|
+
};
|
|
176
|
+
this.emit("message", payload);
|
|
177
|
+
}
|
|
178
|
+
_handleDm(from, message) {
|
|
179
|
+
const cfg = this.config;
|
|
180
|
+
const text = message.trim();
|
|
181
|
+
if (!text) return;
|
|
182
|
+
if (cfg.dmPolicy === "none") return;
|
|
183
|
+
if (cfg.dmPolicy === "allowlist") {
|
|
184
|
+
const allowBareNick = cfg.dangerouslyAllowNameMatching ?? false;
|
|
185
|
+
const allowList = cfg.allowFrom ?? [];
|
|
186
|
+
if (!senderAllowed(from, allowList, allowBareNick)) {
|
|
187
|
+
console.log(chalk.default.gray(` irc: drop DM from ${from} (dmPolicy=allowlist)`));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const payload = {
|
|
192
|
+
chatId: from,
|
|
193
|
+
text,
|
|
194
|
+
from,
|
|
195
|
+
to: from,
|
|
196
|
+
isChannel: false
|
|
197
|
+
};
|
|
198
|
+
this.emit("message", payload);
|
|
199
|
+
}
|
|
200
|
+
async sendMessage(chatId, text) {
|
|
201
|
+
if (!this.client) throw new Error("IRC not connected");
|
|
202
|
+
const lines = text.split("\n").filter(Boolean);
|
|
203
|
+
for (const line of lines) this.client.say(chatId, line);
|
|
204
|
+
}
|
|
205
|
+
async disconnect() {
|
|
206
|
+
if (this.client) {
|
|
207
|
+
this.client.disconnect();
|
|
208
|
+
this.client = null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
getToolPolicy(sender, channel) {
|
|
212
|
+
const groupCfg = getGroupConfig(channel, this.config.groups ?? {});
|
|
213
|
+
return resolveToolPolicy(sender, groupCfg, this.config.dangerouslyAllowNameMatching ?? false);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
//#endregion
|
|
218
|
+
exports.IrcConnector = IrcConnector;
|
|
@@ -0,0 +1,182 @@
|
|
|
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/viber/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "viber-state.json");
|
|
12
|
+
function viberReq(token, endpoint, body) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const payload = JSON.stringify(body);
|
|
15
|
+
const req = https.default.request({
|
|
16
|
+
hostname: "chatapi.viber.com",
|
|
17
|
+
port: 443,
|
|
18
|
+
path: `/pa${endpoint}`,
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: {
|
|
21
|
+
"X-Viber-Auth-Token": token,
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
24
|
+
}
|
|
25
|
+
}, (res) => {
|
|
26
|
+
let data = "";
|
|
27
|
+
res.on("data", (c) => data += c);
|
|
28
|
+
res.on("end", () => {
|
|
29
|
+
try {
|
|
30
|
+
const r = JSON.parse(data);
|
|
31
|
+
if (r.status !== 0) reject(new Error(r.status_message));
|
|
32
|
+
else resolve(r);
|
|
33
|
+
} catch {
|
|
34
|
+
reject(new Error("Invalid JSON"));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
req.on("error", reject);
|
|
39
|
+
req.write(payload);
|
|
40
|
+
req.end();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
var ViberConnector = class extends events.EventEmitter {
|
|
44
|
+
config;
|
|
45
|
+
running = false;
|
|
46
|
+
constructor(config) {
|
|
47
|
+
super();
|
|
48
|
+
this.config = {
|
|
49
|
+
dmPolicy: "allowlist",
|
|
50
|
+
allowFrom: [],
|
|
51
|
+
approvedPairings: [],
|
|
52
|
+
pendingPairings: {},
|
|
53
|
+
...config
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async connect() {
|
|
57
|
+
await viberReq(this.config.authToken, "/set_webhook", {
|
|
58
|
+
url: this.config.webhookUrl,
|
|
59
|
+
event_types: [
|
|
60
|
+
"delivered",
|
|
61
|
+
"seen",
|
|
62
|
+
"failed",
|
|
63
|
+
"subscribed",
|
|
64
|
+
"unsubscribed",
|
|
65
|
+
"conversation_started"
|
|
66
|
+
],
|
|
67
|
+
send_name: true
|
|
68
|
+
});
|
|
69
|
+
const info = await viberReq(this.config.authToken, "/get_account_info", {});
|
|
70
|
+
await this.loadState();
|
|
71
|
+
this.running = true;
|
|
72
|
+
console.log(chalk.default.green(` 🦅 Viber: ${info.name || this.config.botName} connected`));
|
|
73
|
+
this.emit("connected", { name: info.name });
|
|
74
|
+
}
|
|
75
|
+
disconnect() {
|
|
76
|
+
this.running = false;
|
|
77
|
+
}
|
|
78
|
+
verifySignature(body, signature) {
|
|
79
|
+
const expected = crypto.default.createHmac("sha256", this.config.authToken).update(body).digest("hex");
|
|
80
|
+
try {
|
|
81
|
+
return crypto.default.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async handleWebhook(body, signature) {
|
|
87
|
+
if (signature && !this.verifySignature(body, signature)) {
|
|
88
|
+
console.log(chalk.default.yellow(" ⚠ Viber: invalid signature"));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let payload;
|
|
92
|
+
try {
|
|
93
|
+
payload = JSON.parse(body);
|
|
94
|
+
} catch {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (payload.event === "message") {
|
|
98
|
+
const userId = payload.sender?.id;
|
|
99
|
+
const text = payload.message?.text;
|
|
100
|
+
if (!userId || !text) return;
|
|
101
|
+
const allowed = await this.checkDMPolicy(userId, text);
|
|
102
|
+
if (!allowed) return;
|
|
103
|
+
this.emit("message", {
|
|
104
|
+
id: payload.message_token?.toString(),
|
|
105
|
+
channelId: "viber",
|
|
106
|
+
from: userId,
|
|
107
|
+
chatId: userId,
|
|
108
|
+
text,
|
|
109
|
+
senderName: payload.sender?.name,
|
|
110
|
+
timestamp: new Date(payload.timestamp).toISOString(),
|
|
111
|
+
isDM: true
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (payload.event === "conversation_started") await this.sendMessage(payload.user?.id, `🦅 Hi ${payload.user?.name || "there"}! I'm HyperClaw.`);
|
|
115
|
+
}
|
|
116
|
+
async checkDMPolicy(from, text) {
|
|
117
|
+
if (this.config.dmPolicy === "none") return false;
|
|
118
|
+
if (this.config.dmPolicy === "open") return true;
|
|
119
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
120
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
121
|
+
await this.sendMessage(from, "🦅 HyperClaw: Not on allowlist.");
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (this.config.dmPolicy === "pairing") {
|
|
125
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
126
|
+
const upper = text.trim().toUpperCase();
|
|
127
|
+
if (this.config.pendingPairings[upper]) {
|
|
128
|
+
this.config.approvedPairings.push(from);
|
|
129
|
+
delete this.config.pendingPairings[upper];
|
|
130
|
+
await this.saveState();
|
|
131
|
+
await this.sendMessage(from, "🦅 Paired!");
|
|
132
|
+
this.emit("pairing:approved", {
|
|
133
|
+
userId: from,
|
|
134
|
+
channelId: "viber"
|
|
135
|
+
});
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
139
|
+
this.config.pendingPairings[code] = from;
|
|
140
|
+
await this.saveState();
|
|
141
|
+
await this.sendMessage(from, `🦅 Pairing code: ${code}\nApprove: hyperclaw pairing approve viber ${code}`);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
async sendMessage(userId, text) {
|
|
147
|
+
await viberReq(this.config.authToken, "/send_message", {
|
|
148
|
+
receiver: userId,
|
|
149
|
+
type: "text",
|
|
150
|
+
sender: { name: this.config.botName },
|
|
151
|
+
text: text.slice(0, 7e3)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
approvePairing(code) {
|
|
155
|
+
const upper = code.toUpperCase();
|
|
156
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
157
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
158
|
+
delete this.config.pendingPairings[upper];
|
|
159
|
+
this.saveState();
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
async loadState() {
|
|
163
|
+
try {
|
|
164
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
165
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
166
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
167
|
+
} catch {}
|
|
168
|
+
}
|
|
169
|
+
async saveState() {
|
|
170
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
171
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
172
|
+
p: this.config.pendingPairings,
|
|
173
|
+
a: this.config.approvedPairings
|
|
174
|
+
}, { spaces: 2 });
|
|
175
|
+
}
|
|
176
|
+
isRunning() {
|
|
177
|
+
return this.running;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
exports.ViberConnector = ViberConnector;
|