From f6e97481b1a810c5d746d9cdecebb144ec9032fd Mon Sep 17 00:00:00 2001 From: Mizore Date: Sun, 15 Jan 2023 13:04:01 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=94=AF=E6=8C=81=20feishu=20?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + script/config.lua | 5 ++++- script/util_notify.lua | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 57e9bb5..7f15ae5 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - [x] [pushdeer](https://www.pushdeer.com/) - [x] [bark](https://github.com/Finb/Bark) - [x] [dingtalk](https://open.dingtalk.com/document/robots/custom-robot-access) + - [x] [feishu](https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN) - [x] 基站定位 - [x] 定时查询流量 - [x] 开机通知 diff --git a/script/config.lua b/script/config.lua index 4b99697..a693c54 100644 --- a/script/config.lua +++ b/script/config.lua @@ -1,5 +1,5 @@ return { - -- 通知类型 telegram, pushdeer, bark, dingtalk + -- 通知类型 telegram, pushdeer, bark, dingtalk, feishu NOTIFY_TYPE = "pushdeer", -- -- telegram 通知配置, https://github.com/0wQ/telegram-notify @@ -18,6 +18,9 @@ return { -- dingtalk 通知配置, https://open.dingtalk.com/document/robots/custom-robot-access DINGTALK_WEBHOOK = "", -- + -- feishu 通知配置, https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN + FEISHU_WEBHOOK = "", + -- -- 定时查询流量间隔, 单位毫秒, 设置为 0 关闭 QUERY_TRAFFIC_INTERVAL = 1000 * 60 * 60 * 6, -- diff --git a/script/util_notify.lua b/script/util_notify.lua index bda0a0b..e996905 100644 --- a/script/util_notify.lua +++ b/script/util_notify.lua @@ -99,6 +99,30 @@ local function notifyToDingTalk(msg) return http.request("POST", config.DINGTALK_WEBHOOK, header, json_data).wait() end +-- 发送到 feishu +local function notifyToFeishu(msg) + if config.FEISHU_WEBHOOK == nil or config.FEISHU_WEBHOOK == "" then + log.error("util_notify.notifyToFeishu", "未配置 `config.FEISHU_WEBHOOK`") + return + end + + local header = { + ["Content-Type"] = "application/json; charset=utf-8" + } + local body = { + msg_type = "text", + content = { + text = msg + } + } + local json_data = json.encode(body) + -- LuatOS Bug, json.encode 会将 \n 转换为 \b + json_data = string.gsub(json_data, "\\b", "\\n") + + log.info("util_notify.notifyToFeishu", "POST", config.FEISHU_WEBHOOK, json_data) + return http.request("POST", config.FEISHU_WEBHOOK, header, json_data).wait() +end + function util_notify.send(msg) log.info("util_notify.send", "发送通知", config.NOTIFY_TYPE) @@ -147,6 +171,8 @@ function util_notify.send(msg) notify = notifyToBark elseif config.NOTIFY_TYPE == "dingtalk" then notify = notifyToDingTalk + elseif config.NOTIFY_TYPE == "feishu" then + notify = notifyToFeishu else log.error("util_notify.send", "发送通知失败", "未配置 `config.NOTIFY_TYPE`") return