mqtt
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user