@wu529778790/open-im 1.11.2-beta.9 → 1.11.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 +106 -98
- package/dist/clawbot/event-handler.js +4 -2
- package/dist/cli.js +9 -1
- package/dist/commands/handler.d.ts +7 -1
- package/dist/commands/handler.js +39 -1
- package/dist/config-web-page-i18n.d.ts +7 -7
- package/dist/config-web-page-i18n.js +7 -7
- package/dist/index.js +84 -13
- package/dist/shared/choice-detector.d.ts +35 -0
- package/dist/shared/choice-detector.js +58 -0
- package/dist/telegram/event-handler.js +30 -0
- package/dist/telegram/message-sender.js +28 -1
- package/dist/workbuddy/event-handler.js +5 -5
- package/package.json +1 -1
- package/web/dist/assets/index-CDyckT-E.js +57 -0
- package/web/dist/assets/index-XKVTb-0p.css +1 -0
- package/web/dist/index.html +2 -2
- package/README.zh-CN.md +0 -154
- package/web/dist/assets/index-3rbPJRxR.css +0 -1
- package/web/dist/assets/index-BNmg1lgm.js +0 -57
|
@@ -310,6 +310,36 @@ export function setupTelegramHandlers(bot, config, sessionManager) {
|
|
|
310
310
|
await ctx.answerCbQuery("任务已完成或不存在");
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
+
// 处理选择回调
|
|
314
|
+
if (data.startsWith("choice:")) {
|
|
315
|
+
const parts = data.split(":");
|
|
316
|
+
if (parts.length >= 3) {
|
|
317
|
+
const choiceNum = parts[2];
|
|
318
|
+
const chatId = String(ctx.chat?.id ?? "");
|
|
319
|
+
// 将用户选择作为消息发送给 AI
|
|
320
|
+
const { handleTextFlow } = await import("../platform/handle-text-flow.js");
|
|
321
|
+
await handleTextFlow({
|
|
322
|
+
platform: "telegram",
|
|
323
|
+
userId,
|
|
324
|
+
chatId,
|
|
325
|
+
text: choiceNum,
|
|
326
|
+
ctx: createPlatformEventContext({
|
|
327
|
+
platform: "telegram",
|
|
328
|
+
allowedUserIds: config.telegramAllowedUserIds,
|
|
329
|
+
config,
|
|
330
|
+
sessionManager,
|
|
331
|
+
sender: { sendTextReply: async () => { } },
|
|
332
|
+
}),
|
|
333
|
+
handleAIRequest: async () => { },
|
|
334
|
+
sendTextReply: async (c, t) => {
|
|
335
|
+
await sendTextReply(c, t);
|
|
336
|
+
},
|
|
337
|
+
workDir: sessionManager.getWorkDir(userId),
|
|
338
|
+
convId: sessionManager.getConvId(userId),
|
|
339
|
+
});
|
|
340
|
+
await ctx.answerCbQuery(`已选择 ${choiceNum}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
313
343
|
});
|
|
314
344
|
bot.on(message("text"), async (tgCtx) => {
|
|
315
345
|
try {
|
|
@@ -7,6 +7,7 @@ import { buildMessageTitle, OPEN_IM_SYSTEM_TITLE } from "../shared/message-title
|
|
|
7
7
|
import { buildTextNote } from "../shared/message-note.js";
|
|
8
8
|
import { MAX_TELEGRAM_MESSAGE_LENGTH } from "../constants.js";
|
|
9
9
|
import { listDirectories, buildDirectoryKeyboard, } from "../commands/handler.js";
|
|
10
|
+
import { detectChoices, buildChoiceKeyboard } from "../shared/choice-detector.js";
|
|
10
11
|
const log = createLogger("TgSender");
|
|
11
12
|
const lastSentByMsg = new Map();
|
|
12
13
|
// Periodic cleanup of orphaned entries (entries not cleaned by done/error)
|
|
@@ -120,7 +121,33 @@ export async function sendFinalMessages(chatId, messageId, fullContent, note, to
|
|
|
120
121
|
export async function sendTextReply(chatId, text) {
|
|
121
122
|
const bot = getBot();
|
|
122
123
|
try {
|
|
123
|
-
|
|
124
|
+
const formatted = formatMessage(text, "done", undefined, OPEN_IM_SYSTEM_TITLE);
|
|
125
|
+
// 检测是否有编号选择
|
|
126
|
+
const detection = detectChoices(text);
|
|
127
|
+
if (detection.hasChoices) {
|
|
128
|
+
// 有选择:发送纯文本 + 按钮
|
|
129
|
+
const keyboard = buildChoiceKeyboard(detection.choices, chatId);
|
|
130
|
+
try {
|
|
131
|
+
await bot.telegram.sendMessage(Number(chatId), detection.cleanText || formatted, {
|
|
132
|
+
parse_mode: "Markdown",
|
|
133
|
+
reply_markup: keyboard,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
await bot.telegram.sendMessage(Number(chatId), detection.cleanText || formatted, {
|
|
138
|
+
reply_markup: keyboard,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
// 无选择:普通消息
|
|
144
|
+
try {
|
|
145
|
+
await bot.telegram.sendMessage(Number(chatId), formatted, { parse_mode: "Markdown" });
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
await bot.telegram.sendMessage(Number(chatId), formatted);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
124
151
|
}
|
|
125
152
|
catch (err) {
|
|
126
153
|
log.error("Failed to send text:", err);
|
|
@@ -24,17 +24,17 @@ export function setupWorkBuddyHandlers(config, sessionManager) {
|
|
|
24
24
|
});
|
|
25
25
|
// Start task cleanup
|
|
26
26
|
const stopTaskCleanup = startTaskCleanup(ctx.runningTasks);
|
|
27
|
-
// WorkBuddy-specific sender callbacks
|
|
27
|
+
// WorkBuddy-specific sender callbacks
|
|
28
28
|
const platformSender = {
|
|
29
|
-
sendThinkingMessage: async (
|
|
30
|
-
// WorkBuddy
|
|
31
|
-
|
|
29
|
+
sendThinkingMessage: async (chatId, _replyToMessageId, _toolId) => {
|
|
30
|
+
// WorkBuddy 不支持 typing indicator,先发一条"思考中"消息给用户反馈
|
|
31
|
+
await sendTextReply(null, chatId, '🤔 正在处理...', '');
|
|
32
|
+
return 'workbuddy_thinking';
|
|
32
33
|
},
|
|
33
34
|
sendTextReply: async (chatId, text) => {
|
|
34
35
|
await sendTextReply(null, chatId, text, '');
|
|
35
36
|
},
|
|
36
37
|
startTyping: (_chatId) => {
|
|
37
|
-
// WorkBuddy doesn't support typing indicators
|
|
38
38
|
return () => { };
|
|
39
39
|
},
|
|
40
40
|
};
|
package/package.json
CHANGED