Skip to content

feat(notify): urgent priority alert for assigned admins#24

Merged
one-ea merged 1 commit into
mainfrom
260629-feat-priority-alert
Jun 29, 2026
Merged

feat(notify): urgent priority alert for assigned admins#24
one-ea merged 1 commit into
mainfrom
260629-feat-priority-alert

Conversation

@one-ea

@one-ea one-ea commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • When an inbound message arrives in a conversation with urgent priority AND has an assigned admin, bot sends a reminder message in the Topic: "紧急消息提醒:负责人 {id} 请关注本会话。"
  • Alert fires after successful message delivery, before AI draft generation
  • Alert failure is silently caught — does not break main message flow
  • Added /mine, /search, /audit to both private and admin Telegram bot menu commands

Problem

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

  1. Admin sets /priority urgent on a conversation
  2. Admin sets /assign <user_id> to assign themselves
  3. When the external user sends a message, bot delivers it to the Topic as usual
  4. Bot then sends a reminder message in the same Topic mentioning the assignee ID
  5. Telegram notifies group members about the new message in the Topic

Verification

  • npm run verify passed (check + 50 tests + audit 0 vulns)
  • 2 new test cases: urgent+assignee condition validation, menu command coverage for /mine /search /audit

Summary by CodeRabbit

  • 新功能

    • Telegram 命令菜单新增了搜索历史、查看我的会话和审计记录相关入口。
    • 当会话处于紧急优先级且已分配负责人时,会自动向管理群发送提醒消息。
  • Bug 修复

    • 更新了管理员命令中的身份说明文本,使其显示更准确。

- 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>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

概述

在 Telegram 机器人菜单的 privateBotCommandsadminBotCommands 中新增 searchmineaudit 三个命令条目,并在 handlePrivateMessage 中增加当会话优先级为 urgent 且存在指派管理员时向对应线程发送紧急提醒的逻辑。

变更内容

紧急提醒与新增机器人命令

层 / 文件 说明
新增 Telegram 菜单命令条目
src/channels/telegram/menu.ts
privateBotCommandsadminBotCommands 各新增 searchmineaudit 三个命令条目;adminBotCommandswhoami 描述由"用户 ID"改为"管理员 ID"。
handlePrivateMessage 紧急提醒逻辑
src/channels/telegram/messages.ts
消息投递至管理群后新增条件分支:会话 priorityurgent 且存在 assignedAdminId 时,调用 ctx.api.sendMessage 向对应 topic 线程发送提醒,异常被捕获忽略不影响后续流程。
测试用例扩展
test/core.test.ts
新增 urgent 优先级+指派管理员会话断言用例,以及对 adminBotCommands 包含 search/mine/audit 的断言。

估计代码审查工作量

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了核心变更:为已分配管理员的紧急会话新增提醒。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 260629-feat-priority-alert

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.

@one-ea one-ea merged commit bd46ed6 into main Jun 29, 2026
3 of 4 checks passed
@one-ea one-ea deleted the 260629-feat-priority-alert branch June 29, 2026 22:00

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 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

📥 Commits

Reviewing files that changed from the base of the PR and between e4cb408 and 4e22eb1.

📒 Files selected for processing (3)
  • src/channels/telegram/menu.ts
  • src/channels/telegram/messages.ts
  • test/core.test.ts

Comment on lines +302 to +312
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 {
// 提醒失败不影响主流程
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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.

Comment thread test/core.test.ts
Comment on lines +736 to +752
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);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

这个用例没有覆盖新增的 Telegram 紧急提醒行为。

它只验证了 priorityassignedAdminId 的持久化,然后在测试里重复了一遍触发条件;但并没有调用 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.

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