forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushover.go
49 lines (39 loc) · 1002 Bytes
/
pushover.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
39
40
41
42
43
44
45
46
47
48
49
package push
import (
"errors"
"github.com/gregdel/pushover"
)
// PushOver implements the pushover messenger
type PushOver struct {
app *pushover.Pushover
recipients []string
}
type pushOverConfig struct {
App string
Recipients []string
Events map[string]EventTemplate
}
// NewPushOverMessenger creates new pushover messenger
func NewPushOverMessenger(app string, recipients []string) (*PushOver, error) {
if app == "" {
return nil, errors.New("pushover: missing app name")
}
m := &PushOver{
app: pushover.New(app),
recipients: recipients,
}
return m, nil
}
// Send sends to all receivers
func (m *PushOver) Send(title, msg string) {
message := pushover.NewMessageWithTitle(msg, title)
for _, id := range m.recipients {
go func(id string) {
log.TRACE.Printf("pushover: sending to %s", id)
recipient := pushover.NewRecipient(id)
if _, err := m.app.SendMessage(message, recipient); err != nil {
log.ERROR.Print(err)
}
}(id)
}
}