-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.go
38 lines (33 loc) · 1.03 KB
/
notify.go
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
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"github.com/gregdel/pushover"
"regexp"
"strings"
"time"
)
// sends the pushover notification on a new submission
func notify(pushOverApp *pushover.Pushover, pushoverUserToken, pretalxURL string, messages []string) (response *pushover.Response, err error) {
title := fmt.Sprintf("PreTalx: Changed submissions detected")
message := strings.Join(messages, "\n")
recipient := pushover.NewRecipient(pushoverUserToken)
// remove the API part from the URL
r := regexp.MustCompile(`(.*).*/.*/.*/.+/?`)
url := r.FindString(pretalxURL)
// strip the message if it is longer than 1k characters (limit of pushover)
if len(message) > 1024 {
message = message[:1020] + "..."
}
messageObject := &pushover.Message{
Message: message,
Title: title,
URL: url,
URLTitle: "PreTalx",
Timestamp: time.Now().Unix(),
Retry: 60 * time.Second,
DeviceName: "PreTalx-Notifier",
Sound: pushover.SoundCosmic,
}
response, err = pushOverApp.SendMessage(messageObject, recipient)
return
}