Add Event Producer
Update User to carry webhook from circle if assigned Refactor notification handling and update models for webhook support
This commit is contained in:
parent
44cb5501dd
commit
04d1894aea
17 changed files with 351 additions and 101 deletions
|
@ -3,39 +3,52 @@ package notifier
|
|||
import (
|
||||
"context"
|
||||
|
||||
"donetick.com/core/internal/events"
|
||||
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
|
||||
Telegram *telegram.TelegramNotifier
|
||||
Pushover *pushover.Pushover
|
||||
eventsProducer *events.EventsProducer
|
||||
}
|
||||
|
||||
func NewNotifier(t *telegram.TelegramNotifier, p *pushover.Pushover) *Notifier {
|
||||
func NewNotifier(t *telegram.TelegramNotifier, p *pushover.Pushover, ep *events.EventsProducer) *Notifier {
|
||||
return &Notifier{
|
||||
Telegram: t,
|
||||
Pushover: p,
|
||||
Telegram: t,
|
||||
Pushover: p,
|
||||
eventsProducer: ep,
|
||||
}
|
||||
}
|
||||
|
||||
func (n *Notifier) SendNotification(c context.Context, notification *nModel.Notification) error {
|
||||
func (n *Notifier) SendNotification(c context.Context, notification *nModel.NotificationDetails) error {
|
||||
log := logging.FromContext(c)
|
||||
var err error
|
||||
switch notification.TypeID {
|
||||
case nModel.NotificationTypeTelegram:
|
||||
case nModel.NotificationPlatformTelegram:
|
||||
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:
|
||||
err = n.Telegram.SendNotification(c, notification)
|
||||
case nModel.NotificationPlatformPushover:
|
||||
if n.Pushover == nil {
|
||||
log.Error("Pushover is not initialized, Skipping sending message")
|
||||
return nil
|
||||
}
|
||||
return n.Pushover.SendNotification(c, notification)
|
||||
err = n.Pushover.SendNotification(c, notification)
|
||||
}
|
||||
if err != nil {
|
||||
log.Error("Failed to send notification", "err", err)
|
||||
}
|
||||
if notification.RawEvent != nil && notification.WebhookURL != nil {
|
||||
// if we have a webhook url, we should send the event to the webhook
|
||||
n.eventsProducer.NotificaitonEvent(c, *notification.WebhookURL, notification.RawEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue