From 5e7104d5a36059faeea0d9d71082e48dc2e2a718 Mon Sep 17 00:00:00 2001 From: kilo5hz <90814817+kilo5hz@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:23:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=80=9A=E7=9F=A5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0gotify=20(#936)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/data/notify.ts | 8 ++++++++ back/services/notify.ts | 20 ++++++++++++++++++++ sample/config.sample.sh | 8 ++++++++ 3 files changed, 36 insertions(+) diff --git a/back/data/notify.ts b/back/data/notify.ts index 35143e1a..a28e0721 100644 --- a/back/data/notify.ts +++ b/back/data/notify.ts @@ -1,4 +1,5 @@ export enum NotificationMode { + 'gotify' = 'gotify', 'goCqHttpBot' = 'goCqHttpBot', 'serverChan' = 'serverChan', 'bark' = 'bark', @@ -15,6 +16,12 @@ abstract class NotificationBaseInfo { public type!: NotificationMode; } +export class GotifyNotification extends NotificationBaseInfo { + public gotifyUrl = ''; + public gotifyToken = ''; + public gotifyPriority = 0; +} + export class GoCqHttpBotNotification extends NotificationBaseInfo { public goCqHttpBotUrl = ''; public goCqHttpBotToken = ''; @@ -70,6 +77,7 @@ export class EmailNotification extends NotificationBaseInfo { export interface NotificationInfo extends GoCqHttpBotNotification, + GotifyNotification, ServerChanNotification, BarkNotification, TelegramBotNotification, diff --git a/back/services/notify.ts b/back/services/notify.ts index 404a2bce..84119d7c 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -13,6 +13,7 @@ export default class NotificationService { private userService!: UserService; private modeMap = new Map([ + ['gotify', this.gotify], ['goCqHttpBot', this.goCqHttpBot], ['serverChan', this.serverChan], ['bark', this.bark], @@ -67,6 +68,25 @@ export default class NotificationService { return true; } + private async gotify() { + const { gotifyUrl, gotifyToken, gotifyPriority } = this.params; + const res: any = await got + .post(`${gotifyUrl}/message?token=${gotifyToken}`, { + timeout: this.timeout, + retry: 0, + body: `title=${encodeURIComponent( + this.title, + )}&message=${encodeURIComponent( + this.content, + )}&priority=${gotifyPriority}`, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }) + .json(); + return typeof res.id === 'number'; + } + private async goCqHttpBot() { const { goCqHttpBotQq, goCqHttpBotToken, goCqHttpBotUrl } = this.params; const res: any = await got diff --git a/sample/config.sample.sh b/sample/config.sample.sh index 097404cc..58122716 100644 --- a/sample/config.sample.sh +++ b/sample/config.sample.sh @@ -112,4 +112,12 @@ export GOBOT_URL="" export GOBOT_TOKEN="" export GOBOT_QQ="" +## 10. gotify +## gotify_url 填写gotify地址,如https://push.example.de:8080 +## gotify_token 填写gotify的消息应用token +## gotify_priority 填写推送消息优先级,默认为0 +export GOTIFY_URL=""; +export GOTIFY_TOKEN=""; +export GOTIFY_PRIORITY=0; + ## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可