add new /Callcount endpoint (#480)

* add new /Callcount endpoint

* update db-helpers

* update endpoint
This commit is contained in:
Sam Machin
2025-07-03 16:49:27 +01:00
committed by GitHub
parent 0d4b7e88ad
commit 9854666d4f
5 changed files with 32 additions and 9 deletions

6
app.js
View File

@@ -48,7 +48,8 @@ const {
retrieveKey, retrieveKey,
deleteKey, deleteKey,
incrKey, incrKey,
listConferences listConferences,
getCallCount
} = require('./lib/helpers/realtimedb-helpers'); } = require('./lib/helpers/realtimedb-helpers');
const { const {
getTtsVoices, getTtsVoices,
@@ -118,7 +119,8 @@ app.locals = {
queryAlertsSP, queryAlertsSP,
writeCdrs, writeCdrs,
writeAlerts, writeAlerts,
AlertType AlertType,
getCallCount
}; };
const unless = (paths, middleware) => { const unless = (paths, middleware) => {

View File

@@ -13,7 +13,8 @@ const {
deleteKey, deleteKey,
incrKey, incrKey,
client: redisClient, client: redisClient,
listConferences listConferences,
getCallCount
} = require('@jambonz/realtimedb-helpers')({}, logger); } = require('@jambonz/realtimedb-helpers')({}, logger);
module.exports = { module.exports = {
@@ -29,5 +30,6 @@ module.exports = {
deleteKey, deleteKey,
redisClient, redisClient,
incrKey, incrKey,
listConferences listConferences,
getCallCount
}; };

View File

@@ -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; module.exports = router;

8
package-lock.json generated
View File

@@ -19,7 +19,7 @@
"@jambonz/db-helpers": "^0.9.12", "@jambonz/db-helpers": "^0.9.12",
"@jambonz/lamejs": "^1.2.2", "@jambonz/lamejs": "^1.2.2",
"@jambonz/mw-registrar": "^0.2.7", "@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/speech-utils": "^0.2.13",
"@jambonz/time-series": "^0.2.8", "@jambonz/time-series": "^0.2.8",
"@jambonz/verb-specifications": "^0.0.107", "@jambonz/verb-specifications": "^0.0.107",
@@ -4145,9 +4145,9 @@
} }
}, },
"node_modules/@jambonz/realtimedb-helpers": { "node_modules/@jambonz/realtimedb-helpers": {
"version": "0.8.14", "version": "0.8.15",
"resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.14.tgz", "resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.15.tgz",
"integrity": "sha512-KW+5f7Tlmx6WQjD2m1TBD3dEOPGhAhVespgy4OlevoXuLK1XGFSpArFePWmMfrOfrQCnFvpQY8A1njmK9TezSg==", "integrity": "sha512-gGQrUL9eHO+Gx2nSphl6/GwCo1Vui3GfKvjUYrxxicGPFDV+m8UMvWPKfgL9xHa3GIwGGDGeGDj5jJf77/RT9A==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"debug": "^4.3.4", "debug": "^4.3.4",

View File

@@ -30,7 +30,7 @@
"@jambonz/db-helpers": "^0.9.12", "@jambonz/db-helpers": "^0.9.12",
"@jambonz/lamejs": "^1.2.2", "@jambonz/lamejs": "^1.2.2",
"@jambonz/mw-registrar": "^0.2.7", "@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/speech-utils": "^0.2.13",
"@jambonz/time-series": "^0.2.8", "@jambonz/time-series": "^0.2.8",
"@jambonz/verb-specifications": "^0.0.107", "@jambonz/verb-specifications": "^0.0.107",