-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
90 lines (66 loc) · 3.56 KB
/
server.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const express = require('express');
const dotenv = require('dotenv').config();
const bodyParser = require('body-parser');
const process = require('process');
const port = process.env.PORT || 5000;
const connectDB = require('./config/db');
const { createEssay, serverDelay, logicHandler, fileURLGenerator } = require("./controllers/devController");
const { sendMessage, simpleMessage, sendMediaMessage, generateResponse } = require("./controllers/openaiController");
const {sendEmail }=require("./config/nodemailer");
const Message = require("./models/messageSchema");
const Student = require("./models/studentModel");
const {registerUser} = require("./controllers/functions/registerStudent");
//development only
const {matchMentor, requestEssayFeedback} = require("./controllers/essayController");
//google docs config
const {authorize} = require("./config/google");
//authorize and initialize API
authorize()
//aws
const { awsBoot, getResource } = require('./config/aws');
const { get } = require('mongoose');
//setup express app
const app = express()
//send a test email
// sendEmail();
//connect to database
connectDB();
//Setup JSON Parsing
app.use(bodyParser.json());
// parse application/x-www-form-urlencoded, basically can only parse incoming Request Object if strings or arrays
app.use(bodyParser.urlencoded({ extended: false }));
//api requests
app.post('/sms', async (req, res)=>{
const userMessage = req.body.Body;
const phoneNumber = req.body.From;
console.log(typeof(phoneNumber)
);
await logicHandler(userMessage, phoneNumber);
// if(logicHandler(userMessage, phoneNumber)===false){
// await createEssay(userMessage, phoneNumber);
// console.log("Case 2")
// }else{
// sendMessage(phoneNumber, "File in progress...");
// }
console.log(userMessage + "\n\n--------------\n\n-------------");
// let openaiMessage = await generateResponse(userMessage);
// await sendMessage(phoneNumber, openaiMessage);
// res.status(200).json({message: "Hello"});
})
app.listen(port, async ()=> {
console.log(`Server started on port ${port}`);
//development only
// requestEssayFeedback("+12369939310", "Sample", "Sample Prompt");
// await createGoogleDoc("test document").catch((err)=>{
// console.error('Error:', err.message)
// });
// sendMessage("whatsapp:+12369939310", "Before you start, check this out! \n\n ⬇️⬇️⬇️⬇️⬇️⬇️")
// sendMediaMessage("whatsapp:+12369939310", "Welcome, please review this document first!", "https://jmc.msu.edu/_assets/pdfs/academics/writing%20consultancy/write-personal-statement.pdf")
//1000ms delay to send messages in correct order
// serverDelay();
// const url = "https://github.com/makac1896/collegeresources/blob/main/his%20logo.png?raw=true";
// sendMediaMessage(null, `Welcome to HIS Alumni! We strive to make your College process smoother, meet *dAVE*\n\n Our newest digital assistant to help you at every stage of the College process! \n\n _Built with passion, fueled by ambition!_ \n\n *Type "list schools" to see available resources*`, url);
// sendMessage("whatsapp:+12369939310", "Welcome to HIS Alumni")
// sendMediaMessage("whatsapp:+12369939310", "_HIS Merit Scholarship Alumni_ \n📜~Fast, Accurate, Free! \n\n Please enter your essay title:", await getResource("harvard ps"));
// sendMediaMessage("whatsapp:+12369939310", "_HIS Merit Scholarship Alumni_ \n📜~Fast, Accurate, Free! \n\n Please enter your essay prompt!", "https://i.ibb.co/G9Xx97V/przemyslaw-marczynski-T-tg8-Vc-DLJ8-unsplash.jpg");
});