-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirebaseClient.js
More file actions
53 lines (34 loc) · 1.27 KB
/
FirebaseClient.js
File metadata and controls
53 lines (34 loc) · 1.27 KB
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
45
46
47
48
49
50
51
52
53
/**
* Created by rawad.elrifai on 6/19/17.
*/
var firebaseConfig = require('./Config').firebaseConfig;
var firebase = require("firebase");
function readData(callback) {
// get today's date
var todayDate = new Date().toLocaleDateString().replace(/\//g,'-');
if(firebase.apps.length == 0) { // <---Important!!! In lambda, it will cause double initialization.
firebase.initializeApp(firebaseConfig);
}
// get reminders data from firebase
firebase.database().ref('reminders/sms/' + todayDate).once('value').then(function (snapshot) {
var reminders = snapshot.val();
console.log(reminders)
// loop through reminders
for (var key in reminders) {
console.log('loop')
if (reminders.hasOwnProperty(key)) {
var val = reminders[key];
var to = val.to
var message = val.message
var twilioClient = require('./TwilioClient')
twilioClient.sendSms(to, message)
}
}
setTimeout(function() {
console.log('about to call callback')
callback(null,'process completed');
console.log('called callback')
}, 3000);
});
}
module.exports.readData = readData