diff --git a/package.json b/package.json index 0d56cce..e14a92b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "telegram-codex-bot", - "version": "0.1.12", + "version": "0.1.13", "description": "Telegram bot powered by the local Codex CLI — zero-dependency, pm2-managed, with a built-in PM2 web viewer", "license": "MIT", "type": "commonjs", diff --git a/src/bot.js b/src/bot.js index 64653a8..8fdd7ed 100644 --- a/src/bot.js +++ b/src/bot.js @@ -210,13 +210,19 @@ function startBot(config) { return null; } - function buildPrompt(message, content) { + // 使用者引用/回覆的文字(圈選引用優先,其次是被回覆的整則訊息) + function quotedTextOf(message) { + return message.quote?.text || message.reply_to_message?.text || message.reply_to_message?.caption || ''; + } + + function buildPrompt(message, content, { includeOwnReply = false } = {}) { const from = message.from || {}; const name = [from.first_name, from.last_name].filter(Boolean).join(' ') || '未知使用者'; const sender = from.username ? `${name}(@${from.username})` : name; const parts = [OUTBOX_RULE]; const replied = message.reply_to_message; - if (replied && replied.from?.id !== botId && (replied.text || replied.caption)) { + // 回覆我自己的訊息通常已在會話記憶裡,不重複貼;但使用者沒打字只回覆時例外(那就是輸入本身) + if (replied && (includeOwnReply || replied.from?.id !== botId) && (replied.text || replied.caption)) { parts.push(`【被回覆的訊息】\n${replied.text || replied.caption}`); } if (message.quote?.text) { @@ -291,7 +297,9 @@ function startBot(config) { await t.sendMessage(chatId, statusText(chatId), { replyTo: message.message_id }); return; } - if (!content && !photo) { + // 只有「引用/回覆 + tag 我」沒打字:直接把引用內容當作這次的輸入 + const quotedOnly = !content && !photo && !!quotedTextOf(message); + if (!content && !photo && !quotedOnly) { await t.sendMessage(chatId, HELP_TEXT, { replyTo: message.message_id }); return; } @@ -324,7 +332,10 @@ function startBot(config) { images.push(dest); } - const prompt = buildPrompt(message, content || '(使用者只傳了圖片,請描述並依上下文處理)'); + const fallback = quotedOnly + ? '(使用者沒有輸入文字,只引用了上面的內容並 tag 我:請直接把引用內容當作這次的輸入來處理)' + : '(使用者只傳了圖片,請描述並依上下文處理)'; + const prompt = buildPrompt(message, content || fallback, { includeOwnReply: quotedOnly }); const existing = sessionKey ? sessions.get(sessionKey) : null; const turnStart = Date.now();