-
Notifications
You must be signed in to change notification settings - Fork 0
/
recentMessages.js
36 lines (30 loc) · 1 KB
/
recentMessages.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
// recentMessage.js
const ACC_SID = "Enter Account SID";
const AUTH_TOKEN = "Enter Authentication Token";
var client = require ('twilio') (ACC_SID, AUTH_TOKEN);
var cron = require ('./cron');
var d;
// Logs all the messages sent after the given timeString (H:m:s in 24 hours format)
var getMessage = function (timeString) {
client.messages.list(function(err, data) {
data.messages.forEach(function(message) {
var messageTime = message.dateSent.substring(17,25);
if (message.status == "received" &&
messageTime >= timeString) {
console.log ("From: " + message.from);
console.log ("Message: " + message.body);
console.log ("\n");
}
});
});
};
// See how to use cron at https://github.com/ncb000gt/node-cron
var cronJob = cron.job('*/10 * * * * *', function (){
d = new Date();
var timeString = d.getUTCHours() + ":" +
d.getUTCMinutes() + ":" + d.getUTCSeconds();
console.log("---------------------------------");
console.log(timeString);
getMessage(timeString);
});
cronJob.start();