Noizu.WhatsApp.Phone (Noizu.WhatsApp v0.1.0)

Copy Markdown View Source

Phone-number hygiene for the Cloud API.

WhatsApp recipients are digits-only E.164 (no +, no punctuation). Every outbound recipient passes through normalize/1; every number that reaches error text or inspect output passes through mask/1 (last 4 digits only).

Phone.normalize("+1 (415) 555-1234")  # => "14155551234"
Phone.mask("14155551234")             # => "*******1234"

Summary

Functions

Masks a phone number for logs and error text: *** + last 4 digits. Non-phone values pass through inspect/1 (which never carries the number itself).

Normalizes a phone number to digits-only E.164. Accepts + prefixes, spaces, dashes, parens, and dots; strips 00 international prefixes. Returns {:ok, digits} (≥ 7 digits) or {:error, :invalid_phone}.

Normalizes or raises ArgumentError (for callers that pre-validate).

Functions

mask(number)

@spec mask(term()) :: String.t()

Masks a phone number for logs and error text: *** + last 4 digits. Non-phone values pass through inspect/1 (which never carries the number itself).

normalize(number)

@spec normalize(term()) :: {:ok, String.t()} | {:error, :invalid_phone}

Normalizes a phone number to digits-only E.164. Accepts + prefixes, spaces, dashes, parens, and dots; strips 00 international prefixes. Returns {:ok, digits} (≥ 7 digits) or {:error, :invalid_phone}.

normalize!(number)

@spec normalize!(term()) :: String.t()

Normalizes or raises ArgumentError (for callers that pre-validate).