Skip to content

Conversation

@RainYangty
Copy link
Contributor

@RainYangty RainYangty commented Sep 20, 2025

6b366e745887955a74f30c0186ced768
ef1ac6a0a397186c253ee8ad88ab5bd8

Summary

This Pull Request introduces a comprehensive Task Notification System for MAA. This system is designed to provide immediate, buffered, and reliable status updates to users via multiple third-party channels (DingTalk, Bark, Qmsg, and Custom Webhook).

The core of the implementation relies on a highly decoupled NotificationService architecture to handle scheduling, buffering, and retries independently for each channel.

Key Changes

  1. New Files & Core Architecture (The Notification System):

    • MeoAsstMac/Services/Notification/NotificationManager.swift (New): The central scheduler. Handles log observation, buffering, throttling (sending a summary based on time interval), and dispatching logs to enabled services.
    • MeoAsstMac/Services/Notification/NotificationService.swift (New): Defines the protocol that all services must conform to, ensuring standardization.
    • Independent Services (New): Adds DingTalkService.swift, BarkService.swift, QmsgService.swift, and CustomWebhookService.swift. Each file contains its own specific API request logic, failure counter, and auto-retry/disable mechanism.
  2. DingTalk Client & Security:

    • MeoAsstMac/Services/Notification/DingTalkBotClient.swift (New): A dedicated client to handle the complexity of the DingTalk API, including support for Markdown messages and HMAC-SHA256 signature generation (加签).
  3. Data & UI Integration:

    • MeoAsstMac/Model/MAAViewModel.swift: Adds new @AppStorage properties and models (NotificationTriggers, CustomWebhookSettings, QmsgSettings) to store user configurations for all new features.
    • MeoAsstMac/MeoAsstMacApp.swift: Integrates and initializes the NotificationManager with the MAAViewModel instance at application startup.
    • (Note: UI views for configuration are not in this PR but rely on these data models).
  4. Custom Webhook Feature:

    • The CustomWebhookService.swift implements support for users to provide a custom JSON Body template, allowing variable substitution for {title}, {content}, and {time}.

Files Affected

  • MeoAsstMac/MeoAsstMacApp.swift
  • MeoAsstMac/Model/MAAViewModel.swift
  • MeoAsstMac/Services/Notification/BarkService.swift (New Feature)
  • MeoAsstMac/Services/Notification/CustomWebhookService.swift (New Feature)
  • MeoAsstMac/Services/Notification/DingTalkBotClient.swift (New Feature)
  • MeoAsstMac/Services/Notification/DingTalkService.swift (New Feature)
  • MeoAsstMac/Services/Notification/NotificationManager.swift (New Feature)
  • MeoAsstMac/Services/Notification/NotificationService.swift (New Feature)
  • MeoAsstMac/Services/Notification/QmsgService.swift (New Feature)


摘要

本次拉取请求(PR)引入了一个全面的 MAA 任务通知系统。该系统旨在通过多个第三方渠道(钉钉、Bark、Qmsg 和自定义 Webhook),为用户提供即时、缓冲和可靠的状态更新。

实现的核心是高度解耦的 NotificationService 架构,它负责独立处理每个通道的调度、缓冲和重试逻辑。

主要更改

  1. 新增文件和核心架构(通知系统):

    • MeoAsstMac/Services/Notification/NotificationManager.swift (新增):中央调度器。处理日志监听、缓冲、节流(按时间间隔发送摘要),并将日志分派给已启用的服务。
    • MeoAsstMac/Services/Notification/NotificationService.swift (新增):定义了所有服务必须遵循的协议,确保了标准化。
    • 独立服务 (新增):添加了 DingTalkService.swiftBarkService.swiftQmsgService.swiftCustomWebhookService.swift。每个文件包含各自特有的 API 请求逻辑、失败计数器自动重试/禁用机制
  2. 钉钉客户端与安全性:

    • MeoAsstMac/Services/Notification/DingTalkBotClient.swift (新增):一个专用的客户端,用于处理钉钉 API 的复杂性,包括支持 Markdown 消息HMAC-SHA256 签名 生成(加签)。
  3. 数据和 UI 集成:

    • MeoAsstMac/Model/MAAViewModel.swift:新增了 @AppStorage 属性和模型 (NotificationTriggers, CustomWebhookSettings, QmsgSettings),用于存储所有新功能的用户配置。
    • MeoAsstMac/MeoAsstMacApp.swift:在应用启动时,将 NotificationManagerMAAViewModel 实例集成并初始化。
    • (注意:配置的 UI 视图不在此 PR 中,但依赖于这些数据模型)。
  4. 自定义 Webhook 功能:

    • CustomWebhookService.swift 实现了对用户提供自定义 JSON Body 模板的支持,允许替换 {title}{content}{time} 等变量。

受影响的文件

  • MeoAsstMac/MeoAsstMacApp.swift
  • MeoAsstMac/Model/MAAViewModel.swift
  • MeoAsstMac/Services/Notification/BarkService.swift (新功能)
  • MeoAsstMac/Services/Notification/CustomWebhookService.swift (新功能)
  • MeoAsstMac/Services/Notification/DingTalkBotClient.swift (新功能)
  • MeoAsstMac/Services/Notification/DingTalkService.swift (新功能)
  • MeoAsstMac/Services/Notification/NotificationManager.swift (新功能)
  • MeoAsstMac/Services/Notification/NotificationService.swift (新功能)
  • MeoAsstMac/Services/Notification/QmsgService.swift (新功能)

@RainYangty RainYangty changed the title feat: 消息通知 feat: Add MAA Task Notification System (Supporting DingTalk, Bark, Qmsg, and Custom Webhooks) Sep 30, 2025
This change resolves the issue where Bark notifications fail to send due to URL length limitations when the log content (body) is too long. The original HTTP GET request method places all content in the URL path, which easily exceeds maximum allowed URL lengths (typically 2KB to 8KB).

✨ Key Changes
Protocol Switch: Changed the Bark notification sending method from HTTP GET to HTTP POST request.

Data Format: Content (title, body, key, etc.) is now packaged as a JSON Payload and sent in the request body (httpBody), following the official Bark JSON POST documentation.

Code Refactoring:

Removed the old buildURL(for:config:viewModel:) method from BarkService.

Introduced a new buildRequest(for:config:viewModel:) method to construct a URLRequest object containing the JSON data.

Modified the send(...) method to use URLSession.shared.data(for: request) for sending the POST request.

解决了当日志内容 (body) 过长时,Bark 通知因 URL 长度限制而发送失败的问题。原有的 GET 请求方式将所有通知内容(包括正文)都放在 URL 路径中,容易超过服务器或客户端限制的最大 URL 长度。

✨ 主要改动
协议切换:将 Bark 通知的发送方式从 HTTP GET 请求切换为 HTTP POST 请求。

数据格式:将通知内容 (title, body, key 等) 封装为 JSON Payload,并通过请求体 (httpBody) 发送,遵循 Bark 官方文档的 JSON POST 格式。

代码重构:

移除 BarkService 中构建 URL 的 buildURL(for:config:viewModel:) 方法。

新增 buildRequest(for:config:viewModel:) 方法,用于构建包含 JSON 数据的 URLRequest 对象。

修改 send(...) 方法,使用 URLSession.shared.data(for: request) 发送 POST 请求。
@RainYangty
Copy link
Contributor Author

@hguandl 是否需要加入SMTP, SeverChan, Telegram等在Windows端存在的通知服务

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant