mqtt
Some checks failed
CI / Test (1.22) (push) Failing after -23m51s
CI / Test (1.23) (push) Failing after -23m51s
CI / Lint (push) Has been cancelled
CI / Build (push) Has been cancelled
Release / Build and Release (push) Successful in -18m25s

This commit is contained in:
2025-12-29 23:36:22 +02:00
parent fd2527219e
commit ea1209c84c
14 changed files with 864 additions and 46 deletions

View File

@@ -1,6 +1,7 @@
package eventlogger
import (
"context"
"fmt"
"strings"
"sync"
@@ -8,6 +9,7 @@ import (
"git.warky.dev/wdevs/whatshooked/pkg/config"
"git.warky.dev/wdevs/whatshooked/pkg/events"
"git.warky.dev/wdevs/whatshooked/pkg/logging"
"go.mau.fi/whatsmeow/types"
)
// Logger handles event logging to multiple targets
@@ -24,8 +26,16 @@ type Target interface {
Close() error
}
// WhatsAppManager interface for MQTT target
type WhatsAppManager interface {
SendTextMessage(ctx context.Context, accountID string, jid types.JID, text string) error
SendImage(ctx context.Context, accountID string, jid types.JID, imageData []byte, mimeType string, caption string) error
SendVideo(ctx context.Context, accountID string, jid types.JID, videoData []byte, mimeType string, caption string) error
SendDocument(ctx context.Context, accountID string, jid types.JID, documentData []byte, mimeType string, filename string, caption string) error
}
// NewLogger creates a new event logger
func NewLogger(cfg config.EventLoggerConfig, dbConfig config.DatabaseConfig) (*Logger, error) {
func NewLogger(cfg config.EventLoggerConfig, dbConfig config.DatabaseConfig, waManager WhatsAppManager) (*Logger, error) {
logger := &Logger{
config: cfg,
dbConfig: dbConfig,
@@ -62,6 +72,15 @@ func NewLogger(cfg config.EventLoggerConfig, dbConfig config.DatabaseConfig) (*L
logger.targets = append(logger.targets, postgresTarget)
logging.Info("Event logger PostgreSQL target initialized")
case "mqtt":
mqttTarget, err := NewMQTTTarget(cfg.MQTT, waManager)
if err != nil {
logging.Error("Failed to initialize MQTT target", "error", err)
continue
}
logger.targets = append(logger.targets, mqttTarget)
logging.Info("Event logger MQTT target initialized")
default:
logging.Error("Unknown event logger target type", "type", targetType)
}