NowSMS from Delphi

NowSMS from Delphi SearchSearch
Author Message
DHMHTRHS MANTELLOS
New member
Username: Dimitris

Post Number: 3
Registered: 06-2009
Posted on Monday, July 06, 2009 - 05:02 pm:   

Heya all!
Here's the thing: I'm trying to create a Delphi Application that sends SMSs. I have tried:
1. Running the smsfile.js in a Console application created on runtime in Delphi (works fine but i can't catch the output for further use)
2. Changing the smsfile.js from JScript to JavaScript, embedding it through TWebBrowser as an HTML page in my Delphi application (works fine, but i can't catch the output and i can't enter the phone numbers and the text file names dynamically)
---------------
Now, i'm trying to overcome the previous not-so-intelligent methods, and to translate the smsfile.js into Delphi code.

The thing is that i tried it (wrote two delphi methods that do exactly what the smsfile.js does) and everything seems to work fine, except for two annoying things:

1. The JScript uses the encodeURIcomponent() methods to encode the Strings into URIs. Delphi, on the other hand, doesn't have that. I've already used: TIdURI.PathEncode(), TIdURI.ParamEncode(), TIdURI.URIEncode(), but with no great luck. Some special characters, as well as greek letters, come out as crap in my received SMS messages (and yeah, my messages must be written in greek with loads of special characters).

2. The result of the HTTPGET() function (in the smsfile.js) is a string that creates an HTML page. In other words, a ShowMessage(strResult) will show me a text starting with <HTML><TITLE>........ etc. While my application has to catch the text inside the <p></p> tags (for example the "Message Submitted" text).

So, my questions are:
1: Does anybody know a good Delphi URI Encoder that would work exactly as the encodeURIComponent() does?
2. Is the default return value of the NowSMS application that HTML page i'm seeing? Can't i get only the message itself and nothing else, so that i can use it in the rest of my Delphi App?

Thanx a LOT in advance!

PS. Sorry if i posted the wrong thread in the wrong forum.
PS2. Sorry for talking that much :D
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 1000
Registered: 08-2008
Posted on Tuesday, July 07, 2009 - 01:52 am:   

Hi Dimitris,

I don't know much about Delphi, but your URI encoding issues might actually be character set related rather than encoding related.

By default, NowSMS expects the text to be UTF-8 encoded. But your application is probably working in the local Greek character set.

Try appending "&charset=iso-8859-7" to the URL that you submit. This tells NowSMS to interpret the text as being in the Greek character set.

For the second question ... you raise a good point ... we should have an option that returns the response in a simple text or XML format. But NowSMS always returns an HTML response.

Whenever I've written scripts for parsing the response, I've ignored the fact that it was HTML. Instead, I've just parsed the text searching for "MessageID=" ... and then I parse out the "MessageID=" and "Recipient=" pairs. There is no HTML formatting within this block of the response, so it's quite easy to parse.

--
Des
NowSMS Support
DHMHTRHS MANTELLOS
New member
Username: Dimitris

Post Number: 4
Registered: 06-2009
Posted on Tuesday, July 07, 2009 - 09:56 am:   

Firstly, thank you VERY much for your answers and on such short notice!

Secondly.. The first problem still exists..
I changed the .ini file, adding the "ReceiveSMSCharset=iso-8859-7" line, but the message still arrives awfully. I also upgraded my NowSMS application and chose the charset from within the application (and not by changing the smsgw.ini) and nothing..
Greek letters, euro-signs, other special characters, come out as nonsence. I also tried to send a message in UTF-8. Nothing good came out of that either..

If you have any other suggestions, i'd be more than glad to hear them!

Thanx again!
DHMHTRHS MANTELLOS
New member
Username: Dimitris

Post Number: 5
Registered: 06-2009
Posted on Tuesday, July 07, 2009 - 02:33 pm:   

Problem solved!

In case someone else has the same problem, i post my solutions (i can't say if they are the correct ones, but they worked fine for me)

1. Charset solution: Changing the "ReceiveSMSCharset=iso-8859-7" in the .ini did not work. It worked only when i appended at the end of the message string the "&charset=iso-8859-7" thingie. Only problem: No output for characters: "&", "+" and "?". Everything else seems to work fine, though.

2. HTML Tags solution: I just took the whole message (HTML page) and parsed it into a function i wrote that deletes all the tags. So, the final output now is a plain text with no tags whatsoever.
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 1002
Registered: 08-2008
Posted on Tuesday, July 07, 2009 - 10:54 pm:   

1. I can see where this would be confusing. The ReceiveSMSCharset applies to inbound (received) messages. These are SMS messages that NowSMS recieves over the SMSC connection and is routing to a 2-way command.

That setting has no effect on outbound messages. On outbound messages, if you are not using UTF-8, you need to include the "&charset=" parameter in the URL request.

Regarding the "&", "+" and "?" characters, those definitely have to be escaped (as does " "), as they have special meanings within a URL.

(You might just have to roll your own routine to perform the escaping ... it just involves replacing reserved characters like "&" with an escape string. "&" becomes "%26". "+" becomes "%2B". " " becomes "%20" or "+". A list of the most common necessary escapes can be found here: http://www.nowsms.com/documentation/ProductDocumentation/sending_messages/sendin g_text_messages.htm)

--
Des
NowSMS Support