Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

931 B
Raw Blame
package utils

import "strings"

// NormalizePhoneE164 ensures phone has + prefix for E.164 format.
// Strips WhatsApp JID suffixes (@s.whatsapp.net, @lid, etc.) before formatting.
// Returns empty string if input is empty.
func NormalizePhoneE164(phone string) string {
	phone = strings.TrimSpace(phone)
	if phone == "" {
		return phone
	}
	phone = ExtractPhoneFromJID(phone)
	if !strings.HasPrefix(phone, "+") {
		return "+" + phone
	}
	return phone
}

// ExtractPhoneFromJID extracts phone number from JID by stripping the domain part.
// For example, "[email protected]" becomes "1234567890".
func ExtractPhoneFromJID(jid string) string {
	return strings.Split(jid, "@")[0]
}

// CleanPhoneForWhatsApp prepares a phone number for WhatsApp sending.
// Removes + prefix and trims whitespace.
func CleanPhoneForWhatsApp(phone string) string {
	phone = strings.ReplaceAll(phone, "+", "")
	return strings.TrimSpace(phone)
}