Fixed mqtt bug where phone number is not formatted
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user