+notification from site +version bump fix
Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful

This commit is contained in:
Stephan D
2025-11-17 22:20:17 +01:00
parent c6a56071b5
commit 9dbf77a9a8
21 changed files with 543 additions and 9 deletions

View File

@@ -2,13 +2,17 @@ package notificationimp
import (
"context"
"fmt"
"github.com/tech/sendico/notification/interface/api"
mmail "github.com/tech/sendico/notification/internal/server/notificationimp/mail"
"github.com/tech/sendico/notification/internal/server/notificationimp/telegram"
"github.com/tech/sendico/pkg/domainprovider"
na "github.com/tech/sendico/pkg/messaging/notifications/account"
ni "github.com/tech/sendico/pkg/messaging/notifications/invitation"
snotifications "github.com/tech/sendico/pkg/messaging/notifications/site"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/model"
"github.com/tech/sendico/pkg/mservice"
"go.uber.org/zap"
)
@@ -17,6 +21,7 @@ type NotificationAPI struct {
logger mlogger.Logger
client mmail.Client
dp domainprovider.DomainProvider
tg telegram.Client
}
func (a *NotificationAPI) Name() mservice.Type {
@@ -33,11 +38,22 @@ func CreateAPI(a api.API) (*NotificationAPI, error) {
}
p.logger = a.Logger().Named(p.Name())
if a.Config().Notification == nil {
return nil, fmt.Errorf("notification configuration is missing")
}
if a.Config().Notification.Telegram == nil {
return nil, fmt.Errorf("telegram configuration is missing")
}
var err error
if p.client, err = mmail.CreateMailClient(p.logger.Named("mailer"), p.Name(), a.Register().Producer(), a.Localizer(), a.DomainProvider(), a.Config().Notification); err != nil {
p.logger.Error("Failed to create mail connection", zap.Error(err), zap.String("driver", a.Config().Notification.Driver))
return nil, err
}
if p.tg, err = telegram.NewClient(p.logger.Named("telegram"), a.Config().Notification.Telegram); err != nil {
p.logger.Error("Failed to create telegram client", zap.Error(err))
return nil, err
}
db, err := a.DBFactory().NewAccountDB()
if err != nil {
@@ -64,5 +80,22 @@ func CreateAPI(a api.API) (*NotificationAPI, error) {
return nil, err
}
if err := a.Register().Consumer(snotifications.NewDemoRequestProcessor(p.logger, p.onDemoRequest)); err != nil {
p.logger.Error("Failed to register demo request handler", zap.Error(err))
return nil, err
}
return p, nil
}
func (a *NotificationAPI) onDemoRequest(ctx context.Context, request *model.DemoRequest) error {
if a.tg == nil {
return fmt.Errorf("telegram client is not configured")
}
if err := a.tg.SendDemoRequest(ctx, request); err != nil {
a.logger.Warn("Failed to send demo request via telegram", zap.Error(err))
return err
}
a.logger.Info("Demo request sent via Telegram", zap.String("name", request.Name), zap.String("organization", request.OrganizationName))
return nil
}