Hi…
|
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 91 92 93 |
/* * Telekom Tropo Call Sample */ // This file is special to me, make your own ;-) var secrets=require("./telekom-tropo-app-secret.js"); require("tropo-webapi"); var express = require("express"); var app = express(); var https = require("https"); var secretAccessCode; //This triggers Telekom Tropo to call back function triggerTelekomTropo() { https.get("https://tropo.developergarden.com/api/sessions?action=create&token="+secrets.telekom_tropo_token_outboundVoice, function(res) { console.log("Session creation requested..."); }).on("error", function(err) { console.log("Got error: " + e.message); }); }; // Use this to access elements of http body app.configure(function() { app.use(express.bodyParser()); }); //This is were Telekom Tropo gets the secret message app.post("/",function(req, res) { var tropo = new TropoWebAPI(); tropo.call(secrets.landlineNumber); tropo.say("The secret access code is " + String(secretAccessCode)); res.end(TropoJSON(tropo)); console.log("Message send..."); }); // Entry form - triggers authentication process app.get("/two_way_authenticate", function(req, res) { var body='<html><head><meta http_equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'; body += '<form action="/input_code" method="get">'+ 'If you want to get access code, please press the button.' + '<input type="submit" value="Send access code"/>' + '</form></body></html>'; res.status(200); res.set({"Content-Type": "text/html"}); res.write(body); res.end(); }); // Form to send / enter secret code app.get("/input_code", function(req, res) { secretAccessCode = Math.floor(Math.random()*800)+100; triggerTelekomTropo(); var body='<html><head><meta http_equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'; body += '<form action="/check_code" method="post">'+ 'Please enter code.' + '<textarea name="code"></textarea>' + '<input type="submit" value="Check access code"/>' + '</form></body></html>'; res.status(200); res.set({"Content-Type": "text/html"}); res.write(body); res.end(); }); //Form that checks the secret code and grants access app.post("/check_code", function(req,res) { var body='<html><head><meta http_equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'; if(Number(req.param('code', null)) == secretAccessCode) body+="Access granted"; else body+="Access denied"; body+='</body></html>'; res.status(200); res.set({"Content-Type": "text/html"}); res.write(body); res.end(); }); app.listen(8000); console.log("Server started / listing on port 8000"); |
CU
0xff







