24 February 2015

How to send an SMS in hebrew or any other language other than english with clickatell in vtiger

Today we had to modify vtiger to allow users to send sms in language other than english, after lot of research we were able to get this done

When sending sms through clickatell, you need to convert the message string to a UNICODE characters before submitting to the gateway. Because clickatell has its own unicode convertor.

So we added following function to modules/SMSNotifier/providers/clickatell.php

public function hex_chars($data){
    $mb_hex = '';
    for($i = 0 ; $i<mb_strlen($data,'UTF-8') ; $i++){
        $c = mb_substr($data,$i,1,'UTF-8');
        $o = unpack('N',mb_convert_encoding($c,'UCS-4BE','UTF-8'));
        $mb_hex .= sprintf('%04X',$o[1]);
    }
    return $mb_hex;
} 

then converted the message string passed in send function as follows

$params['text'] = $this->hex_chars($message);

you also have to pass unicode parameter to your message as follows

$params['unicode'] = 1;

No comments:

Post a Comment