- Assign default circle to user when leaving a circle
- Support Pushover - Support Disable Signup - Migrate chatID to TargetID
This commit is contained in:
parent
850d472445
commit
adf5c0c0cd
20 changed files with 362 additions and 151 deletions
41
internal/notifier/notifier.go
Normal file
41
internal/notifier/notifier.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package notifier
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
nModel "donetick.com/core/internal/notifier/model"
|
||||
pushover "donetick.com/core/internal/notifier/service/pushover"
|
||||
telegram "donetick.com/core/internal/notifier/service/telegram"
|
||||
"donetick.com/core/logging"
|
||||
)
|
||||
|
||||
type Notifier struct {
|
||||
Telegram *telegram.TelegramNotifier
|
||||
Pushover *pushover.Pushover
|
||||
}
|
||||
|
||||
func NewNotifier(t *telegram.TelegramNotifier, p *pushover.Pushover) *Notifier {
|
||||
return &Notifier{
|
||||
Telegram: t,
|
||||
Pushover: p,
|
||||
}
|
||||
}
|
||||
|
||||
func (n *Notifier) SendNotification(c context.Context, notification *nModel.Notification) error {
|
||||
log := logging.FromContext(c)
|
||||
switch notification.TypeID {
|
||||
case nModel.NotificationTypeTelegram:
|
||||
if n.Telegram == nil {
|
||||
log.Error("Telegram bot is not initialized, Skipping sending message")
|
||||
return nil
|
||||
}
|
||||
return n.Telegram.SendNotification(c, notification)
|
||||
case nModel.NotificationTypePushover:
|
||||
if n.Pushover == nil {
|
||||
log.Error("Pushover is not initialized, Skipping sending message")
|
||||
return nil
|
||||
}
|
||||
return n.Pushover.SendNotification(c, notification)
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue