-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgotify.go
More file actions
26 lines (24 loc) · 737 Bytes
/
gotify.go
File metadata and controls
26 lines (24 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main
import (
"errors"
"fmt"
"net/http"
"net/url"
"github.com/mmcdole/gofeed"
)
func Send(item *gofeed.Item, feedName string, config map[string]string) (error) {
notificationMessage := fmt.Sprintf("%s: %s", item.Title, item.Link)
notificationTitle := fmt.Sprintf("New item in %s", feedName)
if len(config["url"]) > 0 && len(config["token"]) > 0 {
postURL := fmt.Sprintf("%s/message?token=%s", config["url"], config["token"])
response, err := http.PostForm(postURL,
url.Values{"message": {notificationMessage}, "title": {notificationTitle}})
if err != nil {
return err
}
fmt.Println("Gotify response: ", response.Status)
return err
} else {
return errors.New("gotify: Token or URL is not set")
}
}