Subversion Repositories SmartDukaan

Rev

Rev 37413 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.service.whatsapp;

/**
 * Recipient-number handling for the WhatsApp gateway.
 *
 * <p>Lives here rather than in a general string utility because "prefix 91" is an India-MSISDN rule
 * that only holds for this integration.</p>
 */
public final class WhatsappNumbers {

    private WhatsappNumbers() {
    }

    /**
     * Normalises a recipient to a bare MSISDN: strips everything non-numeric, prefixes {@code 91} when
     * exactly ten digits remain, and passes longer numbers (already country-coded) through. Returns
     * {@code null} when nothing usable is left, which callers treat as "do not send".
     */
    public static String toMsisdn(String mobile) {
        if (mobile == null) {
            return null;
        }
        String digits = mobile.replaceAll("[^0-9]", "");
        if (digits.isEmpty()) {
            return null;
        }
        if (digits.length() == 10) {
            return "91" + digits;
        }
        return digits;
    }
}