mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
create outbound dial from webhook ws (#581)
* wip, create outbound dial from webhook ws * wip, create outbound dial from webhook ws * clean
This commit is contained in:
@@ -23,6 +23,7 @@ const {
|
|||||||
AWS_REGION,
|
AWS_REGION,
|
||||||
JAMBONES_USE_FREESWITCH_TIMER_FD
|
JAMBONES_USE_FREESWITCH_TIMER_FD
|
||||||
} = require('../config');
|
} = require('../config');
|
||||||
|
const bent = require('bent');
|
||||||
const BackgroundTaskManager = require('../utils/background-task-manager');
|
const BackgroundTaskManager = require('../utils/background-task-manager');
|
||||||
const BADPRECONDITIONS = 'preconditions not met';
|
const BADPRECONDITIONS = 'preconditions not met';
|
||||||
const CALLER_CANCELLED_ERR_MSG = 'Response not sent due to unknown transaction';
|
const CALLER_CANCELLED_ERR_MSG = 'Response not sent due to unknown transaction';
|
||||||
@@ -977,6 +978,64 @@ class CallSession extends Emitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* perform live call control - create rest:dial
|
||||||
|
* @param {obj} opts create call options
|
||||||
|
*/
|
||||||
|
async _lccCallDial(opts) {
|
||||||
|
try {
|
||||||
|
const restDialUrl = `${this.srf.locals.serviceUrl}/v1/createCall`;
|
||||||
|
await this.transformInputIfRequired(opts);
|
||||||
|
const resp = bent('POST', 'json', 201)(restDialUrl, opts);
|
||||||
|
this.logger.info(resp.body, 'successfully create outbound call');
|
||||||
|
return resp.body;
|
||||||
|
} catch (err) {
|
||||||
|
if (err.json) {
|
||||||
|
err.body = await err.json();
|
||||||
|
}
|
||||||
|
this.logger.error(err, 'failed to create outbound call from ' + this.callSid);
|
||||||
|
this._notifyTaskError(err.body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async transformInputIfRequired(opts) {
|
||||||
|
const {
|
||||||
|
lookupAppBySid
|
||||||
|
} = this.srf.locals.dbHelpers;
|
||||||
|
opts.account_sid = this.accountSid;
|
||||||
|
|
||||||
|
if (opts.application_sid) {
|
||||||
|
this.logger.debug(`Callsession:_validateCreateCall retrieving application ${opts.application_sid}`);
|
||||||
|
const application = await lookupAppBySid(opts.application_sid);
|
||||||
|
Object.assign(opts, {
|
||||||
|
call_hook: application.call_hook,
|
||||||
|
app_json: application.app_json,
|
||||||
|
call_status_hook: application.call_status_hook,
|
||||||
|
speech_synthesis_vendor: application.speech_synthesis_vendor,
|
||||||
|
speech_synthesis_language: application.speech_synthesis_language,
|
||||||
|
speech_synthesis_voice: application.speech_synthesis_voice,
|
||||||
|
speech_recognizer_vendor: application.speech_recognizer_vendor,
|
||||||
|
speech_recognizer_language: application.speech_recognizer_language
|
||||||
|
});
|
||||||
|
this.logger.debug({opts, application}, 'Callsession:_validateCreateCall augmented with application settings');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof opts.call_hook === 'string') {
|
||||||
|
const url = opts.call_hook;
|
||||||
|
opts.call_hook = {
|
||||||
|
url,
|
||||||
|
method: 'POST'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (typeof opts.call_status_hook === 'string') {
|
||||||
|
const url = opts.call_status_hook;
|
||||||
|
opts.call_status_hook = {
|
||||||
|
url,
|
||||||
|
method: 'POST'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* perform live call control -- set a new call_hook
|
* perform live call control -- set a new call_hook
|
||||||
* @param {object} opts
|
* @param {object} opts
|
||||||
@@ -1454,6 +1513,10 @@ Duration=${duration} `
|
|||||||
this._lccCallStatus(data);
|
this._lccCallStatus(data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'dial':
|
||||||
|
this._lccCallDial(data);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'mute:status':
|
case 'mute:status':
|
||||||
this._lccMuteStatus(call_sid, data);
|
this._lccMuteStatus(call_sid, data);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user