-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMSer.js
35 lines (30 loc) · 838 Bytes
/
SMSer.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
var config = require('./config.json'),
twilio = require('twilio');
function SMSer () {
this._client = twilio(
config.twilioConfig.accountSid,
config.twilioConfig.authToken
);
this._numbers = config.phoneNumbers;
}
SMSer.prototype = {
send: function (listing) {
for (var i = 0; i < this._numbers.length; i += 1) {
console.log("Sending text message to ", this._numbers[i]);
this._client.messages.create({
to: this._numbers[i],
from: config.twilioConfig.fromNumber,
body: this._getMessage(listing)
}, function (err, message) {
console.log(err);
console.log(message);
});
}
},
_getMessage: function (listing) {
return [
listing.title, listing.location, listing.price, listing.url
].join(' | ');
}
};
module.exports = SMSer;