forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshoutrrr.go
55 lines (45 loc) · 1.04 KB
/
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
46
47
48
49
50
51
52
53
54
55
package push
import (
"github.com/containrrr/shoutrrr"
"github.com/containrrr/shoutrrr/pkg/router"
"github.com/containrrr/shoutrrr/pkg/types"
"github.com/evcc-io/evcc/util"
)
func init() {
registry.Add("email", NewShoutrrrFromConfig)
registry.Add("shout", NewShoutrrrFromConfig)
}
// Shoutrrr implements the shoutrrr messaging aggregator
type Shoutrrr struct {
log *util.Logger
app *router.ServiceRouter
}
// NewShoutrrrFromConfig creates new Shoutrrr messenger
func NewShoutrrrFromConfig(other map[string]interface{}) (Messenger, error) {
var cc struct {
URI string
}
if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}
app, err := shoutrrr.CreateSender(cc.URI)
if err != nil {
return nil, err
}
m := &Shoutrrr{
log: util.NewLogger("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 {
m.log.ERROR.Println("send:", err)
}
}
}