sms send from js code
authorPaul J R <me@pjr.cc>
Sun, 27 Jul 2014 14:03:05 +0000 (00:03 +1000)
committerPaul J R <me@pjr.cc>
Sun, 27 Jul 2014 14:03:05 +0000 (00:03 +1000)
sms_send/sms_send.js [new file with mode: 0644]

diff --git a/sms_send/sms_send.js b/sms_send/sms_send.js
new file mode 100644 (file)
index 0000000..9717e49
--- /dev/null
@@ -0,0 +1,59 @@
+var http = require("http");
+var url = require("url");
+var qs = require("querystring");
+var cp = require("child_process").exec;
+
+var port = 8080;
+var itest = "email-smtp.us-east-1.amazonaws.com";
+
+function servRequest(req, res) {
+       //§console.log("req: ");
+       //console.log(req);
+       //console.log("res: ");
+       //console.log(res);
+       
+       var path = url.parse(req.url);
+       
+       var strings = qs.parse(path.query);
+       
+       //console.log(strings);
+       
+       var num = strings['num'];
+       var msg = strings['msg'];
+       
+       
+       //testCon(function sendit() {
+       if(typeof strings['num'] != "undefined" && typeof strings['msg'] != "undefined") {
+               sendMessage(num, msg, res);
+       } else {
+               res.write("no");
+               res.end();
+       }
+       //});
+       
+}
+
+function endRequest(res) {
+       res.write("ok");
+       res.end();
+       
+}
+
+function sendMessage(num, msg, res) {
+       var sm = cp("echo '"+msg+"' | gammu-smsd-inject TEXT "+num, function (error, stdout, stderr) {
+           console.log('stdout: ' + stdout);
+           console.log('stderr: ' + stderr);
+           if (error !== null) {
+             console.log('exec error: ' + error);
+           }
+           
+           endRequest(res);
+       });             
+}
+
+function testCon(passBackFunc) {
+       
+}
+
+
+http.createServer(servRequest).listen(port);
\ No newline at end of file