Scheduling messages | Search |
NowSMS Support Forums ⬆ NowSMS Support - SMS Issues ⬆ Archive through October 31, 2007 ⬆ |
◄ ► |
Author | Message | ||||
Kev Williams New member Username: Celticjedi Post Number: 27 Registered: 12-2004 |
Hi, I know that NowSMS can't schedule messages to go out at certain times. However it is possible to use the command line to send a message and it is possible to use Windows Scheduled Tasks to pass arguments to a VB or similar script. I can't figure out how to combine these though, has anyone else? I want to set something up so that when people sign up to a service they get an automated message sent to them every day over a 3 week period. | ||||
Bryce Norwood - NowSMS Support Board Administrator Username: Bryce Post Number: 6842 Registered: 10-2002 |
Hi Kev, Absolutely. There's a good simple Windows script example in the following thread: http://support.nowsms.com/discus/messages/1/5318.html That example is more oriented toward a simple command line interface, but it could be easily modified. Note that the phone number parameter in the example could also be a distribution list. So you could have a scheduled task that fired off a message to a distribution list. -bn | ||||
Kev Williams New member Username: Celticjedi Post Number: 28 Registered: 12-2004 |
thanks Bryce, I'll check it out. the next stage is to do the same but the script would take the message from a database before adding it to the task. If it works I'll post the script here. | ||||
Kev Williams New member Username: Celticjedi Post Number: 29 Registered: 12-2004 |
Hi, I've seen this post and used the script to send a message from the command line but when I try to automate it it doesn't work. It seems to be not passing the arguments to the sms.js script | ||||
Kev Williams New member Username: Celticjedi Post Number: 30 Registered: 12-2004 |
does anyone have any other solutions to this? thanks | ||||
Kev Williams New member Username: Celticjedi Post Number: 31 Registered: 12-2004 |
ok i now have this script, which fetches some data from a database on our webserver -> var NowSMSServerAddress = "http://127.0.0.1:8800"; var NowSMSUserName = "***"; var NowSMSPassword = "***"; var strRequest; var message; // Instantiate a WinHttpRequest object. var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1"); // Initialize an HTTP request. WinHttpReq.Open("GET", "http://***.co.uk/sms/timedtest.php", false); // Send the HTTP request. WinHttpReq.Send(); strRequest = NowSMSServerAddress + "/?PhoneNumber="+ encodeURIComponent(WScript.Arguments(0)) + "&User=" + encodeURIComponent(NowSMSUserName) + "&password=" + encodeURIComponent(NowSMSPassword) + "&text="; message = WinHttpReq.ResponseText; strRequest += message; // Display the response text. WScript.Echo(strRequest); which I am trying to set up as a Scheduled Task. When I run it from the command line with the following command -> wscript c:\windows\system32\smstimed.js +4477****** all i get is a pop-up alert box with all the correct info in but the script is not running the sms server, any ideas? | ||||
Malcolm - Now Support New member Username: Malcolm Post Number: 12 Registered: 12-2006 |
It looks like your modified version of the script is not passing the arguments. The complete URL needs to be passed in the WinHttpReq.Open ... but you are calling a different URL there. -- Malcolm Now Wireless Support | ||||
Kev Williams New member Username: Celticjedi Post Number: 32 Registered: 12-2004 |
i know it's not passing the arguments, i asked about that before. the WinHttpReq.Open URL is where the database is that holds the text of the messages. i can see that that part works because the pop-up alert contains the correct text from the database. my problem is getting the arguments passed to the NowSMS server on my local machine. | ||||
Malcolm - Now Support New member Username: Malcolm Post Number: 40 Registered: 12-2006 |
Maybe we need to backup a step (or two). I'm not understanding the question. Are you saying that the problem is specific to using the Windows "scheduled tasks" facility? That is, does the script work properly from the command line, just not from "scheduled tasks"? -- Malcolm Now Wireless Support | ||||
Kev Williams New member Username: Celticjedi Post Number: 33 Registered: 12-2004 |
sorry, not making myself very clear am i. the scripts seem to work because when i run them from the command line the script fetches the text from the online databse and passes it to the windows script host. but wscript just pastes the resulting text into a pop-up box and does not pass it onto the NowSMS server (http://127.0.0.1:8800). I think the same seems to happen when using a scheduled task but i was trying it out with the command line to see what was happening. any ideas? | ||||
Malcolm - Now Support Frequent Contributor Username: Malcolm Post Number: 51 Registered: 12-2006 |
Do you issue another WinHttpReq.Open passing the strRequest variable? That variable contains the URL that has been constructed for connecting to the NowSMS server. You need to do an "Open", then a "Send" to make the script connect to the URL. -- Malcolm Now Wireless Support | ||||
Kev Williams New member Username: Celticjedi Post Number: 34 Registered: 12-2004 |
no, just the one Open and Send as in the script outlined above. The script works from the command line, it connects to the online database and returns the correct message, the problem is that the result is presented in an alert box, not passed onto the NowSMS server to be transmitted. | ||||
Malcolm - Now Support Moderator Username: Malcolm Post Number: 175 Registered: 12-2006 |
I guess that is what has me confused. I don't see any code in the script where you actually connect to the NowSMS server. You are building the URL, but not connecting to it (Open/Send). | ||||
Kev Williams New member Username: Celticjedi Post Number: 35 Registered: 12-2004 |
The strRequest is built with the NowSMS server details, then WScript.Echo(strRequest) outputs it. This is where it should go to the server but it outputs it to an alert box instead. Should the Open/Send command come after the WScript.Echo? | ||||
DevMan New member Username: Devman Post Number: 1 Registered: 07-2007 |
Hi, It was a good thread, this one. I am not a JS expert and a NowSMS novice to boot. I just wanted to know if I can modify the script to send OMA CP WAP Push Msgs instead of SMSes. Can you help me go about it? Cheers | ||||
Bryce Norwood - NowSMS Support Board Administrator Username: Bryce Post Number: 7343 Registered: 10-2002 |
Hi, Before I address the specifics of the most recent question, I want to go back to the original topic. The original topic was asking about the ability to send messages at a pre-scheduled time. This capability was added into NowSMS 2007, so it is no longer necessary to create your own script for doing this. Of course, there are still plenty of good reasons for using a script like this for sending messages. With that said ... let's move on to OMA Client Provisioning messages. If your script is running on the same server as NowSMS, then it's an easy modification. Instead of using the script referenced above, I'm going to use the script from the following link: http://www.nowsms.com/support/bulletins/tb-nowsms-008.htm As long as we can keep the script using HTTP GET, then it is a simple modification to the script. In order to send an OMA CP message using HTTP GET, you must first save your XML document in the "OTA" subdirectory of the NowSMS installation. For example, save it as OMACP.XML. Here's the script ... ----BEGIN SMSOMACP.JS---- /* This is a command line script for sending an XML Settings document via NowSMS. THIS NAMED DOCUMENT MUST BE STORED IN THE OTA SUBDIRECTORY OF NOWSMS BEFORE RUNNING THE SCRIPT. Below, you must substitute 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,...] OTAFilename\r\n"); WScript.Echo (" (Note: OTAFilename must exist in the OTA subdirectory of NowSMS)\r\n"); WScript.Quit(); } strRequest = NowSMSServerAddress + "/?PhoneNumber=" + encodeURIComponent(WScript.Arguments(0)) + "&User=" + encodeURIComponent(NowSMSUserName) + "&password=" + encodeURIComponent(NowSMSPassword) + "&ota=" + encodeURIComponent (WScript.Arguments(1)); WScript.Echo(HTTPGET(strRequest)); ----END SMSOMACP.JS---- Then run the following to submit the document: cscript SMSOMACP.js phonenumber OMACP.XML If you don't have access to create the file in the OTA directory of the NowSMS installation, then it would be more complex. You would need to change the method from a GET to a POST, change the URL to OTA=POST instead of OTA=filename, and include the XML as the data in the post. I'm not expert enough in JScript to do that quickly, so for now I leave you with the above example. -bn | ||||
Bryce Norwood - NowSMS Support Board Administrator Username: Bryce Post Number: 7344 Registered: 10-2002 |
Actually, changing the GET to a POST was very easy ... Here's the revised script ...
/* This is a command line script for sending an XML Settings Document via NowSMS. Below, you must substitute 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 HTTPPOST(strURL,xmlSettings) { 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("POST", strURL, false); // Send the HTTP request. WinHttpReq.Send(xmlSettings); // 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 objFSO, objTextFile; var ForReading = 1; var strRequest; var xmlSettings; if (WScript.Arguments.Count() < 2) { WScript.Echo ("Usage: " + WScript.ScriptName + " PhoneNumber1[,PhoneNumber2,...] OTAFilename\r\n"); WScript.Quit(); } objFSO = new ActiveXObject("Scripting.FileSystemObject"); try { objTextFile = objFSO.OpenTextFile(WScript.Arguments(1), ForReading); } catch (objError) { WScript.Echo ("Cannot open file " + WScript.Arguments(1) + "\r\n"); WScript.Quit(); } xmlSettings = objTextFile.ReadAll(); objTextFile.Close(); strRequest = NowSMSServerAddress + "/?PhoneNumber=" + encodeURIComponent(WScript.Arguments(0)) + "&User=" + encodeURIComponent(NowSMSUserName) + "&password=" + encodeURIComponent(NowSMSPassword) + "&ota=post"; WScript.Echo(HTTPPOST(strRequest,xmlSettings)); ------------- This script takes an XML settings document and posts it directly to NowSMS, so that you don't have to worry about creating a file in the OTA subdirectory first. cscript smsota.js phonenumber settings.xml Enjoy! -bn | ||||
Bryce Norwood - NowSMS Support Board Administrator Username: Bryce Post Number: 7372 Registered: 10-2002 |
Update: I've modified the above script to add support for specifying PIN values. For more details, see http://blog.nowsms.com/2007/07/send-oma-client-provisioning-ota-xml.html. | ||||
Bryce Norwood - NowSMS Support Board Administrator Username: Bryce Post Number: 7376 Registered: 10-2002 |
And on a similar note, there is now a script example that allows MMS messages to be submitted from a command line interface. For more details, see http://blog.nowsms.com/2007/07/sending-mms-from-command-line.html | ||||
DevMan New member Username: Devman Post Number: 3 Registered: 07-2007 |
Bryce: thanks a lot. That script would be quite useful. Cheers... |