forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoutrrr.go
45 lines (36 loc) · 822 Bytes
/
shoutrrr.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
package push
import (
"fmt"
"github.com/containrrr/shoutrrr"
"github.com/containrrr/shoutrrr/pkg/router"
"github.com/containrrr/shoutrrr/pkg/types"
)
// Shoutrrr implements the shoutrrr messaging aggregator
type Shoutrrr struct {
app *router.ServiceRouter
}
type shoutrrrConfig struct {
URI string
}
// NewShoutrrrMessenger creates new Shoutrrr messenger
func NewShoutrrrMessenger(uri string) (*Shoutrrr, error) {
app, err := shoutrrr.CreateSender(uri)
if err != nil {
return nil, fmt.Errorf("shoutrrr: %v", err)
}
m := &Shoutrrr{
app: app,
}
return m, nil
}
// Send sends to all receivers
func (m *Shoutrrr) Send(title, msg string) {
params := &types.Params{
"title": title,
}
for _, err := range m.app.Send(msg, params) {
if err != nil {
log.ERROR.Printf("shoutrrr: %v", err)
}
}
}