From 169560a09524bbfb8fedfc434f621e969311640c Mon Sep 17 00:00:00 2001 From: Sam Machin Date: Thu, 3 Jul 2025 14:52:54 +0100 Subject: [PATCH] add new /Callcount endpoint --- app.js | 6 ++++-- lib/helpers/realtimedb-helpers.js | 6 ++++-- lib/routes/api/accounts.js | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 7417696..a2c1c86 100644 --- a/app.js +++ b/app.js @@ -48,7 +48,8 @@ const { retrieveKey, deleteKey, incrKey, - listConferences + listConferences, + getCallCount } = require('./lib/helpers/realtimedb-helpers'); const { getTtsVoices, @@ -118,7 +119,8 @@ app.locals = { queryAlertsSP, writeCdrs, writeAlerts, - AlertType + AlertType, + getCallCount }; const unless = (paths, middleware) => { diff --git a/lib/helpers/realtimedb-helpers.js b/lib/helpers/realtimedb-helpers.js index dc9205c..919832e 100644 --- a/lib/helpers/realtimedb-helpers.js +++ b/lib/helpers/realtimedb-helpers.js @@ -13,7 +13,8 @@ const { deleteKey, incrKey, client: redisClient, - listConferences + listConferences, + getCallCount } = require('@jambonz/realtimedb-helpers')({}, logger); module.exports = { @@ -29,5 +30,6 @@ module.exports = { deleteKey, redisClient, incrKey, - listConferences + listConferences, + getCallCount }; diff --git a/lib/routes/api/accounts.js b/lib/routes/api/accounts.js index 1e72d45..7961c40 100644 --- a/lib/routes/api/accounts.js +++ b/lib/routes/api/accounts.js @@ -1220,4 +1220,23 @@ router.get('/:sid/Conferences', async(req, res) => { } }); +/** + * retrieve counts of calls under an account + */ +router.get('/:sid/Callcount', async(req, res) => { + const {logger, getCallCount} = req.app.locals; + try { + const accountSid = parseAccountSid(req); + await validateRequest(req, accountSid); + const count = await getCallCount(accountSid); + count.outbound = Number(count.outbound); + count.inbound = Number(count.inbound); + logger.debug(`retrieved, outbound: ${count.outbound}, inbound: ${count.inbound}, for account sid ${accountSid}`); + res.status(200).json(count); + updateLastUsed(logger, accountSid, req).catch((err) => {}); + } catch (err) { + sysError(logger, res, err); + } +}); + module.exports = router;