nomadcode/services/core/internal/notification/service.go
toki e36db7281b feat: update project rules, roadmap, and core service changes
- Update agent-ops project rules and roadmap files
- Add proto-socket infrastructure communication rail milestone
- Update Flutter pubspec.lock and contracts notes
- Enhance core service: config, HTTP middleware, router
- Add notification module improvements
- Add protosocket internal package
2026-05-30 19:32:48 +09:00

57 lines
1.4 KiB
Go

package notification
import (
"context"
"errors"
"log/slog"
"github.com/nomadcode/nomadcode-core/internal/adapters/mattermost"
)
type Service struct {
mattermost *mattermost.Client
logger *slog.Logger
sinks []TaskEventSink
}
func NewService(mattermostClient *mattermost.Client, logger *slog.Logger, sinks ...TaskEventSink) *Service {
return &Service{
mattermost: mattermostClient,
logger: logger,
sinks: append([]TaskEventSink{}, sinks...),
}
}
func (s *Service) NotifyTaskCompleted(ctx context.Context, input TaskNotification) error {
return s.NotifyTaskEvent(ctx, TaskEvent{
Type: TaskEventCompleted,
TaskID: input.TaskID,
Title: input.Title,
Status: input.Status,
Message: input.Message,
})
}
func (s *Service) NotifyTaskEvent(ctx context.Context, input TaskEvent) error {
if s.logger != nil {
s.logger.Info("task event notification requested", "type", input.Type, "task_id", input.TaskID)
}
var errs []error
for _, sink := range s.sinks {
if err := sink.HandleTaskEvent(ctx, input); err != nil {
errs = append(errs, err)
}
}
if input.Type == TaskEventCompleted && s.mattermost != nil {
errs = append(errs, s.mattermost.SendTaskNotification(ctx, mattermost.TaskNotificationInput{
TaskID: input.TaskID,
Title: input.Title,
Status: input.Status,
Message: input.Message,
}))
}
return errors.Join(errs...)
}