Browse Source

Merge branch 'main' of github.com:0wQ/air780e-forwarder

Mizore 2 years ago
parent
commit
a0dacb6ce3
2 changed files with 31 additions and 0 deletions
  1. 6 0
      script/config.lua
  2. 25 0
      script/util_notify.lua

+ 6 - 0
script/config.lua

@@ -42,6 +42,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 = 0,
     --

+ 25 - 0
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