SMS Command Line Interface

SMS Command Line Interface SearchSearch
Author Message
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 3026
Registered: 10-2002
Posted on Tuesday, July 13, 2004 - 04:43 pm:   

This is an update for the following older thread on this discussion board:

http://support.nowsms.com/discus/messages/1/375.html

From time to time we get asked for a command line interface for sending SMS messages via NowSMS. The thread referenced above presents a simple Windows script that can send a predefined message.

Here is an update to that script which offers some more flexibility. This updated script allows recipient phone numbers, and the message text, to be specified on the command line.

Assuming that the script is saved as a file named sms.js, you would issue the following command:

cscript sms.js PhoneNumber1[,PhoneNumber2,...] SMS Message Text

Examples:

cscript sms.js +44777777777 This is a test message

cscript sms.js +44777777777,+44777777778 This is a test message to 2 recipients

---begin sms.js---
/*
This is a command line script for sending an SMS message via NowSMS.

Below, you must subsitute in the address of your NowSMS server, plus a valid username and password for
an account defined in the "SMS Users" list of that server.

Note: This script uses the encodeURIComponent method introduced in Internet Explorer 5.5. If you are running
Windows 2000 or an earlier version of Windows, you must have Internet Explorer 5.5 or later installed for this
script to work.
*/

var NowSMSServerAddress = "http://127.0.0.1:8800";
var NowSMSUserName = "test";
var NowSMSPassword = "test";

function HTTPGET(strURL)
{
var strResult;

try
{
// Create the WinHTTPRequest ActiveX Object.
var WinHttpReq = new ActiveXObject("Msxml2.XMLHTTP" /* or "WinHttp.WinHttpRequest.5"*/);

// Create an HTTP request.
var temp = WinHttpReq.Open("GET", strURL, false);

// Send the HTTP request.
WinHttpReq.Send();

// Retrieve the response text.
strResult = WinHttpReq.ResponseText;
}
catch (objError)
{
strResult = objError + "\n"
strResult += "WinHTTP returned error: " +
(objError.number & 0xFFFF).toString() + "\n\n";
strResult += objError.description;
}

// Return the response text.
return strResult;
}

var strRequest;

if (WScript.Arguments.Count() < 2) {
WScript.Echo ("Usage: " + WScript.ScriptName + " PhoneNumber1[,PhoneNumber2,...] Message Text\r\n");
WScript.Quit();
}

strRequest = NowSMSServerAddress + "/?PhoneNumber=" + encodeURIComponent(WScript.Arguments(0)) + "&User=" + encodeURIComponent(NowSMSUserName) + "&password=" + encodeURIComponent(NowSMSPassword) + "&text=";

for (i=1; i<WScript.Arguments.Count(); i++)
{
if (i > 1) {
strRequest += "%20";
}
strRequest += encodeURIComponent(WScript.Arguments(i));
}


WScript.Echo(HTTPGET(strRequest));
---end sms.js---