@wu529778790/open-im 1.10.9-beta.17 → 1.10.9-beta.18
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/clawbot/client.js +24 -9
- package/dist/clawbot/message-sender.js +9 -5
- package/dist/config-web.js +11 -3
- package/package.json +1 -1
package/dist/clawbot/client.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Receives messages via long-polling ilink/bot/getupdates
|
|
5
5
|
* and dispatches them to the event handler.
|
|
6
6
|
*/
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
7
8
|
import { createLogger } from '../logger.js';
|
|
8
9
|
import { jitteredDelay } from '../shared/reconnect.js';
|
|
9
10
|
import { CLAWBOT_POLL_INTERVAL_MS } from '../constants.js';
|
|
@@ -137,17 +138,31 @@ function updateState(state) {
|
|
|
137
138
|
}
|
|
138
139
|
async function fetchApi(path, signal) {
|
|
139
140
|
const url = `${apiUrl}${path}`;
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
141
|
+
const headers = {
|
|
142
|
+
'Content-Type': 'application/json',
|
|
143
|
+
'AuthorizationType': 'ilink_bot_token',
|
|
144
|
+
'iLink-App-Id': 'bot',
|
|
145
|
+
'iLink-App-ClientVersion': '131588',
|
|
146
|
+
'X-WECHAT-UIN': randomUUID(),
|
|
147
|
+
};
|
|
148
|
+
// Add bot_token to URL for authenticated endpoints
|
|
149
|
+
const sep = path.includes('?') ? '&' : '?';
|
|
150
|
+
const authedUrl = apiToken ? `${url}${sep}bot_token=${encodeURIComponent(apiToken)}` : url;
|
|
151
|
+
const res = await fetch(authedUrl, { headers, signal });
|
|
148
152
|
const text = await res.text();
|
|
149
153
|
try {
|
|
150
|
-
const
|
|
154
|
+
const raw = JSON.parse(text);
|
|
155
|
+
// iLink API uses {"ret": 0} for success, {"ret": -1} for error
|
|
156
|
+
if ('ret' in raw) {
|
|
157
|
+
const ok = raw.ret === 0 || raw.ret === '0';
|
|
158
|
+
const result = raw.result ?? raw.data ?? raw;
|
|
159
|
+
if (!ok) {
|
|
160
|
+
log.warn(`ClawBot API ${path.split('?')[0]} response: ${text.substring(0, 500)}`);
|
|
161
|
+
}
|
|
162
|
+
return { ok, error: ok ? undefined : String(raw.retmsg ?? raw.errmsg ?? raw.msg ?? `ret=${raw.ret}`), result };
|
|
163
|
+
}
|
|
164
|
+
// Fallback: {"ok": true/false} format
|
|
165
|
+
const json = raw;
|
|
151
166
|
if (!json.ok) {
|
|
152
167
|
log.warn(`ClawBot API ${path.split('?')[0]} response: ${text.substring(0, 500)}`);
|
|
153
168
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ClawBot Message Sender - Send messages via iLink API
|
|
3
3
|
*/
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
4
5
|
import { createLogger } from '../logger.js';
|
|
5
6
|
import { splitLongContent, toReplyPlainText } from '../shared/utils.js';
|
|
6
7
|
import { MAX_CLAWBOT_MESSAGE_LENGTH } from '../constants.js';
|
|
@@ -18,19 +19,22 @@ async function postMessage(chatId, text) {
|
|
|
18
19
|
return false;
|
|
19
20
|
}
|
|
20
21
|
try {
|
|
21
|
-
const
|
|
22
|
+
const url = `${apiUrl}/ilink/bot/sendmessage?bot_token=${encodeURIComponent(apiToken)}`;
|
|
23
|
+
const res = await fetch(url, {
|
|
22
24
|
method: 'POST',
|
|
23
25
|
headers: {
|
|
24
26
|
'Content-Type': 'application/json',
|
|
25
|
-
|
|
26
|
-
AuthorizationType: 'ilink_bot_token',
|
|
27
|
+
'AuthorizationType': 'ilink_bot_token',
|
|
27
28
|
'iLink-App-Id': 'bot',
|
|
29
|
+
'iLink-App-ClientVersion': '131588',
|
|
30
|
+
'X-WECHAT-UIN': randomUUID(),
|
|
28
31
|
},
|
|
29
32
|
body: JSON.stringify({ chat_id: chatId, text }),
|
|
30
33
|
});
|
|
31
34
|
const data = await res.json();
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
const ok = data.ok === true || data.ret === 0 || data.ret === '0';
|
|
36
|
+
if (!ok) {
|
|
37
|
+
log.error(`ClawBot sendmessage failed: ${JSON.stringify(data).substring(0, 300)}`);
|
|
34
38
|
return false;
|
|
35
39
|
}
|
|
36
40
|
return true;
|
package/dist/config-web.js
CHANGED
|
@@ -625,12 +625,20 @@ async function probeClawBot(config) {
|
|
|
625
625
|
const apiToken = clean(String(config.apiToken ?? ""));
|
|
626
626
|
if (!apiToken)
|
|
627
627
|
throw new Error("ClawBot API token is required.");
|
|
628
|
-
const
|
|
629
|
-
|
|
628
|
+
const { randomUUID } = await import('node:crypto');
|
|
629
|
+
const response = await fetch(`${apiUrl}/ilink/bot/getupdates?timeout=1&bot_token=${encodeURIComponent(apiToken)}`, {
|
|
630
|
+
headers: {
|
|
631
|
+
'Content-Type': 'application/json',
|
|
632
|
+
'AuthorizationType': 'ilink_bot_token',
|
|
633
|
+
'iLink-App-Id': 'bot',
|
|
634
|
+
'iLink-App-ClientVersion': '131588',
|
|
635
|
+
'X-WECHAT-UIN': randomUUID(),
|
|
636
|
+
},
|
|
630
637
|
signal: AbortSignal.timeout(TEST_TIMEOUT_MS),
|
|
631
638
|
});
|
|
632
639
|
const body = await readJsonResponse(response);
|
|
633
|
-
|
|
640
|
+
const ok = body.ok === true || body.ret === 0 || body.ret === '0';
|
|
641
|
+
if (!response.ok || !ok) {
|
|
634
642
|
throw new Error(String(body.error ?? body.description ?? `HTTP ${response.status}`));
|
|
635
643
|
}
|
|
636
644
|
return "ClawBot API reachable.";
|