-
Notifications
You must be signed in to change notification settings - Fork 7
/
notification.go
40 lines (35 loc) · 946 Bytes
/
notification.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
package main
type notificatorConfig struct {
Type string
MinAmount uint64
Params map[string]string
}
type notificator interface {
Notify(amount uint64, comment string) error
Target() string
}
var notificators []notificator
func setupNotificators(cfg ServerConfig) {
for _, c := range cfg.Notificators {
switch c.Type {
case "mail":
notificators = append(notificators, NewMailNotificator(c))
case "http":
notificators = append(notificators, NewHttpNotificator(c))
case "telegram":
notificators = append(notificators, NewTelegramNotificator(c))
}
}
}
func broadcastNotification(amount uint64, comment string) {
log.Infof("Received %d sats with comment: %s", amount, comment)
for _, n := range notificators {
err := n.Notify(amount, comment)
if err != nil {
log.Infof("Error sending notification to %s: %s",
n.Target(), err)
} else {
log.Infof("Notification sent to %s", n.Target())
}
}
}