Fixed mqtt bug where phone number is not formatted
Some checks failed
CI / Test (1.23) (push) Failing after -22m52s
CI / Test (1.22) (push) Failing after -22m44s
CI / Build (push) Successful in -25m59s
CI / Lint (push) Successful in -25m47s

This commit is contained in:
2025-12-30 01:00:42 +02:00
parent 7b2390cbf6
commit d80a6433b9
3 changed files with 18 additions and 13 deletions

View File

@@ -17,14 +17,15 @@ import (
// MQTTTarget represents an MQTT logging target
type MQTTTarget struct {
client mqtt.Client
config config.MQTTConfig
waManager WhatsAppManager
eventFilter map[string]bool
client mqtt.Client
config config.MQTTConfig
waManager WhatsAppManager
eventFilter map[string]bool
defaultCountryCode string
}
// NewMQTTTarget creates a new MQTT target
func NewMQTTTarget(cfg config.MQTTConfig, waManager WhatsAppManager) (*MQTTTarget, error) {
func NewMQTTTarget(cfg config.MQTTConfig, waManager WhatsAppManager, defaultCountryCode string) (*MQTTTarget, error) {
if cfg.Broker == "" {
return nil, fmt.Errorf("MQTT broker is required")
}
@@ -41,9 +42,10 @@ func NewMQTTTarget(cfg config.MQTTConfig, waManager WhatsAppManager) (*MQTTTarge
}
target := &MQTTTarget{
config: cfg,
waManager: waManager,
eventFilter: make(map[string]bool),
config: cfg,
waManager: waManager,
eventFilter: make(map[string]bool),
defaultCountryCode: defaultCountryCode,
}
// Build event filter map for fast lookup
@@ -183,10 +185,13 @@ func (m *MQTTTarget) handleSendMessage(client mqtt.Client, msg mqtt.Message) {
sendReq.Type = "text"
}
// Format phone number to JID format
formattedJID := utils.FormatPhoneToJID(sendReq.To, m.defaultCountryCode)
// Parse JID
jid, err := types.ParseJID(sendReq.To)
jid, err := types.ParseJID(formattedJID)
if err != nil {
logging.Error("Failed to parse JID", "to", sendReq.To, "error", err)
logging.Error("Failed to parse JID", "to", sendReq.To, "formatted", formattedJID, "error", err)
return
}