-
-
Save WhiteyDude/e1a9d19f09e098dd6d72865c301e440c to your computer and use it in GitHub Desktop.
This file contains 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
const calls = require('./calls'); | |
srf.invite(async(req, res) => { | |
const ms = req.app.locals.ms; | |
const to_number = calls.convertToE164(req.calledNumber); | |
let ep, dlg; | |
try { | |
const {endpoint, dialog} = await ms.connectCaller(req, res); | |
ep = endpoint; | |
dlg = dialog; | |
const number = await calls.check_is_valid(to_number); | |
if (!number) { | |
console.log(`[${req.callid}] ${to_number} does not match`) | |
await calls.playback_failure(endpoint); | |
dialog.destroy(); | |
endpoint.destroy(); | |
} | |
else { | |
setHandlers(req, res, dialog, endpoint); | |
// Valid number, continuing execution | |
endpoint.play(['ivr/8000/ivr-please_state_your_name_and_reason_for_calling.wav']); | |
} | |
} catch (err) { | |
console.error(err, 'Error connecting call to media server'); | |
res.send(503); | |
if (dlg) dlg.destroy(); | |
if (ep) ep.destroy(); | |
} | |
}); | |
function setHandlers(req, res, dialog, endpoint) { | |
dialog.on('destroy', () => { | |
console.log(`Received BYE, deleting ${req.callid}`) | |
endpoint.destroy(); | |
// calls.delete_call(req.call_id); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment