-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (27 loc) · 976 Bytes
/
index.js
File metadata and controls
33 lines (27 loc) · 976 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
25
26
27
28
29
30
31
32
33
import express from 'express';
import bodyParser from "body-parser";
import Puzzle from "./Puzzle";
// Create a new express application instance
const app = express();
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static("www"));
let oGames = {};
app.post("/sms", (req, res) =>{
let sFrom = req.body.From;
if(!oGames.hasOwnProperty(sFrom)){
oGames[sFrom] = new Puzzle();
}
let sMessage = req.body.Body|| req.body.body;
let sReply = oGames[sFrom].takeTurn(sMessage);
let aReply = [sReply]
res.setHeader('content-type', 'text/xml');
let sResponse = "<Response>";
for(let n = 0; n < aReply.length; n++){
sResponse += "<Message>";
sResponse += aReply[n];
sResponse += "</Message>";
}
res.end(sResponse + "</Response>");
});
var port = process.env.PORT || parseInt(process.argv.pop()) || 3000;
app.listen(port, () => console.log('Example app listening on port ' + port + '!'));