Adds 93 services, bringing the total to 109 plus webhook and email: chat and messengers (DingTalk, Feishu, LINE, Nextcloud Talk, Threema, WhatsApp gateways, Nostr, Home Assistant, …), push (Bark, Gorush, ServerChan, …), SMS and calls (Twilio, Plivo, 46elks, Alibaba Cloud, Teltonika routers, …), email APIs (SendGrid, Brevo, Resend, Microsoft Graph, …) and incident management (Grafana OnCall, Jira Service Management, Splunk On-Call, Squadcast, SIGNL4, …). Customers bring their own credentials; secrets are sealed like the others. Services pair incidents by their ID where they can resolve alerts. Signed requests (DingTalk, Nextcloud Talk, Alibaba Cloud) and replies that report failures with status 200 are handled. Nostr messages are sealed and gift-wrapped (NIP-17/59) with go-nostr, but sent over our own WebSocket connections so relays go through the network guard. Messages now carry the monitor's name, ID and target. The channel form groups services, the i18n test derives provider keys from the registry, and channel types may contain digits. Refs #92 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
172 lines
8.3 KiB
Go
172 lines
8.3 KiB
Go
package notify
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"regexp"
|
|
)
|
|
|
|
// Push services for phones and desktops.
|
|
|
|
var serverChanTurbo = regexp.MustCompile(`^(?i)sctp(\d+)t`)
|
|
|
|
var pushProviders = []Provider{
|
|
{Type: "bark", Group: "push", Fields: []Field{secretURL("endpoint_url"), text("group", false), text("sound", false)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
// The endpoint includes the device key, e.g.
|
|
// https://api.day.app/KEY.
|
|
return c.json(ctx, http.MethodPost, trimURL(cfg["endpoint_url"]), nil, map[string]any{
|
|
"title": m.Title, "body": m.Body, "url": m.URL,
|
|
"group": or(cfg["group"], "UptimeSebi"), "sound": or(cfg["sound"], "telegraph"),
|
|
})
|
|
}},
|
|
{Type: "gorush", Group: "push", Fields: []Field{
|
|
urlField("server_url", true, ""), secret("device_token", true),
|
|
{Name: "platform", Kind: "select", Options: []string{"ios", "android", "huawei"}, Default: "ios"},
|
|
text("topic", false),
|
|
{Name: "priority", Kind: "select", Options: []string{"high", "normal"}, Default: "high"},
|
|
}, send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
platform := map[string]int{"ios": 1, "android": 2, "huawei": 3}[cfg["platform"]]
|
|
return c.json(ctx, http.MethodPost, trimURL(cfg["server_url"])+"/api/push", nil, map[string]any{
|
|
"notifications": []map[string]any{{
|
|
"tokens": []string{cfg["device_token"]}, "platform": platform, "title": m.Title, "message": m.Body,
|
|
"priority": or(cfg["priority"], "high"), "topic": cfg["topic"],
|
|
}},
|
|
})
|
|
}},
|
|
{Type: "lunasea", Group: "push", Fields: []Field{
|
|
{Name: "target", Kind: "select", Options: []string{"device", "user"}, Default: "device"},
|
|
secret("target_id", true),
|
|
}, send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
target := "device"
|
|
if cfg["target"] == "user" {
|
|
target = "user"
|
|
}
|
|
return c.json(ctx, http.MethodPost, "https://notify.lunasea.app/v1/custom/"+target+"/"+url.PathEscape(cfg["target_id"]), nil,
|
|
map[string]any{"title": m.Title, "body": m.Body})
|
|
}},
|
|
{Type: "notifery", Group: "push", Fields: []Field{secret("api_key", true), text("group", false)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
body := map[string]any{"title": m.Title, "message": m.Body + "\n" + m.URL}
|
|
if cfg["group"] != "" {
|
|
body["group"] = cfg["group"]
|
|
}
|
|
switch m.Event {
|
|
case Opened:
|
|
body["code"] = 1
|
|
case Resolved:
|
|
body["code"] = 0
|
|
}
|
|
return c.json(ctx, http.MethodPost, "https://api.notifery.com/event", http.Header{"x-api-key": {cfg["api_key"]}}, body)
|
|
}},
|
|
{Type: "notifyapp", Group: "push", Fields: []Field{text("device_id", true), secret("token", true)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
u := "https://push.getnotifyapp.com/notify-json/" + url.PathEscape(cfg["device_id"]) + "?token=" + url.QueryEscape(cfg["token"])
|
|
return c.json(ctx, http.MethodPost, u, nil, map[string]any{"title": m.Title, "text": m.Body, "timeSensitive": m.Event == Opened})
|
|
}},
|
|
{Type: "pushdeer", Group: "push", Fields: []Field{secret("push_key", true), urlField("server_url", false, "https://api2.pushdeer.com")},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
reply, err := c.callJSON(ctx, http.MethodPost, trimURL(or(cfg["server_url"], "https://api2.pushdeer.com"))+"/message/push", nil,
|
|
map[string]any{"pushkey": cfg["push_key"], "text": m.Title, "desp": m.Body + "\n\n" + m.URL, "type": "markdown"})
|
|
return replyCheck(reply, err, func(v map[string]any) string {
|
|
if e := str(v["error"]); e != "" {
|
|
return "PushDeer: " + e
|
|
}
|
|
return ""
|
|
})
|
|
}},
|
|
{Type: "pushplus", Group: "push", Fields: []Field{secret("send_key", true)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
reply, err := c.callJSON(ctx, http.MethodPost, "https://www.pushplus.plus/send", nil,
|
|
map[string]any{"token": cfg["send_key"], "title": m.Title, "content": m.Body + "\n" + m.URL, "template": "txt"})
|
|
return replyCheck(reply, err, func(v map[string]any) string {
|
|
if str(v["code"]) != "200" {
|
|
return "PushPlus: " + str(v["msg"])
|
|
}
|
|
return ""
|
|
})
|
|
}},
|
|
{Type: "pushy", Group: "push", Fields: []Field{secret("api_key", true), text("device_token", true)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
return c.json(ctx, http.MethodPost, "https://api.pushy.me/push?api_key="+url.QueryEscape(cfg["api_key"]), nil, map[string]any{
|
|
"to": cfg["device_token"], "data": map[string]any{"message": m.Title, "url": m.URL},
|
|
"notification": map[string]any{"title": m.Title, "body": m.Body, "badge": 1, "sound": "ping.aiff"},
|
|
})
|
|
}},
|
|
{Type: "serverchan", Group: "push", Fields: []Field{secret("send_key", true)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
key := cfg["send_key"]
|
|
u := "https://sctapi.ftqq.com/" + url.PathEscape(key) + ".send"
|
|
// ServerChan³ keys name their own host.
|
|
if g := serverChanTurbo.FindStringSubmatch(key); g != nil {
|
|
u = "https://" + g[1] + ".push.ft07.com/send/" + url.PathEscape(key) + ".send"
|
|
}
|
|
return c.json(ctx, http.MethodPost, u, nil, map[string]any{"title": m.Title, "desp": m.Body + "\n\n" + m.URL})
|
|
}},
|
|
{Type: "signalgrid", Group: "push", Fields: []Field{secret("client_key", true), text("channel", true)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
typ := map[string]string{"down": "CRIT", "up": "SUCCESS"}[m.status()]
|
|
reply, err := c.form(ctx, "https://api.signalgrid.co/v1/push", nil, url.Values{
|
|
"client_key": {cfg["client_key"]}, "channel": {cfg["channel"]}, "title": {m.Title},
|
|
"body": {m.Body + "\n" + m.URL}, "type": {or(typ, "INFO")}, "critical": {"false"},
|
|
})
|
|
return replyCheck(reply, err, func(v map[string]any) string {
|
|
if code := str(v["code"]); code != "" && code != "200" {
|
|
return "Signalgrid: " + str(v["text"])
|
|
}
|
|
return ""
|
|
})
|
|
}},
|
|
{Type: "spugpush", Group: "push", Fields: []Field{secret("template_key", true)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
return c.json(ctx, http.MethodPost, "https://push.spug.cc/send/"+url.PathEscape(cfg["template_key"]), nil,
|
|
map[string]any{"title": m.Title, "content": m.Body + "\n" + m.URL})
|
|
}},
|
|
{Type: "techulus", Group: "push", Fields: []Field{secret("api_key", true), text("channel", false), text("sound", false)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
body := map[string]any{"title": m.Title, "body": m.Body + "\n" + m.URL, "timeSensitive": m.Event == Opened}
|
|
if cfg["channel"] != "" {
|
|
body["channel"] = cfg["channel"]
|
|
}
|
|
if cfg["sound"] != "" {
|
|
body["sound"] = cfg["sound"]
|
|
}
|
|
return c.json(ctx, http.MethodPost, "https://push.techulus.com/api/v1/notify/"+url.PathEscape(cfg["api_key"]), nil, body)
|
|
}},
|
|
{Type: "wpush", Group: "push", Fields: []Field{secret("api_key", true), text("channel", true)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
reply, err := c.callJSON(ctx, http.MethodPost, "https://api.wpush.cn/api/v1/send", nil,
|
|
map[string]any{"title": m.Title, "content": m.Body + "\n" + m.URL, "apikey": cfg["api_key"], "channel": cfg["channel"]})
|
|
return replyCheck(reply, err, func(v map[string]any) string {
|
|
if str(v["code"]) != "0" {
|
|
return "WPush: " + str(v["message"])
|
|
}
|
|
return ""
|
|
})
|
|
}},
|
|
{Type: "wxpusher", Group: "push", Fields: []Field{secret("spt", true)},
|
|
send: func(ctx context.Context, c *client, cfg map[string]string, m Message) error {
|
|
// Simple push tokens, up to ten per request.
|
|
spts := list(cfg["spt"])
|
|
for i := 0; i < len(spts); i += 10 {
|
|
reply, err := c.callJSON(ctx, http.MethodPost, "https://wxpusher.zjiecode.com/api/send/message/simple-push", nil, map[string]any{
|
|
"content": m.text(), "summary": truncate(m.Title, 100), "contentType": 1, "sptList": spts[i:min(i+10, len(spts))],
|
|
})
|
|
if err := replyCheck(reply, err, func(v map[string]any) string {
|
|
if str(v["code"]) != "1000" {
|
|
return "WxPusher: " + str(v["msg"])
|
|
}
|
|
return ""
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if len(spts) == 0 {
|
|
return fmt.Errorf("no SPT set")
|
|
}
|
|
return nil
|
|
}},
|
|
}
|