feat: Add MAA Task Notification System (Supporting DingTalk, Bark, Qmsg, and Custom Webhooks) - #63
Open
RainYangty wants to merge 7 commits into
Open
Conversation
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 请求。
Contributor
Author
|
@hguandl 是否需要加入SMTP, SeverChan, Telegram等在Windows端存在的通知服务 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
NotificationServicearchitecture to handle scheduling, buffering, and retries independently for each channel.Key Changes
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.DingTalkService.swift,BarkService.swift,QmsgService.swift, andCustomWebhookService.swift. Each file contains its own specific API request logic, failure counter, and auto-retry/disable mechanism.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 (加签).Data & UI Integration:
MeoAsstMac/Model/MAAViewModel.swift: Adds new@AppStorageproperties and models (NotificationTriggers,CustomWebhookSettings,QmsgSettings) to store user configurations for all new features.MeoAsstMac/MeoAsstMacApp.swift: Integrates and initializes theNotificationManagerwith theMAAViewModelinstance at application startup.Custom Webhook Feature:
CustomWebhookService.swiftimplements support for users to provide a custom JSON Body template, allowing variable substitution for{title},{content}, and{time}.Files Affected
MeoAsstMac/MeoAsstMacApp.swiftMeoAsstMac/Model/MAAViewModel.swiftMeoAsstMac/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架构,它负责独立处理每个通道的调度、缓冲和重试逻辑。主要更改
新增文件和核心架构(通知系统):
MeoAsstMac/Services/Notification/NotificationManager.swift(新增):中央调度器。处理日志监听、缓冲、节流(按时间间隔发送摘要),并将日志分派给已启用的服务。MeoAsstMac/Services/Notification/NotificationService.swift(新增):定义了所有服务必须遵循的协议,确保了标准化。DingTalkService.swift、BarkService.swift、QmsgService.swift和CustomWebhookService.swift。每个文件包含各自特有的 API 请求逻辑、失败计数器 和 自动重试/禁用机制。钉钉客户端与安全性:
MeoAsstMac/Services/Notification/DingTalkBotClient.swift(新增):一个专用的客户端,用于处理钉钉 API 的复杂性,包括支持 Markdown 消息 和 HMAC-SHA256 签名 生成(加签)。数据和 UI 集成:
MeoAsstMac/Model/MAAViewModel.swift:新增了@AppStorage属性和模型 (NotificationTriggers,CustomWebhookSettings,QmsgSettings),用于存储所有新功能的用户配置。MeoAsstMac/MeoAsstMacApp.swift:在应用启动时,将NotificationManager与MAAViewModel实例集成并初始化。自定义 Webhook 功能:
CustomWebhookService.swift实现了对用户提供自定义 JSON Body 模板的支持,允许替换{title}、{content}和{time}等变量。受影响的文件
MeoAsstMac/MeoAsstMacApp.swiftMeoAsstMac/Model/MAAViewModel.swiftMeoAsstMac/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(新功能)