@wu529778790/open-im 1.11.4-beta.18 → 1.11.4-beta.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/README.md CHANGED
@@ -137,27 +137,6 @@ claude -c # 接上手机端的对话
137
137
  }
138
138
  ```
139
139
 
140
- ### 语音回复(可选)
141
-
142
- ClawBot 支持语音回复,需要 Python 3 + edge-tts:
143
-
144
- ```bash
145
- # 安装依赖
146
- pip3 install edge-tts
147
-
148
- # 启用语音
149
- # 在管理页面 http://127.0.0.1:39282 打开 ClawBot 的「语音回复」开关
150
- ```
151
-
152
- 支持的中文声音:
153
- - 晓晓(女声,温柔)
154
- - 晓伊(女声,活泼)
155
- - 云希(男声,年轻)
156
- - 云健(男声,沉稳)
157
- - 云扬(男声,专业)
158
-
159
- > 不安装 Python 也能正常使用 open-im,语音回复是可选功能。
160
-
161
140
  ### 环境变量
162
141
 
163
142
  - **`ANTHROPIC_*`** — Claude API 配置
@@ -12,8 +12,7 @@ import { createLogger } from '../logger.js';
12
12
  import { jitteredDelay, isFatalReconnectError, SLOW_PROBE_MS } from '../shared/reconnect.js';
13
13
  import { cacheContextToken } from './message-sender.js';
14
14
  import { setClawbotContextToken, clearClawbotContextToken } from '../shared/active-chats.js';
15
- import { createMediaTargetPath } from '../shared/media-storage.js';
16
- import { createDecipheriv } from 'node:crypto';
15
+ import { decryptAes256CbcMedia, saveBufferMedia, createMediaTargetPath } from '../shared/media-storage.js';
17
16
  import { CLAWBOT_POLL_INTERVAL_MS } from '../constants.js';
18
17
  const log = createLogger('ClawBot');
19
18
  const RECONNECT_DELAYS_MS = [3000, 5000, 10000, 20000, 30000];
@@ -133,10 +132,6 @@ function startPolling() {
133
132
  cacheContextToken(chatId, msg.context_token);
134
133
  setClawbotContextToken(msg.context_token);
135
134
  }
136
- // Debug: log raw item_list for image messages
137
- if (extracted === '[图片]') {
138
- log.info(`Image message raw item_list: ${JSON.stringify(msg.item_list).substring(0, 2000)}`);
139
- }
140
135
  // Extract and download images from message
141
136
  const imagePaths = await extractImages(msg);
142
137
  userMessages.push({ chatId, msgId, content: extracted, imagePaths: imagePaths.length > 0 ? imagePaths : undefined });
@@ -254,47 +249,28 @@ async function extractImages(msg) {
254
249
  for (const item of msg.item_list) {
255
250
  if (item.type !== 2 /* MessageItemType.IMAGE */)
256
251
  continue;
257
- const imageItem = item.image_item;
258
- const media = imageItem?.media;
259
- // iLink API 使用 full_url 而非 cdn_url
260
- const imageUrl = media?.full_url || media?.cdn_url;
261
- if (!imageUrl) {
262
- log.warn('Image item missing full_url/cdn_url');
252
+ const media = item.image_item?.media;
253
+ if (!media?.cdn_url)
263
254
  continue;
264
- }
265
- // AES key: aeskey 字段是 32 字符 hex(16 字节),需要直接用作 AES-128-CBC key
266
- const aesKeyHex = imageItem?.aeskey;
267
255
  try {
268
256
  // Download from CDN
269
- const response = await fetch(imageUrl, { signal: AbortSignal.timeout(30_000) });
257
+ const response = await fetch(media.cdn_url, { signal: AbortSignal.timeout(30_000) });
270
258
  if (!response.ok) {
271
259
  log.warn(`Image download failed: HTTP ${response.status}`);
272
260
  continue;
273
261
  }
274
262
  const buffer = Buffer.from(await response.arrayBuffer());
275
- // 解密:aeskey hex 编码的 16 字节密钥,用 AES-128-CBC 解密
263
+ // Decrypt if AES key provided
276
264
  let decrypted;
277
- if (aesKeyHex && aesKeyHex.length === 32) {
278
- try {
279
- const keyBuf = Buffer.from(aesKeyHex, 'hex');
280
- const iv = keyBuf.subarray(0, 16);
281
- const decipher = createDecipheriv('aes-128-cbc', keyBuf, iv);
282
- decrypted = Buffer.concat([decipher.update(buffer), decipher.final()]);
283
- }
284
- catch {
285
- log.info('AES-128 decryption failed, using raw image data');
286
- decrypted = buffer;
287
- }
265
+ if (media.aes_key) {
266
+ decrypted = decryptAes256CbcMedia(buffer, media.aes_key);
288
267
  }
289
268
  else {
290
269
  decrypted = buffer;
291
270
  }
292
271
  // Save to disk
293
272
  const targetPath = createMediaTargetPath('.jpg', `clawbot-${Date.now()}`);
294
- const { writeFile } = await import('node:fs/promises');
295
- const { mkdir } = await import('node:fs/promises');
296
- await mkdir('/tmp/t/open-im-images', { recursive: true });
297
- await writeFile(targetPath, decrypted);
273
+ await saveBufferMedia(decrypted, targetPath);
298
274
  paths.push(targetPath);
299
275
  log.info(`ClawBot image saved: ${targetPath}`);
300
276
  }
@@ -5,7 +5,8 @@
5
5
  */
6
6
  import { randomBytes } from 'node:crypto';
7
7
  import { createLogger } from '../logger.js';
8
- import { toReplyPlainText } from '../shared/utils.js';
8
+ import { splitLongContent, toReplyPlainText } from '../shared/utils.js';
9
+ import { MAX_CLAWBOT_MESSAGE_LENGTH } from '../constants.js';
9
10
  import { getChannelState } from './client.js';
10
11
  import { getActiveChatId, getClawbotContextToken } from '../shared/active-chats.js';
11
12
  const log = createLogger('ClawBotSender');
@@ -93,9 +94,20 @@ async function postMessage(chatId, text, contextToken) {
93
94
  */
94
95
  export async function sendTextReply(chatId, text, contextToken) {
95
96
  const plainText = toReplyPlainText(text);
96
- // 发送文字消息
97
- log.info(`Sending ClawBot reply to chatId=${chatId}, len=${plainText.length}`);
98
- await postMessage(chatId, plainText, contextToken);
97
+ const parts = splitLongContent(plainText, MAX_CLAWBOT_MESSAGE_LENGTH);
98
+ if (parts.length === 1) {
99
+ log.info(`Sending ClawBot reply to chatId=${chatId}, len=${plainText.length}`);
100
+ await postMessage(chatId, plainText, contextToken);
101
+ return;
102
+ }
103
+ log.info(`Sending ClawBot reply in ${parts.length} parts to chatId=${chatId}, totalLen=${plainText.length}`);
104
+ for (let i = 0; i < parts.length; i++) {
105
+ const partText = i === 0
106
+ ? `${parts[i]}\n\n_(1/${parts.length})_`
107
+ : `_(续 ${i + 1}/${parts.length})_\n\n${parts[i]}`;
108
+ await postMessage(chatId, partText, contextToken);
109
+ log.info(`ClawBot part ${i + 1}/${parts.length} sent`);
110
+ }
99
111
  }
100
112
  /**
101
113
  * Send error reply to a ClawBot chat.
@@ -21,12 +21,9 @@ export interface TextItem {
21
21
  }
22
22
  /** Image content item */
23
23
  export interface ImageItem {
24
- aeskey?: string;
25
24
  media?: {
26
25
  aes_key?: string;
27
26
  cdn_url?: string;
28
- full_url?: string;
29
- encrypt_query_param?: string;
30
27
  };
31
28
  width?: number;
32
29
  height?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "1.11.4-beta.18",
3
+ "version": "1.11.4-beta.2",
4
4
  "description": "Your AI coding assistant, in every chat app. Multi-platform IM bridge for Claude Code, Codex, and CodeBuddy.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -58,13 +58,9 @@
58
58
  "@sentry/node": "^10.58.0",
59
59
  "centrifuge": "^5.5.3",
60
60
  "dingtalk-stream": "^2.1.4",
61
- "edge-tts": "^1.0.1",
62
- "https-proxy-agent": "^9.1.0",
63
- "node-edge-tts": "^1.2.10",
64
61
  "prompts": "^2.4.2",
65
- "say": "^0.16.0",
66
62
  "telegraf": "^4.16.3",
67
- "ws": "^8.21.0"
63
+ "ws": "^8.20.0"
68
64
  },
69
65
  "devDependencies": {
70
66
  "@eslint/js": "^9.15.0",