-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsms-sender.js
44 lines (39 loc) · 1.04 KB
/
sms-sender.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
35
36
37
38
39
40
41
42
43
44
"use strict";
const Tools = require("./tools.js");
const http = require("http");
// Sends sms messages to a given list of recipients.
class SmsSender {
constructor() {
this.IP = "192.168.1.9";
const ERROR_MSG = "No SMS numbers found.";
try {
const r = /((\+\d\d)\s?|0)\d{3}\s?\d+/g;
const validNumbers =
Tools.readLines("data/smsNumbers.txt").filter(l => r.test(l));
this.mNumberLine = validNumbers.join();
if(!this.mNumbers)
Tools.log(ERROR_MSG);
}
catch(e) {
Tools.log(ERROR_MSG);
}
}
static toUrl (t, ns) { return `http://${this.IP}/broadcast?text=${text}&numbers=${ns}`; }
static broadcast(smsText) {
if(!this.mNumbers) {
return false;
}
http.get(this.toUrl(smsText, this.mNumbers), resp => { //FINISH THIS
let data = "";
resp.on("data", (chunk) => data += chunk);
resp.on("end", () => {
console.log(JSON.parse(data).explanation);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
}
if(typeof module !== "undefined") {
module.exports = SmsSender;
}