feat(notify): urgent priority alert for assigned admins#24
Conversation
- When inbound message arrives in a conversation with urgent priority and an assigned admin, bot sends a reminder message in the Topic mentioning the assignee ID - Alert fires after successful delivery, before AI draft generation - Alert failure does not break main message flow - Add /mine, /search, /audit to Telegram bot menu commands - 2 new test cases: urgent+assignee condition, menu command coverage Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
概述在 Telegram 机器人菜单的 变更内容紧急提醒与新增机器人命令
估计代码审查工作量🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/channels/telegram/messages.ts`:
- Around line 302-312: The urgent reminder logic in messages.ts is currently
outside the successful delivery flow, so it can run after copyWithDelivery()
failures and miss the rebuilt-topic success path. Move the telegram alert tied
to bundle.conversation.priority and assignedAdminId into the actual “delivered
successfully” branches in the main send flow, or gate it with a
deliveredToManagement flag that is set only after a successful send. Keep the
reminder near ctx.api.sendMessage and topic.messageThreadId handling so it
executes only after successful delivery, including after Topic rebuild recovery.
In `@test/core.test.ts`:
- Around line 736-752: The current test only checks priority and assignee
persistence in ConversationService and does not exercise the Telegram alert
path. Update the test around handlePrivateMessage to simulate an incoming
Telegram message, then assert that the urgent reminder is actually sent to the
management group using the current conversation’s message_thread_id/topic. Also
verify the reminder is only emitted after successful delivery and that no alert
is sent on failure, since the production flow swallows reminder exceptions.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: ec9bf539-8ba8-40c0-bc62-9b1e7511ff8f
📒 Files selected for processing (3)
src/channels/telegram/menu.tssrc/channels/telegram/messages.tstest/core.test.ts
| if (bundle.conversation.priority === "urgent" && bundle.conversation.assignedAdminId) { | ||
| try { | ||
| await ctx.api.sendMessage( | ||
| deps.config.TELEGRAM_MANAGEMENT_CHAT_ID, | ||
| `紧急消息提醒:负责人 ${bundle.conversation.assignedAdminId} 请关注本会话。`, | ||
| { message_thread_id: topic.messageThreadId }, | ||
| ); | ||
| } catch { | ||
| // 提醒失败不影响主流程 | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
把紧急提醒放到“投递成功”分支里,而不是放在整个 try/catch 之后。
现在这段代码有两个相反但都错误的结果:如果 copyWithDelivery() 失败并走了 Line 280-Line 299 的错误处理,这里仍会继续发提醒;而如果首个 Topic 失效并走了 Line 220-Line 265 的重建成功路径,这里又永远执行不到。这样既不满足“成功投递后再提醒”,也会漏掉重建 Topic 后的成功投递。建议用 deliveredToManagement 标记,或把提醒抽到每个成功投递分支里,在任何早退之前执行。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/channels/telegram/messages.ts` around lines 302 - 312, The urgent
reminder logic in messages.ts is currently outside the successful delivery flow,
so it can run after copyWithDelivery() failures and miss the rebuilt-topic
success path. Move the telegram alert tied to bundle.conversation.priority and
assignedAdminId into the actual “delivered successfully” branches in the main
send flow, or gate it with a deliveredToManagement flag that is set only after a
successful send. Keep the reminder near ctx.api.sendMessage and
topic.messageThreadId handling so it executes only after successful delivery,
including after Topic rebuild recovery.
| it("supports urgent priority with assignee for alert trigger", async () => { | ||
| const service = new ConversationService(handle.db, 30); | ||
| const bundle = await service.getOrCreateConversation({ | ||
| platform: "telegram", | ||
| externalUserId: "700", | ||
| displayName: "UrgentUser", | ||
| }); | ||
| service.setPriority(bundle.conversation.id, "urgent"); | ||
| service.assign(bundle.conversation.id, "500"); | ||
|
|
||
| const conv = await service.getConversation(bundle.conversation.id); | ||
| assert.ok(conv); | ||
| assert.equal(conv!.priority, "urgent"); | ||
| assert.equal(conv!.assignedAdminId, "500"); | ||
| // Alert condition: priority === "urgent" && assignedAdminId is truthy | ||
| assert.ok(conv!.priority === "urgent" && conv!.assignedAdminId !== null); | ||
| }); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
这个用例没有覆盖新增的 Telegram 紧急提醒行为。
它只验证了 priority 和 assignedAdminId 的持久化,然后在测试里重复了一遍触发条件;但并没有调用 handlePrivateMessage(),也没有断言提醒是否真的发到了管理群对应 message_thread_id。这条链路正好是这次 PR 的核心改动,而且生产代码会吞掉提醒异常,单靠当前测试抓不到错线程/错时机/失败后仍提醒这类回归。建议补一个消息流测试,直接断言:成功投递后才发送提醒,并且提醒发到当前会话 Topic。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/core.test.ts` around lines 736 - 752, The current test only checks
priority and assignee persistence in ConversationService and does not exercise
the Telegram alert path. Update the test around handlePrivateMessage to simulate
an incoming Telegram message, then assert that the urgent reminder is actually
sent to the management group using the current conversation’s
message_thread_id/topic. Also verify the reminder is only emitted after
successful delivery and that no alert is sent on failure, since the production
flow swallows reminder exceptions.
Summary
urgentpriority AND has an assigned admin, bot sends a reminder message in the Topic: "紧急消息提醒:负责人 {id} 请关注本会话。"/mine,/search,/auditto both private and admin Telegram bot menu commandsProblem
Admins in the Forum group see Topic updates via Telegram native notifications, but there was no way to highlight urgent conversations. In multi-admin teams, the assigned admin might miss urgent messages buried among many active Topics.
How it works
/priority urgenton a conversation/assign <user_id>to assign themselvesVerification
npm run verifypassed (check + 50 tests + audit 0 vulns)Summary by CodeRabbit
新功能
Bug 修复