Skip to content

fix(mx-space): pass unhandled text updates to next middleware - #126

Open
specialhua wants to merge 1 commit into
mx-space:mainfrom
specialhua:fix/text-handler-swallows-commands
Open

specialhua wants to merge 1 commit into
mx-space:mainfrom
specialhua:fix/text-handler-swallows-commands

Conversation

@specialhua

Copy link
Copy Markdown

Problem

Module commands never get a reply. Sending /mx_stat, /mx_get_detail, /mx_get_posts, /mx_get_notes or /hitokoto to the bot does nothing, in private chats and in groups. No error is logged. /start and /help still work.

Cause

bindEvents in src/modules/mx-space/index.ts registers tgBot.on("text", ...) for replying to comments and rejecting friend links. The handler returns early for any message it does not consume (not from the owner, or not a reply to a tracked message), and it never calls next().

Registration order makes this swallow every command:

  • bindEvents registers the text handler synchronously.
  • bindCommandssetTGBotCommands first awaits getMyCommands/setMyCommands, and only then calls tgBot.command(...).

So the text handler always sits in front of the module commands. A command is also a text message, so it stops there and the command handler never runs. /help and /start are registered earlier in initTgBot, which is why they still work.

History, for context:

  • eaee94b (feat: comment reply) added a bot-level tgBot.on('text', ctx => botEventBus.emit('text', ctx)) forwarder in src/bot/index.ts, also without next(). It was registered before command('help'), so at that point every command except /start was swallowed.
  • 2d25ff7 moved the handler into the mx-space module. /help started working again, but the module commands are still swallowed.

Fix

The handler now takes next and calls return next() on each early-return path for messages it does not handle. A short comment explains why.

Nothing changes for messages the handler does consume. When the owner replies to a tracked comment or link-audit message, the handler still handles it and stops there.

Verification

  • pnpm typecheck, pnpm build, and eslint / prettier --check on the changed file all pass.

  • Offline check against the real module, no network. I bundled a small script with the project's tsdown settings. It calls the real register from src/modules/mx-space, stubs Telegram.prototype.callApi, and feeds /mx_get_detail from ownerId in a private chat through bot.handleUpdate:

    Telegram API calls
    main [] (command swallowed)
    this PR [sendMessage] (usage reply sent)
  • On a real deployment (Docker, Node 22), /mx_stat got no reply before this change and replies normally after it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LPQRktGEiEMKSFtRWjgh45

The owner comment-reply `text` handler returned without calling `next()`
for every message it did not consume. It is registered before the
commands in `bindCommands` (which awaits `setMyCommands` first), so every
module command such as /mx_stat, /mx_get_detail and /hitokoto was
swallowed and never answered.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LPQRktGEiEMKSFtRWjgh45
@safedep

safedep Bot commented Sep 13, 2026

Copy link
Copy Markdown

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep GitHub App

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant