snake case REST payloads, support for LCC with child_call_hook, handle 302 on outdial

This commit is contained in:
Dave Horton
2021-04-22 14:39:54 -04:00
parent 8eb0cd1520
commit 576f645489
11 changed files with 340 additions and 179 deletions

View File

@@ -7,11 +7,13 @@ const {DbErrorUnprocessableRequest} = require('../utils/errors');
/**
* validate the call state
*/
function retrieveCallSession(callSid, opts) {
function retrieveCallSession(logger, callSid, opts) {
logger.debug(`retrieving session for callSid ${callSid}`);
const cs = sessionTracker.get(callSid);
if (cs) {
const task = cs.currentTask;
if (!task || task.name != TaskName.Enqueue) {
logger.debug({cs}, 'found call session but not in Enqueue task??');
throw new DbErrorUnprocessableRequest(`enqueue api failure: indicated call is not queued: ${task.name}`);
}
}
@@ -19,14 +21,14 @@ function retrieveCallSession(callSid, opts) {
}
/**
* notify a waiting session that a conference has started
* notify a waiting session that a queue event has occurred
*/
router.post('/:callSid', async(req, res) => {
const logger = req.app.locals.logger;
const callSid = req.params.callSid;
logger.debug({body: req.body}, 'got enqueue event');
logger.debug({callSid, body: req.body}, 'got enqueue event');
try {
const cs = retrieveCallSession(callSid, req.body);
const cs = retrieveCallSession(logger, callSid, req.body);
if (!cs) {
logger.info(`enqueue: callSid not found ${callSid}`);
return res.sendStatus(404);