Skip to content

feat(tutorbot): add Zulip channel support#452

Merged
pancacake merged 1 commit into
HKUDS:devfrom
wedone:feat/add-zulip-channel
May 8, 2026
Merged

feat(tutorbot): add Zulip channel support#452
pancacake merged 1 commit into
HKUDS:devfrom
wedone:feat/add-zulip-channel

Conversation

@wedone

@wedone wedone commented May 6, 2026

Copy link
Copy Markdown
Contributor

Description

为 DeepTutor tutorbot 添加 Zulip 作为新的消息频道。

为何选择 Zulip?

1. 原生 KaTeX/LaTeX 支持(核心特性)

这是选择 Zulip 的首要原因。主流 IM 工具(Slack、Discord、Microsoft Teams、飞书、钉钉等)都不原生支持数学公式渲染,而 Zulip 内置 KaTeX 引擎:

  • 内联公式:$$E=mc^2$$
  • 块级公式:```math \int_a^b f(t) dt ```
  • 对于教育场景(数学、物理、化学、工程)至关重要

2. 100% 开源(无"Open Core"陷阱)

  • 许可证:Apache 2.0
  • 服务端:完全开源,可自托管
  • 客户端:全平台开源
  • 数据主权:自托管时完全掌控数据

3. 免费额度友好

  • Zulip Cloud 免费版:10,000 条可搜索消息,5GB 存储,国内可直连
  • 免费标准版资格:开源项目、学术研究、教育机构、非营利组织
  • 自托管:所有功能免费,无限消息

4. 话题式讨论(适合教育场景)

  • 每个问题独立话题,互不干扰
  • 学生可快速找到类似问答
  • 支持话题移动/拆分/合并、已解决标记
  • 历史讨论成为知识库

5. 自托管选项

  • 可部署在国内服务器稳定访问
  • Docker 一键部署
  • 支持纯内网环境

已实现功能

功能 说明
私信和频道消息 支持私聊和 Stream 消息
事件队列 API register/get_events/deregister 可靠监听
无限循环保护 三层防护(max_message_id、自身消息过滤、去重)
文件上传下载 可配置超时和重试机制
权限控制 allow_from 支持 user_id 和 email
频道群组策略 mention(仅@时回复)/ open(回复所有)
数学公式转换 KaTeX/LaTeX 双向转换
输入状态 私信输入指示器

技术亮点

  • 使用 call_endpoint 配置自定义超时,而非 send_message/upload_file(默认 15s 超时会导致文件上传 ReadTimeout)
  • 通过 run_in_executorrun_coroutine_threadsafe 实现同步-异步桥接
  • BAD_EVENT_QUEUE_ID 错误时自动重新注册事件队列

Related Issues

  • None

Module(s) Affected

  • agents (tutorbot channels)
  • tests

Checklist

  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes. (76 unit tests)
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

  • 已在 Zulip Cloud 和自托管服务器上测试
  • 76 个单元测试全部通过
  • pre-commit 检查全部通过(ruff、mypy、bandit 等)

Add Zulip as a new messaging channel for DeepTutor tutorbot.

Features:
- Private message and stream message support
- Event queue API (register/get_events/deregister) for reliable message listening
- Three-layer infinite loop protection (max_message_id, own message filter, dedup)
- File upload/download with configurable timeout and retry
- Permission control via allow_from (supports both user_id and email)
- Stream group policy: mention (respond only when mentioned) / open (respond to all)
- KaTeX/LaTeX bidirectional conversion for math formulas
- Typing indicator support for private chats (Zulip native API)

Technical highlights:
- Uses call_endpoint with custom timeout instead of send_message/upload_file
  (default 15s timeout causes ReadTimeout on file uploads)
- Sync-async bridging via run_in_executor and run_coroutine_threadsafe
- Automatic event queue re-registration on BAD_EVENT_QUEUE_ID error

Tests: 88 unit tests covering all core functionality
@wedone wedone changed the base branch from main to dev May 6, 2026 14:45
@pancacake pancacake merged commit accfab9 into HKUDS:dev May 8, 2026
7 checks passed
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