-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (46 loc) · 1.63 KB
/
main.py
File metadata and controls
59 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
"""Lark Bot with Claude Code integration.
Connects to Lark via WebSocket, listens for @mentions,
and responds using Claude Code CLI.
"""
import logging
import sys
import lark_oapi as lark
from bot.event_handler import create_event_handler
from config import Config
from lark_client.client import create_client
from lark_client.message_api import get_bot_info
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)
logger = logging.getLogger(__name__)
def main() -> None:
# Load config
config = Config()
logger.info("Config loaded: model=%s, max_turns=%d", config.claude_model, config.claude_max_turns)
# Create Lark REST client
client = create_client(config)
# Get bot's own identity
logger.info("Fetching bot info...")
bot_info = get_bot_info(client)
bot_open_id = bot_info.get("open_id", "")
bot_name = bot_info.get("app_name", "")
if not bot_open_id:
logger.error("Failed to get bot open_id. Check your LARK_APP_ID and LARK_APP_SECRET.")
sys.exit(1)
logger.info("Bot identity: name=%s, open_id=%s", bot_name, bot_open_id)
# Create event handler
event_handler = create_event_handler(client, config, bot_open_id, bot_name)
# Start WebSocket connection (blocking)
logger.info("Starting WebSocket connection...")
ws_client = lark.ws.Client(
app_id=config.lark_app_id,
app_secret=config.lark_app_secret,
event_handler=event_handler,
log_level=lark.LogLevel.INFO,
domain=config.lark_domain,
)
ws_client.start()
if __name__ == "__main__":
main()