✨ 支持 dingtalk 通知
This commit is contained in:
parent
8978078ef3
commit
92578e5adb
@ -6,6 +6,7 @@
|
|||||||
- [x] [telegram](https://github.com/0wQ/telegram-notify)
|
- [x] [telegram](https://github.com/0wQ/telegram-notify)
|
||||||
- [x] [pushdeer](https://www.pushdeer.com/)
|
- [x] [pushdeer](https://www.pushdeer.com/)
|
||||||
- [x] [bark](https://github.com/Finb/Bark)
|
- [x] [bark](https://github.com/Finb/Bark)
|
||||||
|
- [x] [dingtalk](https://open.dingtalk.com/document/robots/custom-robot-access)
|
||||||
- [x] 基站定位
|
- [x] 基站定位
|
||||||
- [x] 定时查询流量
|
- [x] 定时查询流量
|
||||||
- [x] 开机通知
|
- [x] 开机通知
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
return {
|
return {
|
||||||
-- 通知类型 telegram, pushdeer, bark
|
-- 通知类型 telegram, pushdeer, bark, dingtalk
|
||||||
NOTIFY_TYPE = "pushdeer",
|
NOTIFY_TYPE = "pushdeer",
|
||||||
--
|
--
|
||||||
-- telegram 通知配置, https://github.com/0wQ/telegram-notify
|
-- telegram 通知配置, https://github.com/0wQ/telegram-notify
|
||||||
@ -15,6 +15,9 @@ return {
|
|||||||
BARK_API = "https://api.day.app",
|
BARK_API = "https://api.day.app",
|
||||||
BARK_KEY = "",
|
BARK_KEY = "",
|
||||||
--
|
--
|
||||||
|
-- dingtalk 通知配置, https://open.dingtalk.com/document/robots/custom-robot-access
|
||||||
|
DINGTALK_WEBHOOK = "",
|
||||||
|
--
|
||||||
-- 定时查询流量间隔, 单位毫秒, 设置为 0 关闭
|
-- 定时查询流量间隔, 单位毫秒, 设置为 0 关闭
|
||||||
QUERY_TRAFFIC_INTERVAL = 1000 * 60 * 60 * 6,
|
QUERY_TRAFFIC_INTERVAL = 1000 * 60 * 60 * 6,
|
||||||
--
|
--
|
||||||
|
@ -29,7 +29,7 @@ local function notifyToTelegram(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- 发送到 pushdeer
|
-- 发送到 pushdeer
|
||||||
local function notifyToPushDeer(msg, httpCallback)
|
local function notifyToPushDeer(msg)
|
||||||
if config.PUSHDEER_API == "" then
|
if config.PUSHDEER_API == "" then
|
||||||
log.error("util_notify.notifyToPushDeer", "未配置 `config.PUSHDEER_API`")
|
log.error("util_notify.notifyToPushDeer", "未配置 `config.PUSHDEER_API`")
|
||||||
return
|
return
|
||||||
@ -53,7 +53,7 @@ local function notifyToPushDeer(msg, httpCallback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- 发送到 bark
|
-- 发送到 bark
|
||||||
local function notifyToBark(msg, httpCallback)
|
local function notifyToBark(msg)
|
||||||
if config.BARK_API == "" then
|
if config.BARK_API == "" then
|
||||||
log.error("util_notify.notifyToBark", "未配置 `config.BARK_API`")
|
log.error("util_notify.notifyToBark", "未配置 `config.BARK_API`")
|
||||||
return
|
return
|
||||||
@ -75,6 +75,30 @@ local function notifyToBark(msg, httpCallback)
|
|||||||
return http.request("POST", url, header, urlencodeTab(body)).wait()
|
return http.request("POST", url, header, urlencodeTab(body)).wait()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 发送到 dingtalk
|
||||||
|
local function notifyToDingTalk(msg)
|
||||||
|
if config.DINGTALK_WEBHOOK == nil or config.DINGTALK_WEBHOOK == "" then
|
||||||
|
log.error("util_notify.notifyToDingTalk", "未配置 `config.DINGTALK_WEBHOOK`")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local header = {
|
||||||
|
["Content-Type"] = "application/json; charset=utf-8"
|
||||||
|
}
|
||||||
|
local body = {
|
||||||
|
msgtype = "text",
|
||||||
|
text = {
|
||||||
|
content = 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.notifyToDingTalk", "POST", config.DINGTALK_WEBHOOK, json_data)
|
||||||
|
return http.request("POST", config.DINGTALK_WEBHOOK, header, json_data).wait()
|
||||||
|
end
|
||||||
|
|
||||||
function util_notify.send(msg)
|
function util_notify.send(msg)
|
||||||
log.info("util_notify.send", "发送通知", config.NOTIFY_TYPE)
|
log.info("util_notify.send", "发送通知", config.NOTIFY_TYPE)
|
||||||
|
|
||||||
@ -121,6 +145,8 @@ function util_notify.send(msg)
|
|||||||
notify = notifyToPushDeer
|
notify = notifyToPushDeer
|
||||||
elseif config.NOTIFY_TYPE == "bark" then
|
elseif config.NOTIFY_TYPE == "bark" then
|
||||||
notify = notifyToBark
|
notify = notifyToBark
|
||||||
|
elseif config.NOTIFY_TYPE == "dingtalk" then
|
||||||
|
notify = notifyToDingTalk
|
||||||
else
|
else
|
||||||
log.error("util_notify.send", "发送通知失败", "未配置 `config.NOTIFY_TYPE`")
|
log.error("util_notify.send", "发送通知失败", "未配置 `config.NOTIFY_TYPE`")
|
||||||
return
|
return
|
||||||
@ -135,7 +161,7 @@ function util_notify.send(msg)
|
|||||||
while retry_count < max_retry do
|
while retry_count < max_retry do
|
||||||
local code, headers, body = notify(msg)
|
local code, headers, body = notify(msg)
|
||||||
if code == 200 then
|
if code == 200 then
|
||||||
log.info("util_notify.send", "发送通知成功", "retry_count:", retry_count)
|
log.info("util_notify.send", "发送通知成功", "retry_count:", retry_count, "code:", code, "body:", body)
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
retry_count = retry_count + 1
|
retry_count = retry_count + 1
|
||||||
|
Loading…
Reference in New Issue
Block a user