GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.
Go botgogolanggolang-whatsappgolang-whatsapp-apirestrest-apiwhatsappwhatsapp-apiwhatsapp-api-gowhatsapp-multi-devicewhatsapp-web-multi-device
fix(utils): read grouped TEL properties when extracting the vCard phone (#858)
Elio Bonfim Júniordc6d11afa431
diff --git a/src/pkg/utils/whatsapp.go b/src/pkg/utils/whatsapp.goindex fa8a68f5..b0736fef 100644--- a/src/pkg/utils/whatsapp.go+++ b/src/pkg/utils/whatsapp.go@@ -94,15 +94,31 @@ func ExtractPhoneFromVCard(vcard string) string {for _, line := range lines {line = strings.TrimSpace(line)- if strings.HasPrefix(strings.ToUpper(line), "TEL") {- if idx := strings.LastIndex(line, ":"); idx >= 0 {- return strings.TrimSpace(line[idx+1:])- }+ if !isVCardTelProperty(line) {+ continue+ }+ if idx := strings.LastIndex(line, ":"); idx >= 0 {+ return strings.TrimSpace(line[idx+1:])}}return ""}+// isVCardTelProperty reports whether a vCard content line is a TEL property.+// vCard allows any property name to carry a group prefix, and iOS exports every+// phone that way ("item1.TEL;waid=...:+55 11 99999-0006"), so the group is+// dropped before comparing the name.+func isVCardTelProperty(line string) bool {+ name := line+ if idx := strings.IndexAny(name, ";:"); idx >= 0 {+ name = name[:idx]+ }+ if idx := strings.LastIndex(name, "."); idx >= 0 {+ name = name[idx+1:]+ }+ return strings.EqualFold(strings.TrimSpace(name), "TEL")+}+// FormatLocationSummary builds a one-liner for an incoming location or live-location pin.// The maps link is always included so content is never empty for coordinate-only pins.// name and address are optional prefixes.diff --git a/src/pkg/utils/whatsapp_test.go b/src/pkg/utils/whatsapp_test.goindex d6ed7efc..e675307e 100644--- a/src/pkg/utils/whatsapp_test.go+++ b/src/pkg/utils/whatsapp_test.go@@ -85,6 +85,29 @@ func TestExtractPhoneFromVCard(t *testing.T) {vcard: "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:Julio\r\nTEL;type=CELL;waid=5511998913283:\r\n +5511998913283\r\nEND:VCARD",want: "+5511998913283",},+ {+ // iOS exports every phone with a group prefix and an Apple label line.+ name: "GroupedTelFromIOS",+ vcard: "BEGIN:VCARD\nVERSION:3.0\nN:;Dave;;;\nFN:Dave\nitem1.TEL;type=CELL;type=VOICE;type=pref;waid=5511999990006:+55 11 99999-0006\nitem1.X-ABLabel:Mobile\nEND:VCARD",+ want: "+55 11 99999-0006",+ },+ {+ name: "GroupedTelLowercase",+ vcard: "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:Erin\r\nitem2.tel;type=CELL:+1 555 0101\r\nEND:VCARD",+ want: "+1 555 0101",+ },+ {+ name: "GroupedTelFolded",+ vcard: "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:Frank\r\nitem1.TEL;type=CELL;waid=5511998913283:\r\n +5511998913283\r\nEND:VCARD",+ want: "+5511998913283",+ },+ {+ // Only the property name counts: a group or a value that merely+ // contains "TEL" is not a phone.+ name: "OnlyTelPropertyName",+ vcard: "BEGIN:VCARD\nVERSION:3.0\nFN:Grace\nTELEX:12345\nitem3.URL:https://example.com/TEL\nitem4.TEL:+1 555 0102\nEND:VCARD",+ want: "+1 555 0102",+ },{name: "NoTelLine",vcard: "BEGIN:VCARD\nVERSION:3.0\nFN:Carol\nEND:VCARD",