-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.js
34 lines (29 loc) · 971 Bytes
/
sms.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var fs = require('fs');
var chokidar = require('chokidar');
var exec = require('child_process').exec;
var cmd = function(number, text) {
return "gammu-smsd-inject TEXT "
+ number.toString()
+ " -text "
+ '\"'+text+'\"';
};
var send = function(number, text) {
exec(cmd(number, text));
console.log("sms sent to "
+ number
+ " at "
+ new Date());
};
var del = function () {
exec('cd /var/spool/gammu/inbox && sudo rm *');
};
var receive = function(callback) {
chokidar.watch('/var/spool/gammu/inbox/').on('add',function(path){
fs.readFile(path,'utf8', function(err, content){
console.log(content+" from "+path.split('_')[3]);
if(callback)
callback({content: content, sender: path.split('_')[3]})
});
});
};
module.exports = { send: send, del: del, receive: receive};