From c714aa04cea0cf83f3bdea5f1272ff26d310caa2 Mon Sep 17 00:00:00 2001 From: AkagiYui Date: Sat, 1 Apr 2023 15:14:54 +0800 Subject: [PATCH] feat: add gotify support --- script/config.lua | 6 ++++++ script/util_notify.lua | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/script/config.lua b/script/config.lua index bb2d369..17b4f3e 100644 --- a/script/config.lua +++ b/script/config.lua @@ -41,6 +41,12 @@ return { NEXT_SMTP_PROXY_TO_EMAIL = "", NEXT_SMTP_PROXY_SUBJECT = "来自 Air780E 的通知", -- + -- gotify 通知配置, https://gotify.net/ + GOTIFY_API = "", + GOTIFY_TITLE = "Air780E", + GOTIFY_PRIORITY = 8, + GOTIFY_TOKEN = "", + -- -- 定时查询流量间隔, 单位毫秒, 设置为 0 关闭 (建议检查 util_mobile.lua 文件中运营商号码和查询代码是否正确, 以免发错短信导致扣费, 收到查询结果短信发送通知会消耗流量) QUERY_TRAFFIC_INTERVAL = 1000 * 60 * 60 * 6, -- diff --git a/script/util_notify.lua b/script/util_notify.lua index 863d588..66c3b3c 100644 --- a/script/util_notify.lua +++ b/script/util_notify.lua @@ -31,6 +31,31 @@ local notify = { log.info("util_notify", "POST", config.TELEGRAM_PROXY_API) return util_http.fetch(nil, "POST", config.TELEGRAM_PROXY_API, header, msg) end, + -- 发送到 gotify + ["gotify"] = function(msg) + if config.GOTIFY_API == nil or config.GOTIFY_API == "" then + log.error("util_notify", "未配置 `config.GOTIFY_API`") + return + end + if config.GOTIFY_TOKEN == nil or config.GOTIFY_TOKEN == "" then + log.error("util_notify", "未配置 `config.GOTIFY_TOKEN`") + return + end + + local header = { + ["Content-Type"] = "application/json; charset=utf-8" + } + local body = { + title = config.GOTIFY_TITLE, + message = msg, + priority = config.GOTIFY_PRIORITY + } + local json_data = json.encode(body) + json_data = string.gsub(json_data, "\\b", "\\n") + + log.info("util_notify", "POST", config.GOTIFY_API) + return util_http.fetch(nil, "POST", config.GOTIFY_API.."/message?token="..config.GOTIFY_TOKEN, header, json_data) + end, -- 发送到 pushdeer ["pushdeer"] = function(msg) if config.PUSHDEER_API == nil or config.PUSHDEER_API == "" then