Created
February 23, 2017 16:42
-
-
Save mooyoul/1b600fcbdf345576759885e92417c37e to your computer and use it in GitHub Desktop.
Nexmo connect demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const path = require('path'); | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
const NCCO_CONNECT = [{ | |
"action": "stream", | |
"streamUrl": [`${process.env.BASE_URL}/greet.mp3`] | |
}, { | |
"action": "stream", | |
"eventUrl": [`${process.env.BASE_URL}/connecting.mp3`] | |
}, { | |
"action": "connect", | |
"eventUrl": [`${process.env.BASE_URL}/events`], | |
"timeout": 30, | |
"from": process.env.CALLER_NUMBER, | |
"endpoint": [ | |
{ | |
"type": "phone", | |
"number": process.env.RECEIVER_NUMBER | |
} | |
] | |
}]; | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({extended: false})); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
app.use((req, res, next) => { | |
console.log('Got request, %s %s', req.method, req.url, req.ip, req.headers); | |
next(); | |
}); | |
app.route('/init') | |
.get((req, res) => { | |
res.send(NCCO_CONNECT); | |
}); | |
app.route('/events') | |
.get((req, res) => { | |
console.log('got event get request'); | |
console.log(req.url, req.query); | |
res.sendStatus(204); | |
}) | |
.post((req, res) => { | |
console.log('got event post request'); | |
console.log(req.url, req.query, req.body); | |
res.sendStatus(204); | |
}); | |
app.listen(9000, () => { | |
console.log('Server started at port 9000...'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment