Files
company-kb/tools/kb-bot/subscribe.sh
yangqianqian 84f7950589 Initial commit: company-kb framework
- 完整的知识库框架(P0-P5 路线图)
- 12篇治理文档
- 工具脚本(kb-init.sh, kb-lint-fm.py, feishu-sync.py, kb-bot)
- 7个 Claude 命令
- 示例项目和测试项目(wanniu-l1)
- 契约文件(meta/kb-contract.yaml)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-16 18:24:39 +08:00

36 lines
1.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# subscribe.sh —— 飞书群消息长连接订阅WebSocket无需公网回调
#
# 起一个常驻长连接,把 @机器人 的群消息事件逐条落到 events/ 目录,
# 由 handle.py 消费。单实例锁由 lark-cli 保证(勿加 --force
#
# 用法:
# bash tools/kb-bot/subscribe.sh # 前台跑
# nohup bash tools/kb-bot/subscribe.sh & # 后台常驻
#
# 依赖: lark-cli 已装且 bot 身份可用lark-cli auth status
set -euo pipefail
BOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
EVENTS_DIR="$BOT_DIR/events"
mkdir -p "$EVENTS_DIR"
export PATH="$HOME/.npm-global/bin:$PATH"
if ! command -v lark-cli >/dev/null 2>&1; then
echo "ERROR: lark-cli 不在 PATH。请先安装并 lark-cli auth login。" >&2
exit 2
fi
echo "[kb-bot] 订阅飞书群消息事件 → $EVENTS_DIR"
echo "[kb-bot] 只收 im.message.receive_v1Ctrl-C 停止。"
# --output-dir: 每个事件写成独立 JSON 文件handle.py 轮询消费
# --compact: 扁平化,提取 text去噪
# --quiet: 抑制 stderr 状态噪音(避免日志泄露)
exec lark-cli event +subscribe \
--event-types im.message.receive_v1 \
--compact \
--quiet \
--output-dir "$EVENTS_DIR"