hyperclaw 5.0.0 → 5.0.2
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/LICENSE +2 -1
- package/README.md +449 -99
- package/dist/a2ui-protocol-Gzm29Gaw.js +75 -0
- package/dist/agents-routing-Biy5ew4a.js +4 -0
- package/dist/agents-routing-CL3HQNoM.js +327 -0
- package/dist/api-keys-guide-CGn5BSF7.js +149 -0
- package/dist/api-keys-guide-ChbThbPj.js +149 -0
- package/dist/audit-BJohI_vC.js +441 -0
- package/dist/audit-NPIMmOSq.js +441 -0
- package/dist/bounty-tools-BUqUKjt0.js +211 -0
- package/dist/bounty-tools-CY_i91DU.js +211 -0
- package/dist/browser-tools-CxJY6pAn.js +5 -0
- package/dist/browser-tools-JZ9ji6AW.js +179 -0
- package/dist/chat-qVuqhlPu.js +258 -0
- package/dist/claw-tasks-B-8RRMdq.js +80 -0
- package/dist/claw-tasks-Cyzdbhz_.js +80 -0
- package/dist/connector-1x1rCBHz.js +162 -0
- package/dist/connector-B4jeCULG.js +305 -0
- package/dist/connector-B7qngfkT.js +286 -0
- package/dist/connector-B8BK0GBo.js +531 -0
- package/dist/connector-BE9eJs8-.js +182 -0
- package/dist/connector-BEe-DTGQ.js +189 -0
- package/dist/connector-BU7p5ZgB.js +167 -0
- package/dist/connector-BUzzq7Ij.js +568 -0
- package/dist/connector-BpDqLgnW.js +419 -0
- package/dist/connector-BpW88ut2.js +189 -0
- package/dist/connector-Bxv-gy8U.js +167 -0
- package/dist/connector-Bz14zcJv.js +213 -0
- package/dist/connector-C1zP5-5q.js +85 -0
- package/dist/connector-CAcpcovF.js +498 -0
- package/dist/connector-CJgVjS58.js +181 -0
- package/dist/connector-Cf53D6qV.js +425 -0
- package/dist/connector-CyHmlbNz.js +508 -0
- package/dist/connector-D22mJGVu.js +340 -0
- package/dist/connector-D6RtMmlL.js +225 -0
- package/dist/connector-D9EnT8A4.js +280 -0
- package/dist/connector-DNDwIh37.js +239 -0
- package/dist/connector-Di27MeO4.js +350 -0
- package/dist/connector-Do0BPiHt.js +194 -0
- package/dist/connector-DvLwOfJy.js +192 -0
- package/dist/connector-DvU83NSq.js +181 -0
- package/dist/connector-DxskpDc_.js +173 -0
- package/dist/connector-byy3eISx.js +552 -0
- package/dist/connector-vV89hsyd.js +218 -0
- package/dist/cost-tracker-Ca1UPZ33.js +103 -0
- package/dist/cost-tracker-fnaj_6M9.js +103 -0
- package/dist/credentials-store-BxijEirw.js +77 -0
- package/dist/credentials-store-CA8UtK0T.js +77 -0
- package/dist/credentials-store-CPkVO6-z.js +4 -0
- package/dist/credentials-store-Cm7DH-kh.js +4 -0
- package/dist/cron-tasks-L0mz1yyU.js +82 -0
- package/dist/cron-tasks-_pqQCmxc.js +82 -0
- package/dist/daemon-7ViroziB.js +5 -0
- package/dist/daemon-BfyKmZhr.js +318 -0
- package/dist/daemon-CNyunwkR.js +5 -0
- package/dist/daemon-CindY8OK.js +318 -0
- package/dist/delivery-DVHmv1IR.js +4 -0
- package/dist/delivery-DgiZcJBp.js +4 -0
- package/dist/delivery-DpMX0Yyc.js +95 -0
- package/dist/delivery-otAU4alM.js +95 -0
- package/dist/destructive-gate-CA0DtA5K.js +101 -0
- package/dist/destructive-gate-DZt71UZR.js +101 -0
- package/dist/developer-keys-Cnd1kswV.js +127 -0
- package/dist/developer-keys-DENo3ZA6.js +8 -0
- package/dist/doctor-Dgjoc3DG.js +230 -0
- package/dist/doctor-RwsOhtAl.js +6 -0
- package/dist/engine-B0kLfRL0.js +256 -0
- package/dist/engine-BJUpRUOv.js +7 -0
- package/dist/engine-D_VeoZHw.js +305 -0
- package/dist/engine-JjRnhlsE.js +7 -0
- package/dist/env-resolve-17ekEU6p.js +10 -0
- package/dist/env-resolve-BFJXWl94.js +115 -0
- package/dist/env-resolve-Z2XF6leB.js +115 -0
- package/dist/env-resolve-bDYssfih.js +10 -0
- package/dist/extraction-tools-DbxnxIco.js +5 -0
- package/dist/extraction-tools-Dg7AHS35.js +91 -0
- package/dist/form_data-CGAy4HE0.js +8657 -0
- package/dist/gmail-watch-setup-C3uSWznp.js +40 -0
- package/dist/health-DUjluWHQ.js +6 -0
- package/dist/health-DVfkpUQW.js +152 -0
- package/dist/heartbeat-engine-CrgL4mrP.js +83 -0
- package/dist/heartbeat-engine-Ut6pXBD6.js +83 -0
- package/dist/hub-9LaKnLjY.js +6 -0
- package/dist/hub-BO6bj8Yj.js +515 -0
- package/dist/hub-Bu52YZqW.js +6 -0
- package/dist/hub-CfwUz9YW.js +515 -0
- package/dist/hyperclawbot-BrcoYLOp.js +505 -0
- package/dist/hyperclawbot-CBiDSKsa.js +505 -0
- package/dist/inference-0mlFQqIm.js +922 -0
- package/dist/inference-DHR82Gh7.js +6 -0
- package/dist/inference-DhA8jpfH.js +2692 -0
- package/dist/inference-SzqFe_nk.js +6 -0
- package/dist/knowledge-graph-BrYpSgxW.js +131 -0
- package/dist/knowledge-graph-DE5lSF02.js +131 -0
- package/dist/loader-9JqY6Nlq.js +4 -0
- package/dist/loader-BkDi8MD9.js +400 -0
- package/dist/loader-Cjdd1kw4.js +400 -0
- package/dist/loader-DI2qDRPC.js +4 -0
- package/dist/logger-Cp8wC7F8.js +83 -0
- package/dist/logger-DCT2l9GV.js +83 -0
- package/dist/manager-3cq3DydI.js +4 -0
- package/dist/manager-B2Gls5RG.js +218 -0
- package/dist/manager-BUrFrPuq.js +117 -0
- package/dist/manager-Bi9UYyVR.js +105 -0
- package/dist/manager-Biz9ixWJ.js +40 -0
- package/dist/manager-CBUHJiY7.js +6 -0
- package/dist/manager-CVLLaKmq.js +218 -0
- package/dist/manager-CWNSML5D.js +117 -0
- package/dist/manager-SJe9gt-q.js +4 -0
- package/dist/mcp-CUoTCMw-.js +139 -0
- package/dist/mcp-loader-BIz-450x.js +94 -0
- package/dist/mcp-loader-CvxRDtPC.js +94 -0
- package/dist/memory-OL77OMOr.js +270 -0
- package/dist/memory-auto-CpQHZlEJ.js +306 -0
- package/dist/memory-auto-D-L2q21G.js +306 -0
- package/dist/memory-auto-DTcy5VBy.js +5 -0
- package/dist/memory-auto-Z6LCf-iK.js +5 -0
- package/dist/memory-gUi4VaIf.js +4 -0
- package/dist/memory-integration-B8RSN4pr.js +91 -0
- package/dist/memory-integration-g2vxwgoE.js +91 -0
- package/dist/moltbook-B-40gQOL.js +81 -0
- package/dist/moltbook-Cl8cQfxJ.js +81 -0
- package/dist/node-TWxRm84k.js +222 -0
- package/dist/nodes-registry-C9dCFwjh.js +52 -0
- package/dist/nodes-registry-DKRtsbNg.js +52 -0
- package/dist/oauth-flow-CeaaGAz0.js +150 -0
- package/dist/oauth-flow-JCfporKq.js +150 -0
- package/dist/oauth-provider-4R0EJlsT.js +110 -0
- package/dist/oauth-provider-B4dzn56l.js +110 -0
- package/dist/observability-CDZmeHfa.js +89 -0
- package/dist/observability-nZ3CBIxG.js +89 -0
- package/dist/onboard-BBBWcfhp.js +10 -0
- package/dist/onboard-BVOtKQdh.js +3641 -0
- package/dist/onboard-Bw28IRQ3.js +4070 -0
- package/dist/onboard-CGNIw27w.js +11 -0
- package/dist/orchestrator-BovkM63z.js +6 -0
- package/dist/orchestrator-CcKx1Ovk.js +189 -0
- package/dist/orchestrator-DSbpkP1X.js +189 -0
- package/dist/orchestrator-DcFfDLTX.js +6 -0
- package/dist/osint-B4_m3VHQ.js +277 -0
- package/dist/osint-B6BZKQAD.js +277 -0
- package/dist/pairing-B6RArWhD.js +196 -0
- package/dist/pairing-BsQ08DLq.js +4 -0
- package/dist/pc-access-B0KocJNe.js +819 -0
- package/dist/pc-access-DkzmugZ7.js +8 -0
- package/dist/pending-approval-BgNjjuI2.js +22 -0
- package/dist/pending-approval-C_HkX1QL.js +22 -0
- package/dist/providers-DxiamZSL.js +5 -0
- package/dist/providers-Dy15rDb7.js +657 -0
- package/dist/reminders-store-CzUY0zYx.js +58 -0
- package/dist/renderer-ANNfXsHn.js +225 -0
- package/dist/rules-BSQwwAYC.js +103 -0
- package/dist/run-main.js +142 -132
- package/dist/runner-BHRSOPEU.js +1271 -0
- package/dist/runner-CJFJUtPm.js +1271 -0
- package/dist/sdk/index.js +2 -2
- package/dist/sdk/index.mjs +2 -2
- package/dist/security--oQObeJO.js +4 -0
- package/dist/security-wBOg0TA8.js +73 -0
- package/dist/server-Brl_HQUB.js +1255 -0
- package/dist/server-CbTTpB5m.js +1255 -0
- package/dist/server-DP_bPzvI.js +4 -0
- package/dist/server-DhfipkwN.js +4 -0
- package/dist/session-store-B09r5HgB.js +5 -0
- package/dist/session-store-DCTQIVur.js +113 -0
- package/dist/sessions-tools-BdlN6Pb6.js +95 -0
- package/dist/sessions-tools-JVLDKSJ_.js +5 -0
- package/dist/skill-loader-B5oeliGu.js +7 -0
- package/dist/skill-loader-Wf3brNOj.js +160 -0
- package/dist/skill-runtime-BGlvly2s.js +102 -0
- package/dist/skill-runtime-BXWd-Ktf.js +102 -0
- package/dist/skill-runtime-DhL2T76p.js +5 -0
- package/dist/skill-runtime-jgklm02e.js +5 -0
- package/dist/src-BbPa6Q8p.js +63 -0
- package/dist/src-BeXtfkK2.js +458 -0
- package/dist/src-Bhybpk1J.js +63 -0
- package/dist/src-CGQjRI4N.js +20 -0
- package/dist/src-DMJ4-uqk.js +458 -0
- package/dist/sub-agent-tools-CmE345s_.js +39 -0
- package/dist/sub-agent-tools-DHY-4WWM.js +39 -0
- package/dist/theme-D0smfC_l.js +8 -0
- package/dist/theme-DajRRZbA.js +180 -0
- package/dist/tool-policy-DZvF8xlQ.js +189 -0
- package/dist/tool-policy-DgNqFWYn.js +189 -0
- package/dist/tts-elevenlabs-C06nUxMK.js +61 -0
- package/dist/tts-elevenlabs-JeFaGNJU.js +61 -0
- package/dist/update-check-BVEqHhFY.js +83 -0
- package/dist/update-check-w4XuxVl7.js +81 -0
- package/dist/vision-JOtOS1Br.js +121 -0
- package/dist/vision-fky3elEo.js +121 -0
- package/dist/vision-tools-C8B3776g.js +5 -0
- package/dist/vision-tools-CB28ZCO_.js +5 -0
- package/dist/vision-tools-dwn9p4el.js +51 -0
- package/dist/vision-tools-vPPwQ-0N.js +51 -0
- package/dist/voice-transcription-B6RtplmN.js +138 -0
- package/dist/voice-transcription-DBo5hXmu.js +138 -0
- package/dist/website-watch-tools-B-jRAeTe.js +139 -0
- package/dist/website-watch-tools-BC9xAL67.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,350 @@
|
|
|
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/line/src/connector.ts
|
|
11
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "line-state.json");
|
|
12
|
+
const TEXT_CHUNK = 5e3;
|
|
13
|
+
const DEFAULT_MEDIA_MAX_MB = 10;
|
|
14
|
+
function lineReq(token, endpoint, body) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const payload = JSON.stringify(body);
|
|
17
|
+
const req = https.default.request({
|
|
18
|
+
hostname: "api.line.me",
|
|
19
|
+
port: 443,
|
|
20
|
+
path: endpoint,
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
Authorization: `Bearer ${token}`,
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
26
|
+
}
|
|
27
|
+
}, (res) => {
|
|
28
|
+
let data = "";
|
|
29
|
+
res.on("data", (c) => data += c);
|
|
30
|
+
res.on("end", () => {
|
|
31
|
+
try {
|
|
32
|
+
resolve(JSON.parse(data));
|
|
33
|
+
} catch {
|
|
34
|
+
resolve({});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
req.on("error", reject);
|
|
39
|
+
req.write(payload);
|
|
40
|
+
req.end();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Start the LINE loading indicator for a chat. */
|
|
44
|
+
function lineLoadingIndicator(token, chatId) {
|
|
45
|
+
return lineReq(token, "/v2/bot/chat/loading/start", {
|
|
46
|
+
chatId,
|
|
47
|
+
loadingSeconds: 20
|
|
48
|
+
}).catch(() => {});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Strip markdown for plain-text delivery.
|
|
52
|
+
* Code blocks and tables are converted to Flex cards when channelData allows;
|
|
53
|
+
* for plain-text paths they become preformatted text.
|
|
54
|
+
*/
|
|
55
|
+
function stripMarkdown(text) {
|
|
56
|
+
return text.replace(/```[\s\S]*?```/g, (m) => m.replace(/```\w*\n?/g, "").trim()).replace(/`([^`]+)`/g, "$1").replace(/^#{1,6}\s+/gm, "").replace(/\*\*(.+?)\*\*/g, "$1").replace(/\*(.+?)\*/g, "$1").replace(/~~(.+?)~~/g, "$1").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/^\s*[-*+]\s+/gm, "• ").replace(/^\s*\d+\.\s+/gm, (m) => m.trimStart());
|
|
57
|
+
}
|
|
58
|
+
function buildQuickReply(items) {
|
|
59
|
+
return { items: items.slice(0, 13).map((label) => ({
|
|
60
|
+
type: "action",
|
|
61
|
+
action: {
|
|
62
|
+
type: "message",
|
|
63
|
+
label: label.slice(0, 20),
|
|
64
|
+
text: label
|
|
65
|
+
}
|
|
66
|
+
})) };
|
|
67
|
+
}
|
|
68
|
+
function buildMessages(text, channelData) {
|
|
69
|
+
const msgs = [];
|
|
70
|
+
const plain = stripMarkdown(text);
|
|
71
|
+
const qr = channelData?.quickReplies?.length ? buildQuickReply(channelData.quickReplies) : void 0;
|
|
72
|
+
if (channelData?.location) {
|
|
73
|
+
const loc = channelData.location;
|
|
74
|
+
msgs.push({
|
|
75
|
+
type: "location",
|
|
76
|
+
title: loc.title,
|
|
77
|
+
address: loc.address,
|
|
78
|
+
latitude: loc.latitude,
|
|
79
|
+
longitude: loc.longitude
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (channelData?.flexMessage) {
|
|
83
|
+
msgs.push({
|
|
84
|
+
type: "flex",
|
|
85
|
+
altText: channelData.flexMessage.altText,
|
|
86
|
+
contents: channelData.flexMessage.contents,
|
|
87
|
+
...qr ? { quickReply: qr } : {}
|
|
88
|
+
});
|
|
89
|
+
return msgs;
|
|
90
|
+
}
|
|
91
|
+
if (channelData?.templateMessage) {
|
|
92
|
+
const t = channelData.templateMessage;
|
|
93
|
+
msgs.push({
|
|
94
|
+
type: "template",
|
|
95
|
+
altText: t.text,
|
|
96
|
+
template: {
|
|
97
|
+
type: "confirm",
|
|
98
|
+
text: t.text,
|
|
99
|
+
actions: [{
|
|
100
|
+
type: "postback",
|
|
101
|
+
label: t.confirmLabel,
|
|
102
|
+
data: t.confirmData
|
|
103
|
+
}, {
|
|
104
|
+
type: "postback",
|
|
105
|
+
label: t.cancelLabel,
|
|
106
|
+
data: t.cancelData
|
|
107
|
+
}]
|
|
108
|
+
},
|
|
109
|
+
...qr ? { quickReply: qr } : {}
|
|
110
|
+
});
|
|
111
|
+
return msgs;
|
|
112
|
+
}
|
|
113
|
+
const chunks = chunkText(plain);
|
|
114
|
+
chunks.forEach((chunk, i) => {
|
|
115
|
+
const isLast = i === chunks.length - 1;
|
|
116
|
+
msgs.push({
|
|
117
|
+
type: "text",
|
|
118
|
+
text: chunk,
|
|
119
|
+
...isLast && qr ? { quickReply: qr } : {}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
return msgs;
|
|
123
|
+
}
|
|
124
|
+
function chunkText(text) {
|
|
125
|
+
const chunks = [];
|
|
126
|
+
for (let i = 0; i < text.length; i += TEXT_CHUNK) chunks.push(text.slice(i, i + TEXT_CHUNK));
|
|
127
|
+
return chunks.length ? chunks : [""];
|
|
128
|
+
}
|
|
129
|
+
var LINEConnector = class extends events.EventEmitter {
|
|
130
|
+
config;
|
|
131
|
+
running = false;
|
|
132
|
+
_token = "";
|
|
133
|
+
_secret = "";
|
|
134
|
+
constructor(config) {
|
|
135
|
+
super();
|
|
136
|
+
this.config = {
|
|
137
|
+
dmPolicy: "pairing",
|
|
138
|
+
allowFrom: [],
|
|
139
|
+
groupPolicy: "allowlist",
|
|
140
|
+
groupAllowFrom: [],
|
|
141
|
+
approvedPairings: [],
|
|
142
|
+
pendingPairings: {},
|
|
143
|
+
mediaMaxMb: DEFAULT_MEDIA_MAX_MB,
|
|
144
|
+
...config
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Resolve token and secret (inline value takes priority over file). */
|
|
148
|
+
async resolveCredentials() {
|
|
149
|
+
this._token = this.config.channelAccessToken || (this.config.tokenFile ? (await fs_extra.default.readFile(this.config.tokenFile, "utf8")).trim() : "");
|
|
150
|
+
this._secret = this.config.channelSecret || (this.config.secretFile ? (await fs_extra.default.readFile(this.config.secretFile, "utf8")).trim() : "");
|
|
151
|
+
if (!this._token || !this._secret) throw new Error("LINE: channelAccessToken and channelSecret are required (or set tokenFile/secretFile).");
|
|
152
|
+
}
|
|
153
|
+
async connect() {
|
|
154
|
+
await this.resolveCredentials();
|
|
155
|
+
await this.loadState();
|
|
156
|
+
this.running = true;
|
|
157
|
+
const wPath = this.config.webhookPath || "/line/webhook";
|
|
158
|
+
console.log(chalk.default.green(` 🟩 LINE: connected (webhook mode — ${wPath})`));
|
|
159
|
+
this.emit("connected", {});
|
|
160
|
+
}
|
|
161
|
+
disconnect() {
|
|
162
|
+
this.running = false;
|
|
163
|
+
}
|
|
164
|
+
verifySignature(rawBody, signature) {
|
|
165
|
+
const expected = crypto.default.createHmac("sha256", this._secret).update(rawBody).digest("base64");
|
|
166
|
+
try {
|
|
167
|
+
return crypto.default.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
|
|
168
|
+
} catch {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async handleWebhook(rawBody, signature) {
|
|
173
|
+
if (!this.verifySignature(rawBody, signature)) {
|
|
174
|
+
console.log(chalk.default.yellow(" ⚠ LINE: invalid signature — check channelSecret"));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
let payload;
|
|
178
|
+
try {
|
|
179
|
+
payload = JSON.parse(rawBody);
|
|
180
|
+
} catch {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
for (const event of payload.events || []) await this.handleEvent(event);
|
|
184
|
+
}
|
|
185
|
+
async handleEvent(event) {
|
|
186
|
+
const src = event.source || {};
|
|
187
|
+
const sourceType = src.type || "user";
|
|
188
|
+
const userId = src.userId || "";
|
|
189
|
+
const groupId = src.groupId || src.roomId || "";
|
|
190
|
+
const replyToken = event.replyToken || "";
|
|
191
|
+
const isGroup = sourceType === "group" || sourceType === "room";
|
|
192
|
+
if (event.type === "postback") {
|
|
193
|
+
const data = event.postback?.data || "";
|
|
194
|
+
if (!data || !userId) return;
|
|
195
|
+
if (isGroup) {
|
|
196
|
+
if (!this.isGroupAllowed(groupId, userId)) return;
|
|
197
|
+
} else if (!await this.checkDMPolicy(userId, data, replyToken)) return;
|
|
198
|
+
this.emit("message", {
|
|
199
|
+
channelId: "line",
|
|
200
|
+
chatId: isGroup ? groupId : userId,
|
|
201
|
+
from: userId,
|
|
202
|
+
text: data,
|
|
203
|
+
replyToken,
|
|
204
|
+
isDM: !isGroup
|
|
205
|
+
});
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (event.type !== "message") return;
|
|
209
|
+
const msgType = event.message?.type || "";
|
|
210
|
+
const messageId = event.message?.id || "";
|
|
211
|
+
let text = "";
|
|
212
|
+
switch (msgType) {
|
|
213
|
+
case "text":
|
|
214
|
+
text = event.message.text || "";
|
|
215
|
+
break;
|
|
216
|
+
case "location":
|
|
217
|
+
text = [
|
|
218
|
+
event.message.title,
|
|
219
|
+
event.message.address,
|
|
220
|
+
`${event.message.latitude},${event.message.longitude}`
|
|
221
|
+
].filter(Boolean).join(" | ");
|
|
222
|
+
break;
|
|
223
|
+
case "sticker":
|
|
224
|
+
text = `[sticker:${event.message.packageId}/${event.message.stickerId}]`;
|
|
225
|
+
break;
|
|
226
|
+
case "image":
|
|
227
|
+
case "video":
|
|
228
|
+
case "audio":
|
|
229
|
+
case "file": {
|
|
230
|
+
const maxBytes = (this.config.mediaMaxMb ?? DEFAULT_MEDIA_MAX_MB) * 1024 * 1024;
|
|
231
|
+
const contentUrl = `/v2/bot/message/${messageId}/content`;
|
|
232
|
+
text = `[${msgType}:${contentUrl} max:${maxBytes}b]`;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
default: return;
|
|
236
|
+
}
|
|
237
|
+
if (!userId || !text) return;
|
|
238
|
+
if (isGroup) {
|
|
239
|
+
if (!this.isGroupAllowed(groupId, userId)) return;
|
|
240
|
+
lineLoadingIndicator(this._token, groupId);
|
|
241
|
+
this.emit("message", {
|
|
242
|
+
channelId: "line",
|
|
243
|
+
chatId: groupId,
|
|
244
|
+
from: userId,
|
|
245
|
+
text,
|
|
246
|
+
replyToken,
|
|
247
|
+
isDM: false
|
|
248
|
+
});
|
|
249
|
+
} else {
|
|
250
|
+
const allowed = await this.checkDMPolicy(userId, text, replyToken);
|
|
251
|
+
if (!allowed) return;
|
|
252
|
+
lineLoadingIndicator(this._token, userId);
|
|
253
|
+
this.emit("message", {
|
|
254
|
+
channelId: "line",
|
|
255
|
+
chatId: userId,
|
|
256
|
+
from: userId,
|
|
257
|
+
text,
|
|
258
|
+
replyToken,
|
|
259
|
+
isDM: true,
|
|
260
|
+
timestamp: new Date(event.timestamp).toISOString()
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
isGroupAllowed(groupId, userId) {
|
|
265
|
+
if (this.config.groupPolicy === "disabled") return false;
|
|
266
|
+
if (this.config.groupPolicy === "open") return true;
|
|
267
|
+
const perGroup = this.config.groups?.[groupId]?.allowFrom;
|
|
268
|
+
const list = perGroup ?? this.config.groupAllowFrom;
|
|
269
|
+
return list.includes(userId) || list.includes(groupId);
|
|
270
|
+
}
|
|
271
|
+
async checkDMPolicy(from, text, replyToken) {
|
|
272
|
+
switch (this.config.dmPolicy) {
|
|
273
|
+
case "disabled": return false;
|
|
274
|
+
case "open": return true;
|
|
275
|
+
case "allowlist":
|
|
276
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
277
|
+
await this.replyMessage(replyToken, "HyperClaw: Not on allowlist.");
|
|
278
|
+
return false;
|
|
279
|
+
case "pairing": {
|
|
280
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
281
|
+
const upper = text.trim().toUpperCase();
|
|
282
|
+
if (this.config.pendingPairings[upper]) {
|
|
283
|
+
this.config.approvedPairings.push(from);
|
|
284
|
+
delete this.config.pendingPairings[upper];
|
|
285
|
+
await this.saveState();
|
|
286
|
+
await this.replyMessage(replyToken, "Paired!");
|
|
287
|
+
this.emit("pairing:approved", {
|
|
288
|
+
userId: from,
|
|
289
|
+
channelId: "line"
|
|
290
|
+
});
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
294
|
+
this.config.pendingPairings[code] = from;
|
|
295
|
+
await this.saveState();
|
|
296
|
+
await this.replyMessage(replyToken, `Pairing code: ${code}\nApprove: hyperclaw pairing approve line ${code}`);
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
default: return false;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async replyMessage(replyToken, text, channelData) {
|
|
303
|
+
const messages = buildMessages(text, channelData).slice(0, 5);
|
|
304
|
+
await lineReq(this._token, "/v2/bot/message/reply", {
|
|
305
|
+
replyToken,
|
|
306
|
+
messages
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
async pushMessage(to, text, channelData) {
|
|
310
|
+
const messages = buildMessages(text, channelData).slice(0, 5);
|
|
311
|
+
await lineReq(this._token, "/v2/bot/message/push", {
|
|
312
|
+
to,
|
|
313
|
+
messages
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/** Unified send — uses replyToken when available, falls back to push. */
|
|
317
|
+
async sendMessage(chatId, text, replyToken, channelData) {
|
|
318
|
+
const id = String(chatId);
|
|
319
|
+
if (replyToken) await this.replyMessage(replyToken, text, channelData);
|
|
320
|
+
else await this.pushMessage(id, text, channelData);
|
|
321
|
+
}
|
|
322
|
+
approvePairing(code) {
|
|
323
|
+
const upper = code.toUpperCase();
|
|
324
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
325
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
326
|
+
delete this.config.pendingPairings[upper];
|
|
327
|
+
this.saveState();
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
async loadState() {
|
|
331
|
+
try {
|
|
332
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
333
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
334
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
335
|
+
} catch {}
|
|
336
|
+
}
|
|
337
|
+
async saveState() {
|
|
338
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
339
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
340
|
+
p: this.config.pendingPairings,
|
|
341
|
+
a: this.config.approvedPairings
|
|
342
|
+
}, { spaces: 2 });
|
|
343
|
+
}
|
|
344
|
+
isRunning() {
|
|
345
|
+
return this.running;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
//#endregion
|
|
350
|
+
exports.LINEConnector = LINEConnector;
|
|
@@ -0,0 +1,194 @@
|
|
|
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/whatsapp/src/connector.ts
|
|
10
|
+
const STATE_FILE = path.default.join(os.default.homedir(), ".hyperclaw", "whatsapp-state.json");
|
|
11
|
+
const GRAPH_API = "graph.facebook.com";
|
|
12
|
+
const API_VERSION = "v18.0";
|
|
13
|
+
function graphReq(token, method, endpoint, body) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
16
|
+
const req = https.default.request({
|
|
17
|
+
hostname: GRAPH_API,
|
|
18
|
+
port: 443,
|
|
19
|
+
path: `/${API_VERSION}${endpoint}`,
|
|
20
|
+
method,
|
|
21
|
+
headers: {
|
|
22
|
+
"Authorization": `Bearer ${token}`,
|
|
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
|
+
const r = JSON.parse(data);
|
|
34
|
+
if (r.error) reject(new Error(`${r.error.code}: ${r.error.message}`));
|
|
35
|
+
else resolve(r);
|
|
36
|
+
} catch {
|
|
37
|
+
reject(new Error("Invalid JSON"));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
req.on("error", reject);
|
|
42
|
+
if (payload) req.write(payload);
|
|
43
|
+
req.end();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
var WhatsAppConnector = class extends events.EventEmitter {
|
|
47
|
+
config;
|
|
48
|
+
running = false;
|
|
49
|
+
constructor(config) {
|
|
50
|
+
super();
|
|
51
|
+
this.config = {
|
|
52
|
+
dmPolicy: "allowlist",
|
|
53
|
+
allowFrom: [],
|
|
54
|
+
approvedPairings: [],
|
|
55
|
+
pendingPairings: {},
|
|
56
|
+
...config
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async connect() {
|
|
60
|
+
const info = await graphReq(this.config.accessToken, "GET", `/${this.config.phoneNumberId}`);
|
|
61
|
+
await this.loadState();
|
|
62
|
+
this.running = true;
|
|
63
|
+
console.log(chalk.default.green(` 🦅 WhatsApp: ${info.display_phone_number || this.config.phoneNumberId} connected`));
|
|
64
|
+
this.emit("connected", {
|
|
65
|
+
phoneNumberId: this.config.phoneNumberId,
|
|
66
|
+
number: info.display_phone_number
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
disconnect() {
|
|
70
|
+
this.running = false;
|
|
71
|
+
}
|
|
72
|
+
verifyWebhook(mode, token, challenge) {
|
|
73
|
+
if (mode === "subscribe" && token === this.config.verifyToken) return challenge;
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
async handleWebhook(body) {
|
|
77
|
+
let payload;
|
|
78
|
+
try {
|
|
79
|
+
payload = JSON.parse(body);
|
|
80
|
+
} catch {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const entry = payload.entry?.[0];
|
|
84
|
+
const changes = entry?.changes?.[0];
|
|
85
|
+
const value = changes?.value;
|
|
86
|
+
if (!value?.messages) return;
|
|
87
|
+
for (const msg of value.messages) {
|
|
88
|
+
if (msg.type !== "text") continue;
|
|
89
|
+
const from = msg.from;
|
|
90
|
+
const text = msg.text?.body;
|
|
91
|
+
if (!text) continue;
|
|
92
|
+
await this.markRead(msg.id).catch(() => {});
|
|
93
|
+
const allowed = await this.checkDMPolicy(from, text);
|
|
94
|
+
if (!allowed) continue;
|
|
95
|
+
this.emit("message", {
|
|
96
|
+
id: msg.id,
|
|
97
|
+
channelId: "whatsapp",
|
|
98
|
+
from,
|
|
99
|
+
chatId: from,
|
|
100
|
+
text,
|
|
101
|
+
timestamp: new Date(parseInt(msg.timestamp) * 1e3).toISOString(),
|
|
102
|
+
isDM: true,
|
|
103
|
+
name: value.contacts?.[0]?.profile?.name
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async checkDMPolicy(from, text) {
|
|
108
|
+
if (this.config.dmPolicy === "none") return false;
|
|
109
|
+
if (this.config.dmPolicy === "open") return true;
|
|
110
|
+
if (this.config.dmPolicy === "allowlist") {
|
|
111
|
+
if (this.config.allowFrom.includes(from)) return true;
|
|
112
|
+
await this.sendMessage(from, "🦅 HyperClaw: You are not on the allowlist.");
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (this.config.dmPolicy === "pairing") {
|
|
116
|
+
if (this.config.approvedPairings.includes(from)) return true;
|
|
117
|
+
const upper = text.trim().toUpperCase();
|
|
118
|
+
if (this.config.pendingPairings[upper]) {
|
|
119
|
+
this.config.approvedPairings.push(from);
|
|
120
|
+
delete this.config.pendingPairings[upper];
|
|
121
|
+
await this.saveState();
|
|
122
|
+
await this.sendMessage(from, "🦅 *Paired!* You can now send messages.");
|
|
123
|
+
this.emit("pairing:approved", {
|
|
124
|
+
userId: from,
|
|
125
|
+
channelId: "whatsapp"
|
|
126
|
+
});
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
const code = Array.from({ length: 6 }, () => "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"[Math.floor(Math.random() * 32)]).join("");
|
|
130
|
+
this.config.pendingPairings[code] = from;
|
|
131
|
+
await this.saveState();
|
|
132
|
+
await this.sendMessage(from, `🦅 HyperClaw Pairing\n\nCode: *${code}*\nAsk owner: hyperclaw pairing approve whatsapp ${code}`);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
async sendMessage(to, text) {
|
|
138
|
+
await graphReq(this.config.accessToken, "POST", `/${this.config.phoneNumberId}/messages`, {
|
|
139
|
+
messaging_product: "whatsapp",
|
|
140
|
+
to,
|
|
141
|
+
type: "text",
|
|
142
|
+
text: {
|
|
143
|
+
body: text.slice(0, 4096),
|
|
144
|
+
preview_url: false
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async markRead(messageId) {
|
|
149
|
+
await graphReq(this.config.accessToken, "POST", `/${this.config.phoneNumberId}/messages`, {
|
|
150
|
+
messaging_product: "whatsapp",
|
|
151
|
+
status: "read",
|
|
152
|
+
message_id: messageId
|
|
153
|
+
}).catch(() => {});
|
|
154
|
+
}
|
|
155
|
+
async sendTemplate(to, templateName, languageCode = "en_US") {
|
|
156
|
+
await graphReq(this.config.accessToken, "POST", `/${this.config.phoneNumberId}/messages`, {
|
|
157
|
+
messaging_product: "whatsapp",
|
|
158
|
+
to,
|
|
159
|
+
type: "template",
|
|
160
|
+
template: {
|
|
161
|
+
name: templateName,
|
|
162
|
+
language: { code: languageCode }
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
approvePairing(code) {
|
|
167
|
+
const upper = code.toUpperCase();
|
|
168
|
+
if (!this.config.pendingPairings[upper]) return false;
|
|
169
|
+
this.config.approvedPairings.push(this.config.pendingPairings[upper]);
|
|
170
|
+
delete this.config.pendingPairings[upper];
|
|
171
|
+
this.saveState();
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
async loadState() {
|
|
175
|
+
try {
|
|
176
|
+
const s = await fs_extra.default.readJson(STATE_FILE);
|
|
177
|
+
if (s.p) this.config.pendingPairings = s.p;
|
|
178
|
+
if (s.a) this.config.approvedPairings = s.a;
|
|
179
|
+
} catch {}
|
|
180
|
+
}
|
|
181
|
+
async saveState() {
|
|
182
|
+
await fs_extra.default.ensureDir(path.default.dirname(STATE_FILE));
|
|
183
|
+
await fs_extra.default.writeJson(STATE_FILE, {
|
|
184
|
+
p: this.config.pendingPairings,
|
|
185
|
+
a: this.config.approvedPairings
|
|
186
|
+
}, { spaces: 2 });
|
|
187
|
+
}
|
|
188
|
+
isRunning() {
|
|
189
|
+
return this.running;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
exports.WhatsAppConnector = WhatsAppConnector;
|