refactored notificatoin / tgsettle responsibility boundaries

This commit is contained in:
Stephan D
2026-02-19 18:56:59 +01:00
parent 47f0a3d890
commit 2fd8a6ebb7
73 changed files with 3705 additions and 681 deletions

View File

@@ -6,6 +6,9 @@ import (
"net/http"
"github.com/tech/sendico/notification/internal/server/notificationimp/telegram"
tnotifications "github.com/tech/sendico/pkg/messaging/notifications/telegram"
"github.com/tech/sendico/pkg/model"
"github.com/tech/sendico/pkg/mservice"
"go.uber.org/zap"
)
@@ -16,11 +19,11 @@ func (a *NotificationAPI) handleTelegramWebhook(w http.ResponseWriter, r *http.R
w.WriteHeader(http.StatusNoContent)
return
}
if a.confirm == nil {
if a.producer == nil {
if a.logger != nil {
a.logger.Warn("Telegram webhook ignored: confirmation manager is not configured")
a.logger.Warn("Telegram webhook ignored: messaging producer is not configured")
}
w.WriteHeader(http.StatusNoContent)
w.WriteHeader(http.StatusServiceUnavailable)
return
}
var update telegram.Update
@@ -52,6 +55,19 @@ func (a *NotificationAPI) handleTelegramWebhook(w http.ResponseWriter, r *http.R
}
a.logger.Info("Telegram webhook update received", fields...)
}
a.confirm.HandleUpdate(r.Context(), &update)
payload := &model.TelegramWebhookUpdate{
UpdateID: update.UpdateID,
}
if update.Message != nil {
payload.Message = update.Message.ToModel()
}
env := tnotifications.TelegramUpdate(string(mservice.Notifications), payload)
if err := a.producer.SendMessage(env); err != nil {
if a.logger != nil {
a.logger.Warn("Failed to publish telegram webhook update", zap.Error(err), zap.Int64("update_id", update.UpdateID))
}
w.WriteHeader(http.StatusServiceUnavailable)
return
}
w.WriteHeader(http.StatusOK)
}