diff --git a/bridge/whatsappmulti/helpers.go b/bridge/whatsappmulti/helpers.go index 5eac958e..c6478656 100644 --- a/bridge/whatsappmulti/helpers.go +++ b/bridge/whatsappmulti/helpers.go @@ -133,6 +133,10 @@ func isGroupJid(identifier string) bool { strings.HasSuffix(identifier, "@broadcast") } +func isPrivateJid(identifier string) bool { + return strings.HasSuffix(identifier, "@s.whatsapp.net") +} + func (b *Bwhatsapp) getDevice() (*store.Device, error) { device := &store.Device{} diff --git a/bridge/whatsappmulti/whatsapp.go b/bridge/whatsappmulti/whatsapp.go index e7c0f691..3cbc689e 100644 --- a/bridge/whatsappmulti/whatsapp.go +++ b/bridge/whatsappmulti/whatsapp.go @@ -171,10 +171,29 @@ func (b *Bwhatsapp) Disconnect() error { return nil } -// JoinChannel Join a WhatsApp group specified in gateway config as channel='number-id@g.us' or channel='Channel name' +// JoinChannel Join a WhatsApp group specified in gateway config as +// channel='number-id@g.us' or channel='Channel name' or channel='number@s.whatsapp.net' // Required implementation of the Bridger interface // https://github.com/42wim/matterbridge/blob/2cfd880cdb0df29771bf8f31df8d990ab897889d/bridge/bridge.go#L11-L16 func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error { + + // Check if this is a private chat JID + if isPrivateJid(channel.Name) { + // For private chats, validate the JID format but don't require group membership + jid, err := types.ParseJID(channel.Name) + if err != nil { + return fmt.Errorf("invalid WhatsApp private chat JID format: %s", err) + } + + // Optionally verify that the contact exists in the contacts list + if _, exists := b.contacts[jid]; !exists { + b.Log.Warnf("Private chat contact %s not found in contacts list, but will attempt to bridge anyway", channel.Name) + } + + b.Log.Infof("Configured private chat channel: %s", channel.Name) + return nil + } + byJid := isGroupJid(channel.Name) // verify if we are member of the given group