2.4 KiB
2.4 KiB
PhoneWork
Feishu bot integration with Claude Code CLI.
Architecture
┌─────────────┐ WebSocket ┌──────────────┐ LangChain ┌─────────────┐
│ Feishu │ ◄──────────────► │ FastAPI │ ◄──────────────► │ LLM API │
│ (client) │ │ (server) │ │ (OpenAI) │
└─────────────┘ └──────────────┘ └─────────────┘
│
▼
┌─────────────┐
│ Claude Code │
│ (PTY) │
└─────────────┘
Components:
| Module | Purpose |
|---|---|
main.py |
FastAPI entry point, starts WebSocket client + session manager |
bot/handler.py |
Receives Feishu events, dispatches to orchestrator |
bot/feishu.py |
Sends replies back to Feishu chats |
orchestrator/agent.py |
LangChain agent with per-user history + active session tracking |
orchestrator/tools.py |
Tools: create_conversation, send_to_conversation, close_conversation |
agent/manager.py |
Session registry with idle timeout reaper |
agent/pty_process.py |
Runs claude -p headlessly, manages session continuity |
Flow: User message → Feishu WebSocket → Handler → Orchestrator (LLM decides action) → Tool → Session Manager → Claude Code PTY → Response back to Feishu
Setup
-
Feishu App: Create at https://open.feishu.cn
- Enable Bot capability + long-connection event subscription
- Get
FEISHU_APP_IDandFEISHU_APP_SECRET
-
LLM Endpoint: Configure OpenAI-compatible endpoint
OPENAI_BASE_URL,OPENAI_API_KEY,OPENAI_MODEL
-
Claude Code CLI: Install and authenticate
claudecommand -
Configuration:
cp keyring.example.yaml keyring.yaml # Edit keyring.yaml with your credentials -
Run:
pip install -r requirements.txt python main.py
Requirements: Python 3.11+