From 5a88071e741a90aecbaa94df1cd66f4cf7861e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Desgualdo=20Pereira?= Date: Sun, 5 Jul 2026 06:45:58 -0300 Subject: [PATCH 1/2] Add a parse for VCard contact information --- lib/wmchat/go/gowm.go | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/lib/wmchat/go/gowm.go b/lib/wmchat/go/gowm.go index 15f3bdd9..b3929193 100644 --- a/lib/wmchat/go/gowm.go +++ b/lib/wmchat/go/gowm.go @@ -20,6 +20,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "runtime" "runtime/debug" "slices" @@ -1592,6 +1593,92 @@ func (handler *WmEventHandler) HandleMessage(messageInfo types.MessageInfo, msg case msg.PinInChatMessage != nil: handler.HandlePinInChatMessage(messageInfo, msg) + case msg.ContactMessage != nil: + displayName := msg.ContactMessage.GetDisplayName() + vcard := msg.ContactMessage.GetVcard() + + reTel := regexp.MustCompile(`(?m)^TEL[^:]*:(.+)`) + telMatches := reTel.FindAllStringSubmatch(vcard, -1) + + var phones []string + for _, match := range telMatches { + if len(match) > 1 { + // Clean up any carriage returns or spaces + phones = append(phones, strings.TrimSpace(match[1])) + } + } + + reEmail := regexp.MustCompile(`(?m)^EMAIL[^:]*:(.+)`) + emailMatches := reEmail.FindAllStringSubmatch(vcard, -1) + + var emails []string + for _, match := range emailMatches { + if len(match) > 1 { + emails = append(emails, strings.TrimSpace(match[1])) + } + } + + // Construct the text display layout for nchat + var sb strings.Builder + sb.WriteString(fmt.Sprintf("[Contact Card] %s", displayName)) + + if len(phones) > 0 { + sb.WriteString(fmt.Sprintf("\nPhone: %s", strings.Join(phones, ", "))) + } + if len(emails) > 0 { + sb.WriteString(fmt.Sprintf("\nEmail: %s", strings.Join(emails, ", "))) + } + + contactText := sb.String() + msg.Conversation = &contactText + handler.HandleTextMessage(messageInfo, msg, isSyncRead) + + case msg.ContactsArrayMessage != nil: + var sb strings.Builder + sb.WriteString("[Multiple Contact Cards]") + + // Loop through every contact in the array + for _, contact := range msg.ContactsArrayMessage.Contacts { + displayName := contact.GetDisplayName() + vcard := contact.GetVcard() + + if displayName == "" && vcard == "" { + continue + } + + // Parse phone numbers from this specific contact's vcard + reTel := regexp.MustCompile(`(?m)^TEL[^:]*:(.+)`) + telMatches := reTel.FindAllStringSubmatch(vcard, -1) + var phones []string + for _, match := range telMatches { + if len(match) > 1 { + phones = append(phones, strings.TrimSpace(match[1])) + } + } + + // Parse emails from this specific contact's vcard + reEmail := regexp.MustCompile(`(?m)^EMAIL[^:]*:(.+)`) + emailMatches := reEmail.FindAllStringSubmatch(vcard, -1) + var emails []string + for _, match := range emailMatches { + if len(match) > 1 { + emails = append(emails, strings.TrimSpace(match[1])) + } + } + + // Format this individual contact entry + sb.WriteString(fmt.Sprintf("\n\n%s", displayName)) + if len(phones) > 0 { + sb.WriteString(fmt.Sprintf("\nPhone: %s", strings.Join(phones, ", "))) + } + if len(emails) > 0 { + sb.WriteString(fmt.Sprintf("\nEmail: %s", strings.Join(emails, ", "))) + } + } + + contactText := sb.String() + msg.Conversation = &contactText + handler.HandleTextMessage(messageInfo, msg, isSyncRead) default: handler.HandleUnsupportedMessage(messageInfo, msg, isSyncRead) } From 3be99e366a82ed3b36ff729216e726c47a4df691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Desgualdo=20Pereira?= Date: Tue, 7 Jul 2026 08:43:25 -0300 Subject: [PATCH 2/2] better regex to match phone and email --- lib/wmchat/go/gowm.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/wmchat/go/gowm.go b/lib/wmchat/go/gowm.go index b3929193..9cc36f1c 100644 --- a/lib/wmchat/go/gowm.go +++ b/lib/wmchat/go/gowm.go @@ -1597,7 +1597,7 @@ func (handler *WmEventHandler) HandleMessage(messageInfo types.MessageInfo, msg displayName := msg.ContactMessage.GetDisplayName() vcard := msg.ContactMessage.GetVcard() - reTel := regexp.MustCompile(`(?m)^TEL[^:]*:(.+)`) + reTel := regexp.MustCompile(`(?i)TEL[^:]*:(.+)`) telMatches := reTel.FindAllStringSubmatch(vcard, -1) var phones []string @@ -1608,7 +1608,7 @@ func (handler *WmEventHandler) HandleMessage(messageInfo types.MessageInfo, msg } } - reEmail := regexp.MustCompile(`(?m)^EMAIL[^:]*:(.+)`) + reEmail := regexp.MustCompile(`(?i)EMAIL[^:]*:(.+)`) emailMatches := reEmail.FindAllStringSubmatch(vcard, -1) var emails []string @@ -1647,7 +1647,7 @@ func (handler *WmEventHandler) HandleMessage(messageInfo types.MessageInfo, msg } // Parse phone numbers from this specific contact's vcard - reTel := regexp.MustCompile(`(?m)^TEL[^:]*:(.+)`) + reTel := regexp.MustCompile(`(?i)TEL[^:]*:(.+)`) telMatches := reTel.FindAllStringSubmatch(vcard, -1) var phones []string for _, match := range telMatches { @@ -1657,7 +1657,7 @@ func (handler *WmEventHandler) HandleMessage(messageInfo types.MessageInfo, msg } // Parse emails from this specific contact's vcard - reEmail := regexp.MustCompile(`(?m)^EMAIL[^:]*:(.+)`) + reEmail := regexp.MustCompile(`(?i)EMAIL[^:]*:(.+)`) emailMatches := reEmail.FindAllStringSubmatch(vcard, -1) var emails []string for _, match := range emailMatches {