發佈 0.1.13:只引用+tag 沒打字時,直接把引用內容當輸入

This commit is contained in:
2026-08-17 16:59:06 +08:00
parent 24c66130d0
commit a49f403a48
2 changed files with 16 additions and 5 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "telegram-codex-bot", "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", "description": "Telegram bot powered by the local Codex CLI — zero-dependency, pm2-managed, with a built-in PM2 web viewer",
"license": "MIT", "license": "MIT",
"type": "commonjs", "type": "commonjs",
+15 -4
View File
@@ -210,13 +210,19 @@ function startBot(config) {
return null; 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 from = message.from || {};
const name = [from.first_name, from.last_name].filter(Boolean).join(' ') || '未知使用者'; const name = [from.first_name, from.last_name].filter(Boolean).join(' ') || '未知使用者';
const sender = from.username ? `${name}@${from.username}` : name; const sender = from.username ? `${name}@${from.username}` : name;
const parts = [OUTBOX_RULE]; const parts = [OUTBOX_RULE];
const replied = message.reply_to_message; 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}`); parts.push(`【被回覆的訊息】\n${replied.text || replied.caption}`);
} }
if (message.quote?.text) { if (message.quote?.text) {
@@ -291,7 +297,9 @@ function startBot(config) {
await t.sendMessage(chatId, statusText(chatId), { replyTo: message.message_id }); await t.sendMessage(chatId, statusText(chatId), { replyTo: message.message_id });
return; 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 }); await t.sendMessage(chatId, HELP_TEXT, { replyTo: message.message_id });
return; return;
} }
@@ -324,7 +332,10 @@ function startBot(config) {
images.push(dest); 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 existing = sessionKey ? sessions.get(sessionKey) : null;
const turnStart = Date.now(); const turnStart = Date.now();