feat(notify): add mattermost

This commit is contained in:
banto
2025-04-11 22:55:47 +08:00
parent 4e3f499d76
commit ec0cdf8b96
11 changed files with 274 additions and 4 deletions

View File

@@ -1,8 +1,8 @@
import { forwardRef, useImperativeHandle, useMemo } from "react";
import { Form, type FormInstance } from "antd";
import {forwardRef, useImperativeHandle, useMemo} from "react";
import {Form, type FormInstance} from "antd";
import { NOTIFY_CHANNELS, type NotifyChannelsSettingsContent } from "@/domain/settings";
import { useAntdForm } from "@/hooks";
import {NOTIFY_CHANNELS, type NotifyChannelsSettingsContent} from "@/domain/settings";
import {useAntdForm} from "@/hooks";
import NotifyChannelEditFormBarkFields from "./NotifyChannelEditFormBarkFields";
import NotifyChannelEditFormDingTalkFields from "./NotifyChannelEditFormDingTalkFields";
@@ -14,6 +14,7 @@ import NotifyChannelEditFormServerChanFields from "./NotifyChannelEditFormServer
import NotifyChannelEditFormTelegramFields from "./NotifyChannelEditFormTelegramFields";
import NotifyChannelEditFormWebhookFields from "./NotifyChannelEditFormWebhookFields";
import NotifyChannelEditFormWeComFields from "./NotifyChannelEditFormWeComFields";
import NotifyChannelEditFormMattermostFields from "@/components/notification/NotifyChannelEditFormMattermostFields.tsx";
type NotifyChannelEditFormFieldValues = NotifyChannelsSettingsContent[keyof NotifyChannelsSettingsContent];
@@ -54,6 +55,8 @@ const NotifyChannelEditForm = forwardRef<NotifyChannelEditFormInstance, NotifyCh
return <NotifyChannelEditFormGotifyFields />;
case NOTIFY_CHANNELS.LARK:
return <NotifyChannelEditFormLarkFields />;
case NOTIFY_CHANNELS.MATTERMOST:
return <NotifyChannelEditFormMattermostFields />;
case NOTIFY_CHANNELS.PUSHPLUS:
return <NotifyChannelEditFormPushPlusFields />;
case NOTIFY_CHANNELS.SERVERCHAN:

View File

@@ -0,0 +1,63 @@
import {useTranslation} from "react-i18next";
import {Form, Input} from "antd";
import {createSchemaFieldRule} from "antd-zod";
import {z} from "zod";
const NotifyChannelEditFormMattermostFields = () => {
const { t } = useTranslation();
const formSchema = z.object({
serverUrl: z
.string({ message: t("settings.notification.channel.form.mattermost_server_url.placeholder") })
.url(t("common.errmsg.url_invalid")),
channelId: z
.string({ message: t("settings.notification.channel.form.mattermost_channel_id.placeholder") })
.nonempty(t("settings.notification.channel.form.mattermost_channel_id.placeholder")),
username: z
.string({ message: t("settings.notification.channel.form.mattermost_username.placeholder") })
.nonempty(t("settings.notification.channel.form.mattermost_username.placeholder")),
password: z
.string({ message: t("settings.notification.channel.form.mattermost_password.placeholder") })
.nonempty(t("settings.notification.channel.form.mattermost_password.placeholder")),
});
const formRule = createSchemaFieldRule(formSchema);
return (
<>
<Form.Item
name="serverUrl"
label={t("settings.notification.channel.form.mattermost_server_url.label")}
rules={[formRule]}
tooltip={<span dangerouslySetInnerHTML={{ __html: t("settings.notification.channel.form.mattermost_server_url.tooltip") }}></span>}
>
<Input placeholder={t("settings.notification.channel.form.mattermost_server_url.placeholder")} />
</Form.Item>
<Form.Item
name="channelId"
label={t("settings.notification.channel.form.mattermost_channel_id.label")}
rules={[formRule]}
>
<Input placeholder={t("settings.notification.channel.form.mattermost_channel_id.placeholder")} />
</Form.Item>
<Form.Item
name="username"
label={t("settings.notification.channel.form.mattermost_username.label")}
rules={[formRule]}
>
<Input placeholder={t("settings.notification.channel.form.mattermost_username.placeholder")} />
</Form.Item>
<Form.Item
name="password"
label={t("settings.notification.channel.form.mattermost_password.label")}
rules={[formRule]}
>
<Input.Password placeholder={t("settings.notification.channel.form.mattermost_password.placeholder")} />
</Form.Item>
</>
);
};
export default NotifyChannelEditFormMattermostFields;

View File

@@ -44,6 +44,7 @@ export const NOTIFY_CHANNELS = Object.freeze({
EMAIL: "email",
GOTIFY: "gotify",
LARK: "lark",
MATTERMOST: "mattermost",
PUSHPLUS: "pushplus",
SERVERCHAN: "serverchan",
TELEGRAM: "telegram",
@@ -64,6 +65,7 @@ export type NotifyChannelsSettingsContent = {
[NOTIFY_CHANNELS.EMAIL]?: EmailNotifyChannelConfig;
[NOTIFY_CHANNELS.GOTIFY]?: GotifyNotifyChannelConfig;
[NOTIFY_CHANNELS.LARK]?: LarkNotifyChannelConfig;
[NOTIFY_CHANNELS.MATTERMOST]?: MattermostNotifyChannelConfig;
[NOTIFY_CHANNELS.PUSHPLUS]?: PushPlusNotifyChannelConfig;
[NOTIFY_CHANNELS.SERVERCHAN]?: ServerChanNotifyChannelConfig;
[NOTIFY_CHANNELS.TELEGRAM]?: TelegramNotifyChannelConfig;
@@ -106,6 +108,14 @@ export type LarkNotifyChannelConfig = {
enabled?: boolean;
};
export type MattermostNotifyChannelConfig = {
serverUrl: string;
channel: string;
username: string;
password: string;
enabled?: boolean;
}
export type PushPlusNotifyChannelConfig = {
token: string;
enabled?: boolean;
@@ -143,6 +153,7 @@ export const notifyChannelsMap: Map<NotifyChannel["type"], NotifyChannel> = new
[NOTIFY_CHANNELS.DINGTALK, "common.notifier.dingtalk"],
[NOTIFY_CHANNELS.GOTIFY, "common.notifier.gotify"],
[NOTIFY_CHANNELS.LARK, "common.notifier.lark"],
[NOTIFY_CHANNELS.MATTERMOST, "common.notifier.mattermost"],
[NOTIFY_CHANNELS.PUSHPLUS, "common.notifier.pushplus"],
[NOTIFY_CHANNELS.WECOM, "common.notifier.wecom"],
[NOTIFY_CHANNELS.TELEGRAM, "common.notifier.telegram"],

View File

@@ -41,6 +41,7 @@
"common.notifier.email": "Email",
"common.notifier.gotify": "Gotify",
"common.notifier.lark": "Lark",
"common.notifier.mattermost": "Mattermost",
"common.notifier.pushplus": "PushPlus",
"common.notifier.serverchan": "ServerChan",
"common.notifier.telegram": "Telegram",

View File

@@ -66,6 +66,15 @@
"settings.notification.channel.form.lark_webhook_url.label": "Webhook URL",
"settings.notification.channel.form.lark_webhook_url.placeholder": "Please enter Webhook URL",
"settings.notification.channel.form.lark_webhook_url.tooltip": "For more information, see <a href=\"https://www.feishu.cn/hc/en-US/articles/807992406756\" target=\"_blank\">https://www.feishu.cn/hc/en-US/articles/807992406756</a>",
"settings.notification.channel.form.mattermost_server_url.label": "Service URL",
"settings.notification.channel.form.mattermost_server_url.placeholder": "Please enter service URL",
"settings.notification.channel.form.mattermost_server_url.tooltip": "Example: <b>https://exmaple.com</b>, the protocol needs to be included but the trailing '/' should not be included.",
"settings.notification.channel.form.mattermost_channel_id.label": "Channel ID",
"settings.notification.channel.form.mattermost_channel_id.placeholder": "Please enter channel ID",
"settings.notification.channel.form.mattermost_username.label": "Username",
"settings.notification.channel.form.mattermost_username.placeholder": "Please enter username",
"settings.notification.channel.form.mattermost_password.label": "Password",
"settings.notification.channel.form.mattermost_password.placeholder": "Please enter password",
"settings.notification.channel.form.pushplus_token.placeholder": "Please enter Token",
"settings.notification.channel.form.pushplus_token.label": "Token",
"settings.notification.channel.form.pushplus_token.tooltip": "For more information, see <a href=\"https://www.pushplus.plus/push1.html\" target=\"_blank\">https://www.pushplus.plus/push1.html</a>",

View File

@@ -41,6 +41,7 @@
"common.notifier.email": "邮件",
"common.notifier.gotify": "Gotify",
"common.notifier.lark": "飞书",
"common.notifier.mattermost": "Mattermost",
"common.notifier.pushplus": "PushPlus推送加",
"common.notifier.serverchan": "Server 酱",
"common.notifier.telegram": "Telegram",

View File

@@ -66,6 +66,15 @@
"settings.notification.channel.form.lark_webhook_url.label": "机器人 Webhook 地址",
"settings.notification.channel.form.lark_webhook_url.placeholder": "请输入机器人 Webhook 地址",
"settings.notification.channel.form.lark_webhook_url.tooltip": "这是什么?请参阅 <a href=\"https://www.feishu.cn/hc/zh-CN/articles/807992406756\" target=\"_blank\">https://www.feishu.cn/hc/zh-CN/articles/807992406756</a>",
"settings.notification.channel.form.mattermost_server_url.label": "服务地址",
"settings.notification.channel.form.mattermost_server_url.placeholder": "请输入服务地址",
"settings.notification.channel.form.mattermost_server_url.tooltip": "示例: <b>https://exmaple.com</b>,需要包含协议但不要包含末尾的'/'",
"settings.notification.channel.form.mattermost_channel_id.label": "频道ID",
"settings.notification.channel.form.mattermost_channel_id.placeholder": "请输入频道ID",
"settings.notification.channel.form.mattermost_username.label": "用户名",
"settings.notification.channel.form.mattermost_username.placeholder": "请输入用户名",
"settings.notification.channel.form.mattermost_password.label": "密码",
"settings.notification.channel.form.mattermost_password.placeholder": "请输入密码",
"settings.notification.channel.form.pushplus_token.placeholder": "请输入Token",
"settings.notification.channel.form.pushplus_token.label": "Token",
"settings.notification.channel.form.pushplus_token.tooltip": "请参阅 <a href=\"https://www.pushplus.plus/push1.html\" target=\"_blank\">https://www.pushplus.plus/push1.html</a>",