Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加gotify自建推送服务支持 #19

Open
GunVeda opened this issue Mar 24, 2024 · 0 comments
Open

添加gotify自建推送服务支持 #19

GunVeda opened this issue Mar 24, 2024 · 0 comments

Comments

@GunVeda
Copy link

GunVeda commented Mar 24, 2024

使用gotify的http api发送消息推送

notification_helper.lua添加

local function gotify(sender_number, content)
    if not config.notification_channel.gotify.enabled then
        return
    end
    if utils.is_empty(config.notification_channel.gotify.host) then
        log.warn("notification_helper", "gotify host 未填写,跳过调用gotify")
        return
    end
    log.info("notification_helper", "正在发送gotify通知")
    local request_body = {
        title = sender_number,
        priority = config.notification_channel.gotify.priority,
        message = content
    }
    local schema = "http"
    if config.notification_channel.gotify.ssl then
        schema = "https"
    end
    local code, headers, response_body = http.request(
        "POST",
        schema .. "://" .. config.notification_channel.gotify.host .. ":" .. config.notification_channel.gotify.port .. "/message?token=" .. config.notification_channel.gotify.app_token,
        { ["Content-Type"] = "application/json" },
        json.encode(request_body)
    ).wait()
    if code ~= 200 then
        log.warn("notification_helper", "gotify发送消息失败,HTTP状态码:" .. code .. ",响应内容:" .. (response_body or ""))
    end
    log.info("notification_helper", "gotify通知发送完成")
end

local notification_channels = {
    bark = bark,
    luatos_notification = luatos_notification,
    server_chan = server_chan,
    ding_talk_bot = ding_talk_bot,
    pushplus = pushplus,
    telegram_bot = telegram_bot,
    feishu_bot = feishu_bot,
    wecom_bot = wecom_bot,
    gotify = gotify,
}

config.lua添加

config.notification_channel = {
// ...
gotify = {
        enabled = false,
        ssl = false,
        app_token = "",
        host = "",
        port = 80,
        priority = 5
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant