Skip to content

hotfix: check if the group is in the backend db#80

Merged
toto04 merged 5 commits intomainfrom
hotfix-temp-mw
Apr 11, 2026
Merged

hotfix: check if the group is in the backend db#80
toto04 merged 5 commits intomainfrom
hotfix-temp-mw

Conversation

@lorenzocorallo
Copy link
Copy Markdown
Member

No description provided.

@lorenzocorallo lorenzocorallo requested a review from toto04 April 11, 2026 14:03
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 11, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 03a4961f-661c-48f0-95ad-d168dc6b604c

📥 Commits

Reviewing files that changed from the base of the PR and between 5e421db and 803dcf4.

📒 Files selected for processing (2)
  • src/middlewares/bot-membership-handler.ts
  • src/middlewares/message-link.ts

Walkthrough

Added backend verification to a bot middleware that previously relied on a TEMP_redis flag, and bumped @polinetwork/backend in package.json. When TEMP_redis indicates a cached chat, the middleware now queries the backend and only skips membership handling if the group exists there.

Changes

Cohort / File(s) Summary
Dependency Update
package.json
Bumped @polinetwork/backend from ^0.15.5 to ^0.15.7.
Membership middleware
src/middlewares/bot-membership-handler.ts
When TEMP_redis.has(ctx.chat.id) is true, call api.tg.groups.getById({ telegramId }) and only return next() if a non-null group is returned; otherwise proceed with existing admin/member checks and possible GroupManagement.create(...) and TEMP_redis.write(...).
Invite-link resolution
src/middlewares/message-link.ts
Replace indexed query result with a single dbGroup value and use dbGroup?.link as fallback for inviteLink (now chat.invite_link ?? dbGroup?.link).

Sequence Diagram

sequenceDiagram
    participant Client
    participant Middleware
    participant TEMP_redis
    participant Backend_API
    participant Membership_Handler

    Client->>Middleware: Request (ctx.chat.id)
    Middleware->>TEMP_redis: has(chat_key)?
    alt TEMP_redis true
        Middleware->>Backend_API: api.tg.groups.getById({ telegramId })
        Backend_API-->>Middleware: Group or null
        alt Group exists
            Middleware->>Client: next() (skip membership handling)
        else Group missing
            Middleware->>Membership_Handler: perform admin/member checks
            Membership_Handler->>Membership_Handler: create group / TEMP_redis.write if needed
        end
    else TEMP_redis false
        Middleware->>Membership_Handler: perform admin/member checks
    end
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a backend database verification step to check if a group exists before proceeding with membership handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

Copy link
Copy Markdown
Contributor

@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

🤖 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/middlewares/bot-membership-handler.ts`:
- Around line 54-57: The middleware currently calls
api.tg.groups.getById.query(...) directly which can throw and break the filter;
update the call in bot-membership-handler to handle transient backend errors
(e.g., append .catch(() => null) or wrap in try/catch) so that backendGroup
becomes null on failure and the middleware falls through to the create flow;
target the line using TEMP_redis, api.tg.groups.getById.query and the
backendGroup variable and ensure you still return next() only when backendGroup
is non-null.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 42b65886-f69b-448f-afac-ba83af2c1098

📥 Commits

Reviewing files that changed from the base of the PR and between edd8388 and 5e421db.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json
  • src/middlewares/bot-membership-handler.ts

Comment thread src/middlewares/bot-membership-handler.ts
@toto04 toto04 enabled auto-merge (squash) April 11, 2026 14:13
@toto04 toto04 merged commit 4df4990 into main Apr 11, 2026
1 of 2 checks passed
@toto04 toto04 deleted the hotfix-temp-mw branch April 11, 2026 14: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.

2 participants