Skip to content

Instantly share code, notes, and snippets.

Forked from davehorton/sample.js
Last active Jun 9, 2019
What would you like to do?
const calls = require('./calls');
srf.invite(async(req, res) => {
const 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);
else {
setHandlers(req, res, dialog, endpoint);
// Valid number, continuing execution['ivr/8000/ivr-please_state_your_name_and_reason_for_calling.wav']);
} catch (err) {
console.error(err, 'Error connecting call to media server');
if (dlg) dlg.destroy();
if (ep) ep.destroy();
function setHandlers(req, res, dialog, endpoint) {
dialog.on('destroy', () => {
console.log(`Received BYE, deleting ${req.callid}`)
// calls.delete_call(req.call_id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment