diff --git a/package.json b/package.json index c0e1cac..1f4311c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "telegram-codex-bot", - "version": "0.1.9", + "version": "0.1.10", "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 8cdd35b..e8f0c96 100644 --- a/src/bot.js +++ b/src/bot.js @@ -111,14 +111,21 @@ function startBot(config) { function shouldRespond(message) { if (message.chat.type === 'private') return true; - if (message.reply_to_message?.from?.id === botId) return true; const text = message.text || message.caption || ''; const entities = message.entities || message.caption_entities || []; - return entities.some((e) => - (e.type === 'mention' && - text.slice(e.offset, e.offset + e.length).toLowerCase() === `@${botUsername.toLowerCase()}`) || - (e.type === 'text_mention' && e.user?.id === botId) - ); + // 訊息中所有被 tag 的 bot(Telegram bot username 一定以 bot 結尾; + // tag 到一般使用者不算,不影響回覆觸發) + const botMentions = entities + .filter((e) => e.type === 'mention') + .map((e) => text.slice(e.offset + 1, e.offset + e.length)) + .filter((u) => /bot$/i.test(u)); + if (botMentions.length > 0) { + // 有明確 tag 時以 tag 為準:只有第一個被 tag 的 bot 回應。 + // 就算這則訊息是回覆我的(例如回覆我的訊息但 tag 別的 bot),我也讓位。 + return botMentions[0].toLowerCase() === botUsername.toLowerCase(); + } + if (message.reply_to_message?.from?.id === botId) return true; + return entities.some((e) => e.type === 'text_mention' && e.user?.id === botId); } function stripMention(text) {