From 9854666d4f661dc4c2848011961c0d59fa6494f2 Mon Sep 17 00:00:00 2001 From: Sam Machin Date: Thu, 3 Jul 2025 16:49:27 +0100 Subject: [PATCH] add new /Callcount endpoint (#480) * add new /Callcount endpoint * update db-helpers * update endpoint --- app.js | 6 ++++-- lib/helpers/realtimedb-helpers.js | 6 ++++-- lib/routes/api/accounts.js | 19 +++++++++++++++++++ package-lock.json | 8 ++++---- package.json | 2 +- 5 files changed, 32 insertions(+), 9 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..c3863f1 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; diff --git a/package-lock.json b/package-lock.json index ad20ac9..d0c004d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@jambonz/db-helpers": "^0.9.12", "@jambonz/lamejs": "^1.2.2", "@jambonz/mw-registrar": "^0.2.7", - "@jambonz/realtimedb-helpers": "^0.8.14", + "@jambonz/realtimedb-helpers": "^0.8.15", "@jambonz/speech-utils": "^0.2.13", "@jambonz/time-series": "^0.2.8", "@jambonz/verb-specifications": "^0.0.107", @@ -4145,9 +4145,9 @@ } }, "node_modules/@jambonz/realtimedb-helpers": { - "version": "0.8.14", - "resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.14.tgz", - "integrity": "sha512-KW+5f7Tlmx6WQjD2m1TBD3dEOPGhAhVespgy4OlevoXuLK1XGFSpArFePWmMfrOfrQCnFvpQY8A1njmK9TezSg==", + "version": "0.8.15", + "resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.15.tgz", + "integrity": "sha512-gGQrUL9eHO+Gx2nSphl6/GwCo1Vui3GfKvjUYrxxicGPFDV+m8UMvWPKfgL9xHa3GIwGGDGeGDj5jJf77/RT9A==", "license": "MIT", "dependencies": { "debug": "^4.3.4", diff --git a/package.json b/package.json index 0beae4d..975d913 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@jambonz/db-helpers": "^0.9.12", "@jambonz/lamejs": "^1.2.2", "@jambonz/mw-registrar": "^0.2.7", - "@jambonz/realtimedb-helpers": "^0.8.14", + "@jambonz/realtimedb-helpers": "^0.8.15", "@jambonz/speech-utils": "^0.2.13", "@jambonz/time-series": "^0.2.8", "@jambonz/verb-specifications": "^0.0.107",