channel/feishu/README.md
飞书Channel支持两种事件接收模式,可以根据部署环境灵活选择。
| 模式 | 适用场景 | 优点 | 缺点 |
|---|---|---|---|
| webhook | 生产环境 | 稳定可靠,官方推荐 | 需要公网IP或域名 |
| websocket | 本地开发 | 无需公网IP,开发便捷 | 需要额外依赖 |
在 config.json 中添加以下配置:
{
"channel_type": "feishu",
"feishu_app_id": "cli_xxxxx",
"feishu_app_secret": "your_app_secret",
"feishu_token": "your_verification_token",
"feishu_bot_name": "你的机器人名称",
"feishu_event_mode": "webhook",
"feishu_port": 9891
}
feishu_app_id: 飞书应用的App IDfeishu_app_secret: 飞书应用的App Secretfeishu_token: 事件订阅的Verification Tokenfeishu_bot_name: 机器人名称(用于群聊@判断)feishu_event_mode: 事件接收模式,可选值:
"websocket": 长连接模式(默认)"webhook": HTTP服务器模式feishu_port: webhook模式下的HTTP服务端口(默认9891){
"feishu_event_mode": "webhook",
"feishu_port": 9891
}
python3 app.py
服务将在 http://0.0.0.0:9891 启动。
http://your-domain:9891/im.message.receive_v1 (接收消息v2.0)pip install lark-oapi
{
"feishu_event_mode": "websocket"
}
python3 app.py
程序将自动建立与飞书开放平台的长连接。
im.message.receive_v1 (接收消息v2.0)从webhook模式切换到websocket模式(或反向切换):
config.json 中的 feishu_event_modelark-oapi 依赖重要: 同一时间只能使用一种模式,否则会导致消息重复接收。
两种模式都使用相同的消息去重机制:
ExpiredDict 存储已处理的消息ID[FeiShu] lark_oapi not installed
解决: 安装依赖 pip install lark-oapi
[Lark][ERROR] connect failed, err:[SSL:CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain
原因: 网络环境中存在自签名证书或SSL中间人代理(如企业代理、VPN等)
解决: 程序会自动检测SSL证书验证失败,并自动重试禁用证书验证的连接。无需手动配置。
当遇到证书错误时,日志会显示:
[FeiShu] SSL certificate verification disabled due to certificate error. This may happen when using corporate proxy or self-signed certificates.
这是正常现象,程序会自动处理并继续运行。
Address already in use
解决: 修改 feishu_port 配置或关闭占用端口的进程
im.message.receive_v1 事件im:message 权限