xiaozuoassistant 0.2.51 → 0.2.53
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.
|
@@ -101,6 +101,46 @@ export class FeishuChannel extends BaseChannel {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
try {
|
|
104
|
+
const sessionId = `feishu:${botName}:${event.chat_id}`;
|
|
105
|
+
// 处理文件类型消息
|
|
106
|
+
if (event.message_type === 'file') {
|
|
107
|
+
const contentObj = JSON.parse(event.content);
|
|
108
|
+
const fileKey = contentObj.file_key;
|
|
109
|
+
const fileName = contentObj.file_name || 'unknown.file';
|
|
110
|
+
const validExts = ['.docx', '.doc', '.xlsx', '.xls', '.pptx', '.ppt', '.csv', '.pdf', '.txt', '.md'];
|
|
111
|
+
const isDocument = validExts.some(ext => fileName.toLowerCase().endsWith(ext));
|
|
112
|
+
if (isDocument) {
|
|
113
|
+
const path = require('path');
|
|
114
|
+
const fs = require('fs-extra');
|
|
115
|
+
const configLoader = require('../config/loader.js').config;
|
|
116
|
+
const workspacePath = path.resolve(configLoader.workspace || path.join(process.cwd(), 'workspace'));
|
|
117
|
+
await fs.ensureDir(workspacePath);
|
|
118
|
+
// 防止文件名冲突,可以加上时间戳前缀,但为了用户体验,我们保留原名,或者加上一个短哈希
|
|
119
|
+
const savePath = path.join(workspacePath, fileName);
|
|
120
|
+
this.emitMessage(sessionId, `收到文件: ${fileName},正在下载到工作区...`, botName);
|
|
121
|
+
try {
|
|
122
|
+
const res = await client.im.messageResource.get({
|
|
123
|
+
path: { message_id: event.message_id, file_key: fileKey },
|
|
124
|
+
params: { type: 'file' }
|
|
125
|
+
});
|
|
126
|
+
await res.writeFile(savePath);
|
|
127
|
+
const instruction = `用户通过飞书发送了一个文档文件: ${fileName}\n文件已自动下载到本地工作区路径: ${savePath}\n请读取该文件并完成用户的后续指令行为。`;
|
|
128
|
+
this.emitMessage(sessionId, instruction, botName);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
console.error(`[Feishu-${botName}] Failed to download file:`, err);
|
|
132
|
+
this.emitMessage(sessionId, `❌ 文件 ${fileName} 下载失败: ${err.message}`, botName);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
// 对于其他不支持的文件类型,提示用户
|
|
137
|
+
this.emitMessage(sessionId, `暂不支持自动处理该类型的文件: ${fileName}。目前支持 Word, Excel, PPT, PDF, TXT 等常见文档格式。`, botName);
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (event.message_type !== 'text') {
|
|
142
|
+
return; // 目前只处理文本和特定文件
|
|
143
|
+
}
|
|
104
144
|
let content = JSON.parse(event.content).text;
|
|
105
145
|
// 清理飞书消息中的 @ 占位符 (例如 "@_user_1")
|
|
106
146
|
if (event.mentions && event.mentions.length > 0) {
|
|
@@ -120,9 +160,6 @@ export class FeishuChannel extends BaseChannel {
|
|
|
120
160
|
if (!content.trim()) {
|
|
121
161
|
return;
|
|
122
162
|
}
|
|
123
|
-
// Use chat_id for group chats, open_id/user_id for p2p?
|
|
124
|
-
// Actually message.chat_id is universal for where the message comes from.
|
|
125
|
-
const sessionId = `feishu:${botName}:${event.chat_id}`;
|
|
126
163
|
// 支持飞书端发送 /archive 触发手动归档
|
|
127
164
|
if (content.trim().toLowerCase() === '/archive') {
|
|
128
165
|
console.log(`[Feishu-${botName}] Manual archive command triggered for sessionId: ${sessionId}`);
|
|
@@ -3,7 +3,11 @@ import path from 'path';
|
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
4
|
const SESSIONS_DIR = path.resolve(process.cwd(), 'sessions');
|
|
5
5
|
const INDEX_FILE = path.join(SESSIONS_DIR, 'index.json');
|
|
6
|
+
import { config } from '../../config/loader.js';
|
|
6
7
|
function defaultWorkspacePath() {
|
|
8
|
+
if (config && config.workspace) {
|
|
9
|
+
return path.resolve(config.workspace);
|
|
10
|
+
}
|
|
7
11
|
return path.resolve(process.cwd(), 'workspace');
|
|
8
12
|
}
|
|
9
13
|
function normalizeWorkspace(input) {
|