add new /Callcount endpoint

This commit is contained in:
Sam Machin
2025-07-03 14:52:54 +01:00
parent 9b4f1b67bf
commit 169560a095
3 changed files with 27 additions and 4 deletions
+4 -2
View File
@@ -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) => {
+4 -2
View File
@@ -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
};
+19
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;