Skip to content

Refactor: Centralize callback query message extraction#71

Merged
vtvz merged 6 commits intomasterfrom
refactor-callback-message-extraction
Mar 14, 2026
Merged

Refactor: Centralize callback query message extraction#71
vtvz merged 6 commits intomasterfrom
refactor-callback-message-extraction

Conversation

@vtvz
Copy link
Owner

@vtvz vtvz commented Mar 14, 2026

Moves message extraction from individual inline button handlers to the centralized dispatcher in bot.rs. Eliminates ~170 lines of repetitive boilerplate code across 13 handlers.

Move message extraction from individual inline button handlers to the
centralized dispatcher in bot.rs. This eliminates repetitive boilerplate
code and simplifies handler signatures by passing Message directly.
@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4400aad0-a977-4ede-be81-f9fbd39b48f3

📥 Commits

Reviewing files that changed from the base of the PR and between 3916d97 and 1f7bc98.

📒 Files selected for processing (15)
  • .gitignore
  • Justfile
  • src/telegram/actions/admin_users/details.rs
  • src/telegram/actions/admin_users/list.rs
  • src/telegram/actions/ai_slop_detection.rs
  • src/telegram/actions/analyze.rs
  • src/telegram/actions/dislike.rs
  • src/telegram/actions/ignore.rs
  • src/telegram/actions/magic.rs
  • src/telegram/actions/recommendasion.rs
  • src/telegram/actions/skippage.rs
  • src/telegram/actions/song_links.rs
  • src/telegram/actions/word_definition.rs
  • src/telegram/handlers/inline_buttons.rs
  • src/workers/bot.rs

📝 Walkthrough

Walkthrough

This PR refactors Telegram inline button action handlers to accept Message parameters directly rather than extracting messages from CallbackQuery objects, with central message extraction occurring in the bot worker. Adds minor build configurations (.gitignore rule for ".claude", lazysql recipe).

Changes

Cohort / File(s) Summary
Build and Configuration
.gitignore, Justfile
Added ignore rule for ".claude" file pattern; added new lazysql recipe invoking PostgreSQL connection.
Telegram Action Handlers (Message Parameter Addition)
src/telegram/actions/admin_users/details.rs, src/telegram/actions/admin_users/list.rs, src/telegram/actions/ai_slop_detection.rs, src/telegram/actions/analyze.rs, src/telegram/actions/dislike.rs, src/telegram/actions/ignore.rs, src/telegram/actions/magic.rs, src/telegram/actions/recommendasion.rs, src/telegram/actions/skippage.rs, src/telegram/actions/song_links.rs, src/telegram/actions/word_definition.rs
Updated all handle_inline function signatures to accept explicit m: Message parameter; removed code paths that extracted message from CallbackQuery using q.get_message(); replaced all message operations to use the provided m parameter directly.
Telegram Handler Coordinator
src/telegram/handlers/inline_buttons.rs
Extended handle function to accept m: Message parameter and thread it through all downstream action handler calls (11+ action invocations updated with the new parameter).
Bot Worker
src/workers/bot.rs
Added guard for absent message in callback_query branch with early-exit alert response; extracts message and derives chat_id from it; invokes inline_buttons::handle with new m parameter; added error handling with localized error messages and respects link preview settings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #59: Modifies the same Telegram action handlers (e.g., src/telegram/actions/analyze.rs), updating internal types and dependencies within affected functions.
  • PR #62: Updates Telegram inline-handling code and the same action handler files, with overlapping modifications to callback and message processing logic.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: centralizing callback query message extraction from individual handlers to a dispatcher.
Description check ✅ Passed The description is directly related to the changeset, explaining the refactoring objective and benefit of eliminating repetitive code across multiple handlers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-callback-message-extraction
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

vtvz added 3 commits March 14, 2026 14:33
Use t!("error.general") instead of inline formatdoc! for consistency
with the rest of the codebase. Add documentation comment explaining
when callback query messages can be inaccessible.
@vtvz
Copy link
Owner Author

vtvz commented Mar 14, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/workers/bot.rs (1)

1-1: ⚠️ Potential issue | 🟠 Major

Remove the stale formatdoc import.

cargo clippy --all-targets --all-features --no-deps -- -D warnings is already failing on this unused import, so the PR cannot go green until it is removed.

🧹 Minimal fix
-use indoc::formatdoc;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/workers/bot.rs` at line 1, Remove the unused import `formatdoc` from the
top of the file to silence the Clippy warning: locate the `use
indoc::formatdoc;` statement in src/workers/bot.rs and delete it (or replace it
with only the necessary indoc imports if any are used elsewhere in the file),
then run cargo clippy to confirm the warning is resolved.
src/telegram/handlers/inline_buttons.rs (1)

26-108: ⚠️ Potential issue | 🟠 Major

Centralize callback acknowledgements in the dispatcher.

After this refactor, six dispatched handlers (handle_inline_regenerate, admin user paging/details, dislike, song_links, skippage) no longer call answer_callback_query, indicated by their unused _q parameters. Only word_definition::handle_inline_list and ai_slop_detection::handle_inline acknowledge callbacks themselves. Telegram keeps the pressed button in its loading state until the callback is acknowledged, so these paths now have inconsistent UX. Adding one empty ack here before dispatch would make the behavior uniform and lets downstream handlers drop their unused _q parameter.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/telegram/handlers/inline_buttons.rs` around lines 26 - 108, Add a uniform
callback acknowledgment in the dispatcher before it matches on
AdminInlineButtons so Telegram no longer leaves buttons loading: call
app.bot().answer_callback_query(q.id.clone()).await? (or the equivalent empty
ack used elsewhere) immediately after verifying admin and before dispatching to
handlers like actions::word_definition::handle_inline_regenerate,
actions::admin_users::list::handle_inline,
actions::admin_users::details::handle_inline, and others; remove or keep
downstream answer_callback_query calls as desired so downstream handlers (e.g.,
handle_inline_list, ai_slop_detection::handle_inline) can continue to
acknowledge themselves or rely on this centralized ack for consistent UX.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/workers/bot.rs`:
- Around line 111-114: Replace the localized call
t!("error.inaccessible-message", locale = "en") with a plain English string
literal for this internal Telegram failure path: update the chain on
app.bot().answer_callback_query(q.id.clone()).text(...) to pass a Rust-side
constant (e.g., "Message is inaccessible") instead of routing through t!,
leaving answer_callback_query and show_alert(true) unchanged; remove the
dependency on the "error.inaccessible-message" catalog entry so the alert
remains a fixed English technical message.

---

Outside diff comments:
In `@src/telegram/handlers/inline_buttons.rs`:
- Around line 26-108: Add a uniform callback acknowledgment in the dispatcher
before it matches on AdminInlineButtons so Telegram no longer leaves buttons
loading: call app.bot().answer_callback_query(q.id.clone()).await? (or the
equivalent empty ack used elsewhere) immediately after verifying admin and
before dispatching to handlers like
actions::word_definition::handle_inline_regenerate,
actions::admin_users::list::handle_inline,
actions::admin_users::details::handle_inline, and others; remove or keep
downstream answer_callback_query calls as desired so downstream handlers (e.g.,
handle_inline_list, ai_slop_detection::handle_inline) can continue to
acknowledge themselves or rely on this centralized ack for consistent UX.

In `@src/workers/bot.rs`:
- Line 1: Remove the unused import `formatdoc` from the top of the file to
silence the Clippy warning: locate the `use indoc::formatdoc;` statement in
src/workers/bot.rs and delete it (or replace it with only the necessary indoc
imports if any are used elsewhere in the file), then run cargo clippy to confirm
the warning is resolved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1cb15124-b2b7-42e7-bdca-eceb94b82a33

📥 Commits

Reviewing files that changed from the base of the PR and between 3916d97 and 4a83b37.

📒 Files selected for processing (16)
  • .gitignore
  • Justfile
  • locales/errors.yml
  • src/telegram/actions/admin_users/details.rs
  • src/telegram/actions/admin_users/list.rs
  • src/telegram/actions/ai_slop_detection.rs
  • src/telegram/actions/analyze.rs
  • src/telegram/actions/dislike.rs
  • src/telegram/actions/ignore.rs
  • src/telegram/actions/magic.rs
  • src/telegram/actions/recommendasion.rs
  • src/telegram/actions/skippage.rs
  • src/telegram/actions/song_links.rs
  • src/telegram/actions/word_definition.rs
  • src/telegram/handlers/inline_buttons.rs
  • src/workers/bot.rs

No longer needed after switching error messages to use t!() macro
and plain text for inaccessible message edge case.
@vtvz
Copy link
Owner Author

vtvz commented Mar 14, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@vtvz vtvz self-assigned this Mar 14, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/workers/bot.rs`:
- Line 123: The current assignment pins and boxes the future when calling
rustify::telegram::handlers::inline_buttons::handle, causing an unnecessary heap
allocation; change the call site that sets let result = Box::pin(...).await to
directly await the async function (i.e., call
rustify::telegram::handlers::inline_buttons::handle(...).await) so the future is
not boxed—update the expression that produces result accordingly.
- Around line 119-121: The code is passing m.chat.id into App::user_state which
keys state by the clicking user; change it to derive the user id from m.from
(the callback sender) and pass that to App::user_state (e.g., use the User id
from m.from, converting to string), handling the Option<User> case appropriately
(return an error or early-exit if m.from is None) so locale/account/error
handling runs under the correct identity; update the variables around
chat_id/m.chat.id references to use the derived user_id when calling
App::user_state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2705c2c6-d63c-44f2-a66d-0a47559d0abd

📥 Commits

Reviewing files that changed from the base of the PR and between 4a83b37 and 96fddc2.

📒 Files selected for processing (1)
  • src/workers/bot.rs

@vtvz vtvz marked this pull request as ready for review March 14, 2026 16:02
@vtvz
Copy link
Owner Author

vtvz commented Mar 14, 2026

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

✅ Actions performed

Full review triggered.

@vtvz vtvz merged commit 27c59a7 into master Mar 14, 2026
4 checks passed
@vtvz vtvz deleted the refactor-callback-message-extraction branch March 14, 2026 16:14
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