Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
There's more than one way to do things
 
PerlMonks  

Sending special characters to sms using Perl

by Ombongi.Moraa (Novice)
on Oct 23, 2012 at 11:20 UTC ( #1000466=perlquestion: print w/ replies, xml ) Need Help??
Ombongi.Moraa has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm using a perl script to create a response that will be sent to subscribers on their phones. However, Im having trouble sending special characters esp @, # and ^;

Currently, Ive implemented the statement that handles text messages by adding paramaters for coding and charset to the line like this;

 ($msgType =~ /(?:web)|(?:err)|(?:text)/i) ? '&text=' . enurl($text).'&coding=2'.'&charset=utf-8'

however, these 2 parameter increase the bytes used by a message so all my messages, even those that are less than 16 characters are received by the phone only halfway;

responses stored in variable $text are not fixed but rather are dynamic depending on the processing for each user message/short code.

I could implement concatenation using my sms gateway but the trouble with this is that those messages will still be sent separately to SMSC and thus each data submit will be billed for the subscriber.

In my perl script Im using CGI::Enurl and I understand this will come of help though I cant find information on how to use it to resolve my problem.

How can I resolve this?

Comment on Sending special characters to sms using Perl
Download Code
Re: Sending special characters to sms using Perl
by moritz (Cardinal) on Oct 23, 2012 at 12:02 UTC

    First of all it seems you are sending SMS using a web-based gateway. So you need to consult the documentation for that gateway.

    Secondly I don't understand why .'&coding=2'.'&charset=utf-8' changes the breakup of messages; that should be done only by body lengths, not by the length of the submission URL. And I don't see the significants of length 16; the length limitation for the message body is more around 140 to 155 characters 160 bytes.

    As for the special characters that don't work, see how enurl() escape those, and what your SMS gateway provider expects.

      @moritz - sorry I meant 160 characters not 16; And this is 140 bytes approximately depending on the characters in the sms. Ive implemented what my sms gateway (kannel) advises but as i explained, since these messages are forwarded separately to smsc, they are considered and MT messages and hence the subscriber gets billed for them. that's why im asking for a solution on the perl side.
Re: Sending special characters to sms using Perl
by flexvault (Vicar) on Oct 23, 2012 at 16:26 UTC

    Ombongi.Moraa,

    I wrote this code in 2004/5. I would do it much different now, but it's worked since and I never even looked at it until your question. We monitor routers, switches, servers, etc. and it something doesn't respond correctly, we use the script to send a message to the support cell phone. The number in the sample is invalid.

    #!/usr/local/bin/perl -w our $log = "/log/sms_emails"; open (CLOG, ">>$log") || die "Could not open-1 $log File\n"; our $ErrCode = "@ARGV"; if ( $ErrCode eq "" ) { print "format is: pyrsms.cgi message-text\n";exit(1); } $rno = time; $usermailmsg = "/tmp/SMS_msg_$rno"; $filout = "$usermailmsg"; open (f_out, ">$filout") || die "Could not open-3a $filout\n"; $PFemail = "9083972845\@messaging.sprintpcs.com"; $ltm = localtime; print f_out "Subject: Error Code: $ErrCode\n\n\n"; close f_out; print CLOG "$ltm\t$PFemail\t$ErrCode\t$usermailmsg\n"; system("/usr/sbin/sendmail $PFemail < $usermailmsg"); sleep 1; system("/usr/sbin/sendmail -v -q 1>>/dev/null 2>>/dev/null");

    Maybe something in the code will help you figure out what you need.

    Good Luck!

    "Well done is better than well said." - Benjamin Franklin

Re: Sending special characters to sms using Perl
by Anonymous Monk on Oct 24, 2012 at 07:27 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1000466]
Approved by Ratazong
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2014-04-21 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls