Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
37388 vikas 1
package com.spice.profitmandi.service.whatsapp;
2
 
3
/**
37409 vikas 4
 * Recipient-number handling for the WhatsApp gateway.
37388 vikas 5
 *
6
 * <p>Lives here rather than in a general string utility because "prefix 91" is an India-MSISDN rule
7
 * that only holds for this integration.</p>
8
 */
9
public final class WhatsappNumbers {
10
 
11
    private WhatsappNumbers() {
12
    }
13
 
14
    /**
15
     * Normalises a recipient to a bare MSISDN: strips everything non-numeric, prefixes {@code 91} when
16
     * exactly ten digits remain, and passes longer numbers (already country-coded) through. Returns
17
     * {@code null} when nothing usable is left, which callers treat as "do not send".
18
     */
19
    public static String toMsisdn(String mobile) {
20
        if (mobile == null) {
21
            return null;
22
        }
23
        String digits = mobile.replaceAll("[^0-9]", "");
24
        if (digits.isEmpty()) {
25
            return null;
26
        }
27
        if (digits.length() == 10) {
28
            return "91" + digits;
29
        }
30
        return digits;
31
    }
32
}