mirror of
https://github.com/42wim/matterbridge.git
synced 2025-05-23 18:27:39 +03:00
Added validation checks to allow private chats.
This commit is contained in:
parent
c4157a4d5b
commit
89b0fa90cd
@ -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{}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user