-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
24 lines (18 loc) · 743 Bytes
/
server.js
File metadata and controls
24 lines (18 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const express = require('express');
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const app = express();
let lastMessage = 'Leave a message for the next person who texts me!';
app.get('/', (req, res) => {
const twiml = new MessagingResponse();
if (req.query.Body === '?') {
twiml.message("Hi! ✨\n\nSend me a message and I'll store it for the next person. Then I'll send you the last message I have stored. 💁")
} else {
twiml.message(lastMessage || "You're amazing!");
lastMessage = req.query.Body;
}
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end(twiml.toString());
});
app.listen(process.env.PORT || 5000, () => {
console.log('Express server listening on port 5000');
});