mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-30 12:36:55 +08:00
- notification 域:渠道能力(MessageChannel→NotificationChannel、ChannelCapability* 迁入 notification.py) - message 域:消息收发(Notification→Message、NotificationType→MessageType、CommingMessage→IncomingMessage、NotificationHistoryItem→MessageHistoryItem、NotificationClear*→MessageClear*) - Agent 工具契约:send_notification_message→send_message、notification_callback→message_callback - 源码不保留旧名物理别名,旧导入经 app/runtime/compat/manifest.py SYMBOL_ALIASES 惰性解析 - API 路径与持久化键冻结不变,前端零改动 - 新增兼容守护测试与 docs/rules/07 命名边界规范
76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
from typing import List, Optional, Union
|
||
|
||
from pydantic import Field
|
||
|
||
from app.workflow.actions import BaseAction, ActionChain
|
||
from app.schemas import ActionParams, ActionContext, Message
|
||
from app.runtime.config import settings
|
||
|
||
|
||
class SendMessageParams(ActionParams):
|
||
"""
|
||
发送消息参数
|
||
"""
|
||
client: Optional[List[str]] = Field(default=[], description="消息渠道")
|
||
userid: Optional[Union[str, int]] = Field(default=None, description="用户ID")
|
||
|
||
|
||
class SendMessageAction(BaseAction):
|
||
"""
|
||
发送消息
|
||
"""
|
||
|
||
contract = {}
|
||
|
||
def __init__(self, action_id: str):
|
||
super().__init__(action_id)
|
||
|
||
@classmethod
|
||
@property
|
||
def name(cls) -> str: # noqa
|
||
return "发送消息"
|
||
|
||
@classmethod
|
||
@property
|
||
def description(cls) -> str: # noqa
|
||
return "发送任务执行消息"
|
||
|
||
@classmethod
|
||
@property
|
||
def data(cls) -> dict: # noqa
|
||
return SendMessageParams().model_dump()
|
||
|
||
@property
|
||
def success(self) -> bool:
|
||
return self.done
|
||
|
||
def execute(self, workflow_id: int, params: dict, context: ActionContext) -> ActionContext:
|
||
"""
|
||
发送messages中的消息
|
||
"""
|
||
params = SendMessageParams(**params)
|
||
msg_text = f"当前进度:{context.progress}%"
|
||
index = 1
|
||
if context.execute_history:
|
||
for history in context.execute_history:
|
||
if not history.message:
|
||
continue
|
||
msg_text += f"\n{index}. {history.action}:{history.message}"
|
||
index += 1
|
||
# 发送消息
|
||
if not params.client:
|
||
params.client = [""]
|
||
for client in params.client:
|
||
ActionChain().post_message(
|
||
Message(
|
||
source=client,
|
||
userid=params.userid,
|
||
title="【工作流执行结果】",
|
||
text=msg_text,
|
||
link=settings.MP_DOMAIN("#/workflow")
|
||
)
|
||
)
|
||
|
||
self.job_done()
|
||
return context
|