支持 wecom 通知

This commit is contained in:
Mizore 2023-01-15 16:52:34 +08:00
parent f6e97481b1
commit 6bc4d89c1f
3 changed files with 31 additions and 1 deletions

View File

@ -8,6 +8,7 @@
- [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] [wecom](https://developer.work.weixin.qq.com/document/path/91770)
- [x] 基站定位
- [x] 定时查询流量
- [x] 开机通知

View File

@ -1,5 +1,5 @@
return {
-- 通知类型 telegram, pushdeer, bark, dingtalk, feishu
-- 通知类型 telegram, pushdeer, bark, dingtalk, feishu, wecom
NOTIFY_TYPE = "pushdeer",
--
-- telegram 通知配置, https://github.com/0wQ/telegram-notify
@ -21,6 +21,9 @@ return {
-- feishu 通知配置, https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN
FEISHU_WEBHOOK = "",
--
-- wecom 通知配置, https://developer.work.weixin.qq.com/document/path/91770
WECOM_WEBHOOK = "",
--
-- 定时查询流量间隔, 单位毫秒, 设置为 0 关闭
QUERY_TRAFFIC_INTERVAL = 1000 * 60 * 60 * 6,
--

View File

@ -123,6 +123,30 @@ local function notifyToFeishu(msg)
return http.request("POST", config.FEISHU_WEBHOOK, header, json_data).wait()
end
-- 发送到 wecom
local function notifyToWeCom(msg)
if config.WECOM_WEBHOOK == nil or config.WECOM_WEBHOOK == "" then
log.error("util_notify.notifyToWeCom", "未配置 `config.WECOM_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.notifyToWeCom", "POST", config.WECOM_WEBHOOK, json_data)
return http.request("POST", config.WECOM_WEBHOOK, header, json_data).wait()
end
function util_notify.send(msg)
log.info("util_notify.send", "发送通知", config.NOTIFY_TYPE)
@ -173,6 +197,8 @@ function util_notify.send(msg)
notify = notifyToDingTalk
elseif config.NOTIFY_TYPE == "feishu" then
notify = notifyToFeishu
elseif config.NOTIFY_TYPE == "wecom" then
notify = notifyToWeCom
else
log.error("util_notify.send", "发送通知失败", "未配置 `config.NOTIFY_TYPE`")
return