Resource: Clickatell unicode convert script

Contains tips for configurators working with Aware IM
Post Reply
hpl123
Posts: 2633
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Resource: Clickatell unicode convert script

Post by hpl123 »

Hi all,
For those of you interested in using the Awaresoft Clickatell plugin and if you use utf-8 extended characters (like I do for Swedish, Danish etc. characters). The Clickatell gateway cannot handle these characters and you have to manually convert the SMS to unicode hex before sending it to the gateway. I have a working PHP script I can share if you need it. Send me a PM and I´ll send you the script.

PS: Support, would it be possible to use the PHP script I´ve got to make a function for this instead? I will send you the script and this question.

Here is the script source link if you want to read/look at it:
http://stackoverflow.com/questions/1383 ... ng-garbled
Henrik (V8 Developer Ed. - Windows)
hpl123
Posts: 2633
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: Resource: Clickatell unicode convert script

Post by hpl123 »

Here is the code from the PHP script (didn´t think about sharing it in the previous post). The script converts a string (UTF-8 to uincode hex) and then writes the output to a txt file. this can porbably also be used to convert other formats etc. NB The actual php script file HAS to be saved in the encoding you want to convert FROM (i.e UTF-8 in this example):

Code: Select all

<?php
$text = "Message";
$arr = unpack('H*hex', iconv('UTF-8', 'UCS-2BE', $text));
$add = strtoupper($arr['hex']);

$f = fopen("output.txt", "w");
fwrite($f, $add);
fclose($f);


?>
Henrik (V8 Developer Ed. - Windows)
customaware
Posts: 2431
Joined: Mon Jul 02, 2012 12:24 am
Location: Ulaanbaatar, Mongolia

Re: Resource: Clickatell unicode convert script

Post by customaware »

Henrik,

I guess I will look pretty dumb asking this question
so I will go ahead and ask it to remove all doubt.

How do I execute php code like that on my Aware IM
server?

Baby steps please. ;-)
Cheers,
Mark
_________________
AwareIM 6.0, 8.7, 8.8, 9.0 , MariaDB, Windows 10, Ubuntu Linux. Theme: Default, Browser: Arc
Upcloud, Obsidian....
Image
hpl123
Posts: 2633
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: Resource: Clickatell unicode convert script

Post by hpl123 »

Mark,
I am a PHP newbie myself so my way of doing this (see below) might not be ideal and actually other developers, anyone good at PHP and good at PHP/Aware IM integration that have tips for doing this another, better way, please chip in.

Here is what I do:

I use a batch file to execute the script (script.bat):

Code: Select all

"C:\Program Files (x86)\PHP\v5.5\php.exe" -f "C:\Scripts\phpunicode.php"
I use Aware IM tags in the PHP script:

Code: Select all

<?php
$text = "<<Sms.Message>>";
$arr = unpack('H*hex', iconv('UTF-8', 'UCS-2BE', $text));
$add = strtoupper($arr['hex']);

$f = fopen("C:\Scripts\output.txt", "w");
fwrite($f, $add);
fclose($f);


?>

I use a Aware IM txt document template that I export as part of SMS convert process:

Code: Select all

EXPORT DOCUMENT PhpUnicode TO FILE 'C:\Scripts\phpunicode.php' 
I use Aware IM EXECUTE PROGRAM to execute the bat file / script:

Code: Select all

EXECUTE PROGRAM 'C:\Scripts\script.bat'
I use Aware IM URL_CONTENTS to read the output.txt file back to Aware IM:

Code: Select all

Sms.Unicode=URL_CONTENTS('file:\\\C:\Scripts\output.txt')
I am working on a queue solution where SMS if created simultaneously, the SMS will get a execution no and will be executed in order (part of this solution might also be actions to delete previous php and output etc. files).
Henrik (V8 Developer Ed. - Windows)
Post Reply