From 1ed5bdfdc933aebcd2f22f0b530566d54d1e8d34 Mon Sep 17 00:00:00 2001 From: Simon Rieger Date: Tue, 1 Jul 2025 20:38:44 +0200 Subject: [PATCH] =?UTF-8?q?Hinzuf=C3=BCgen=20eines=20Action=20Buttons=20um?= =?UTF-8?q?=20den=20Beitrag=20anzuzgeigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index f552c1d..389ef50 100644 --- a/main.go +++ b/main.go @@ -29,18 +29,29 @@ type Notification struct { CreatedAt string `json:"created_at"` Account struct { DisplayName string `json:"display_name"` + Acct string `json:"acct"` } `json:"account"` Status struct { + ID string `json:"id"` Content string `json:"content"` + URL string `json:"url"` // Original-URL des Posts } `json:"status"` } +type NtfyAction struct { + Action string `json:"action"` + Label string `json:"label"` + URL string `json:"url"` + Clear bool `json:"clear"` +} + type NtfyMessage struct { - Topic string `json:"topic"` - Title string `json:"title"` - Message string `json:"message"` - Tags []string `json:"tags"` - Priority int `json:"priority"` + Topic string `json:"topic"` + Title string `json:"title"` + Message string `json:"message"` + Tags []string `json:"tags"` + Priority int `json:"priority"` + Actions []NtfyAction `json:"actions,omitempty"` } func main() { @@ -129,31 +140,39 @@ func fetchNotifications(sinceID string) ([]Notification, error) { // HTML zu Plaintext konvertieren func htmlToPlaintext(html string) string { - // Ersetze HTML-Tags re := regexp.MustCompile(`<[^>]*>`) plain := re.ReplaceAllString(html, "") - - // Ersetze HTML-Entities plain = strings.ReplaceAll(plain, "<", "<") plain = strings.ReplaceAll(plain, ">", ">") plain = strings.ReplaceAll(plain, "&", "&") plain = strings.ReplaceAll(plain, """, "\"") plain = strings.ReplaceAll(plain, "'", "'") - return plain } func sendToNtfy(n Notification) error { - // HTML zu Plaintext konvertieren plainContent := htmlToPlaintext(n.Status.Content) - title := fmt.Sprintf("Neue Benachrichtigung von %s", n.Account.DisplayName) + + var actions []NtfyAction + if n.Status.URL != "" { + actions = []NtfyAction{ + { + Action: "view", + Label: "Beitrag anzeigen", + URL: n.Status.URL, + Clear: true, + }, + } + } + msg := NtfyMessage{ - Topic: ntfyTopic, - Title: title, - Message: fmt.Sprintf("Typ: %s\n\n%s", n.Type, plainContent), - Tags: []string{"bell", "incoming_envelope"}, + Topic: ntfyTopic, + Title: title, + Message: fmt.Sprintf("Typ: %s\n\n%s", n.Type, plainContent), + Tags: []string{"bell", "incoming_envelope"}, Priority: 4, + Actions: actions, } jsonData, err := json.Marshal(msg)