-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (29 loc) · 1.09 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
// Use dotenv to allow us to have a file that store our keys without making them publicly avalible
require('dotenv').config();
const express = require('express')
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const VoiceResponse = require('twilio').twiml.VoiceResponse;
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.urlencoded({ extended: false }))
app.post('/sms', (req, res) => {
console.log(req.body.Body)
if(req.body.Body === 'Whats the time?' || req.body.Body === 'time' || req.body.Body === '⏳')
{
var twiml = new MessagingResponse();
var today = new Date();
var time = today.getHours() + ':' + today.getMinutes();
twiml.message(time);
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end(twiml.toString());
}
else{
}
})
app.post('/call', (req, res) => {
const twiml = new VoiceResponse();
twiml.say('Thats all for now folks!');
res.type('text/xml');
res.send(twiml.toString());
})
app.listen(3000, () => console.log("App started on port 3000"))