@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.
@@ -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
- await bot.telegram.sendMessage(Number(chatId), formatMessage(text, "done", undefined, OPEN_IM_SYSTEM_TITLE));
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 (no thinking message needed)
27
+ // WorkBuddy-specific sender callbacks
28
28
  const platformSender = {
29
- sendThinkingMessage: async (_chatId, _replyToMessageId, _toolId) => {
30
- // WorkBuddy uses incoming msgId directly; no separate thinking message
31
- return 'workbuddy_no_thinking';
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "1.11.2-beta.9",
3
+ "version": "1.11.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",