JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
feat: 支持定时任务发送到飞书
Haowei_Du75c5a4c4bcd6
diff --git a/jiuwenclaw/channel/feishu.py b/jiuwenclaw/channel/feishu.pyindex 6449dfa357..2df795d67d 100644--- a/jiuwenclaw/channel/feishu.py+++ b/jiuwenclaw/channel/feishu.py@@ -579,6 +579,22 @@ class FeishuChannel(BaseChannel):getattr(getattr(sender, "sender_id", None), "open_id", None) or "")+ # 将最近一次可回发的飞书身份写入 config.yaml,供 cron 推送时使用+ try:+ from jiuwenclaw.config import update_channel_in_config++ update_channel_in_config(+ "feishu",+ {+ "last_chat_id": getattr(message, "chat_id", None) or "",+ "last_open_id": open_id or "",+ "last_message_id": getattr(message, "message_id", None) or "",+ },+ )+ except Exception:+ # 不影响正常收消息+ pass+# 处理消息:将平台身份写入 metadata,供回发时使用(与 session_id 解耦,\new_session 后仍可正确回发)await self._handle_message(chat_id=message.chat_id,diff --git a/jiuwenclaw/channel/xiaoyi_channel.py b/jiuwenclaw/channel/xiaoyi_channel.pyindex 5c6d60b37d..fb7319b3d4 100644--- a/jiuwenclaw/channel/xiaoyi_channel.py+++ b/jiuwenclaw/channel/xiaoyi_channel.py@@ -300,6 +300,20 @@ class XiaoyiChannel(BaseChannel):self._session_task_map[session_id] = task_id+ # 将最近一次可回发的小艺身份写入 config.yaml,供 cron 推送时使用+ try:+ from jiuwenclaw.config import update_channel_in_config++ update_channel_in_config(+ "xiaoyi",+ {+ "last_session_id": session_id or "",+ "last_task_id": task_id or "",+ },+ )+ except Exception:+ pass+# 平台身份写入 metadata,供回发时使用(与 session_id 解耦,\new_session 后仍可正确回发)user_message = Message(id=message.get("id", ""),diff --git a/jiuwenclaw/gateway/cron/scheduler.py b/jiuwenclaw/gateway/cron/scheduler.pyindex ccdbcaa20d..d3b5fefdc7 100644--- a/jiuwenclaw/gateway/cron/scheduler.py+++ b/jiuwenclaw/gateway/cron/scheduler.py@@ -354,6 +354,34 @@ class CronSchedulerService:channel_id = (job.targets or "").strip()if not channel_id:return++ # 针对 feishu/xiaoyi:从 config.yaml 取最近一次可回发的平台身份,写入 metadata+ # 这样即使 cron 推送没有 session_id,也能让 Channel.send 正常路由到对应会话。+ metadata: dict | None = None+ try:+ from jiuwenclaw.config import get_config_raw++ cfg = get_config_raw() or {}+ ch_cfg = (cfg.get("channels") or {}).get(channel_id) or {}+ if channel_id == "feishu":+ last_chat_id = str(ch_cfg.get("last_chat_id") or "").strip()+ last_open_id = str(ch_cfg.get("last_open_id") or "").strip()+ if last_chat_id or last_open_id:+ metadata = {+ "feishu_chat_id": last_chat_id,+ "feishu_open_id": last_open_id,+ }+ elif channel_id == "xiaoyi":+ last_session_id = str(ch_cfg.get("last_session_id") or "").strip()+ last_task_id = str(ch_cfg.get("last_task_id") or "").strip()+ if last_session_id or last_task_id:+ metadata = {+ "xiaoyi_session_id": last_session_id,+ "xiaoyi_task_id": last_task_id,+ }+ except Exception:+ metadata = None+msg = Message(id=f"cron-push-{state.run_id}-{channel_id}",type="event",@@ -364,5 +392,6 @@ class CronSchedulerService:ok=True,payload=payload_extra,event_type=EventType.CHAT_FINAL,+ metadata=metadata,)await self._message_handler.publish_robot_messages(msg)diff --git a/jiuwenclaw/gateway/message_handler.py b/jiuwenclaw/gateway/message_handler.pyindex 83e38e0de2..11f2a3fddb 100644--- a/jiuwenclaw/gateway/message_handler.py+++ b/jiuwenclaw/gateway/message_handler.py@@ -49,7 +49,7 @@ class MessageHandler(ABC):self._stream_sessions: dict[str, str | None] = {} # request_id -> session_id# per-channel 控制状态:支持 \new_session / \mode 指令(feishu/xiaoyi/dingding)- self._control_channels = {"feishu", "xiaoyi", "dingding"}+ self._control_channels = {"feishu", "xiaoyi", "dingtalk"}self._channel_states: Dict[str, ChannelControlState] = {}# 直接使用 jiuwenclaw.config 的 get_config_raw/set_config/update_channel_in_config@@ -177,7 +177,7 @@ class MessageHandler(ABC):if not state:return- # 对 feishu/xiaoyi/dingding 强制覆盖 session_id;web 等保持原有行为+ # 对 feishu/xiaoyi/dingtalk 强制覆盖 session_id;web 等保持原有行为if ch in self._control_channels and state.session_id:msg.session_id = state.session_id@@ -344,7 +344,7 @@ class MessageHandler(ABC):continue- # 先处理 Channel 控制指令(仅 feishu/xiaoyi/dingding)+ # 先处理 Channel 控制指令(仅 feishu/xiaoyi/dingtalk)if self._handle_channel_control(msg):# 该消息仅用于修改 session/mode,已给 Channel 回复提示,不再转发给 Agentcontinue