diff --git a/lib/models/account.js b/lib/models/account.js index 2fc5612..19e3ead 100644 --- a/lib/models/account.js +++ b/lib/models/account.js @@ -68,7 +68,7 @@ function transmogrifyResults(results) { /* queue event hook */ if (row.qh && Object.keys(row.qh).length && row.qh.url !== null) { - Object.assign(obj, {queue_event_hook: row.rh}); + Object.assign(obj, {queue_event_hook: row.qh}); delete obj.queue_event_hook.webhook_sid; } else obj.queue_event_hook = null; diff --git a/lib/routes/api/accounts.js b/lib/routes/api/accounts.js index e960ff6..575a7bb 100644 --- a/lib/routes/api/accounts.js +++ b/lib/routes/api/accounts.js @@ -253,6 +253,9 @@ async function validateAdd(req) { if (req.body.registration_hook && typeof req.body.registration_hook !== 'object') { throw new DbErrorBadRequest('\'registration_hook\' must be an object when adding an account'); } + if (req.body.queue_event_hook && typeof req.body.queue_event_hook !== 'object') { + throw new DbErrorBadRequest('\'queue_event_hook\' must be an object when adding an account'); + } } async function validateUpdate(req, sid) { if (req.user.hasAccountAuth && req.user.account_sid !== sid) { @@ -292,11 +295,11 @@ router.post('/', async(req, res) => { // create webhooks if provided const obj = {...req.body, webhook_secret: secret}; - for (const prop of ['registration_hook']) { - if (obj[prop]) { + for (const prop of ['registration_hook', 'queue_event_hook']) { + if (obj[prop] && obj[prop].url && obj[prop].url.length > 0) { obj[`${prop}_sid`] = await Webhook.make(obj[prop]); - delete obj[prop]; } + delete obj[prop]; } logger.debug(`Attempting to add account ${JSON.stringify(obj)}`); @@ -363,7 +366,7 @@ router.put('/:sid', async(req, res) => { const obj = Object.assign({}, req.body); for (const prop of ['registration_hook', 'queue_event_hook']) { if (prop in obj) { - if (null === obj[prop]) { + if (null === obj[prop] || !obj[prop].url || 0 === obj[prop].url.length) { obj[`${prop}_sid`] = null; } else if (typeof obj[prop] === 'object') {