forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
45 lines (38 loc) · 1.01 KB
/
config.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"
"strings"
"github.com/evcc-io/evcc/util"
)
// Sender implements message sending
type Sender interface {
Send(title, msg string)
}
// EventTemplate is the push message template for an event
type EventTemplate struct {
Title, Msg string
}
var log = util.NewLogger("push")
// NewMessengerFromConfig creates a new messenger
func NewMessengerFromConfig(typ string, other map[string]interface{}) (res Sender, err error) {
switch strings.ToLower(typ) {
case "pushover":
var cc pushOverConfig
if err = util.DecodeOther(other, &cc); err == nil {
res, err = NewPushOverMessenger(cc.App, cc.Recipients)
}
case "telegram":
var cc telegramConfig
if err = util.DecodeOther(other, &cc); err == nil {
res, err = NewTelegramMessenger(cc.Token, cc.Chats)
}
case "email", "shout":
var cc shoutrrrConfig
if err = util.DecodeOther(other, &cc); err == nil {
res, err = NewShoutrrrMessenger(cc.URI)
}
default:
err = fmt.Errorf("unknown messenger type: %s", typ)
}
return res, err
}