forked from Reneehsu/Community-Text-at-Spectra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedule.js
53 lines (45 loc) · 1.43 KB
/
schedule.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
45
46
47
48
49
50
51
52
53
var client = require('twilio')(process.env.TWILIO_SID, process.env.TWILIO_AUTH_TOKEN);
console.log('schedule');
var express = require('express')
var mongoose = require('mongoose')
var bodyParser = require('body-parser')
var exphbs = require('express-handlebars');
var client = require('twilio')(process.env.TWILIO_SID, process.env.TWILIO_AUTH_TOKEN);
var cronJob = require('cron').CronJob;
//setup mongoose connection
mongoose.connection.on('error', function() {
console.log('error connecting to database')
})
mongoose.connection.on('connected', function() {
console.log('succesfully connected to database')
})
mongoose.connect(process.env.MONGODB_URI)
var models = require('./models/model');
var User = models.User;
var Community = models.Community;
//setup application configurations
var app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended:true}))
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
Community.find(function(err,community){
if (err){
console.log(err);
} else {
for (var i=0; i<community.length; i++){
for (var j=0; j<community[i].users.length; j++){
client.messages.create({
to: community[i].users[j],
from: '+14245238634',
body: community[i].question,
});
}
}
}
})
// client.messages.create({
// to: '+13109233881',
// from: '+14245238634',
// body: "please work",
// });