Some basic call logging (timestamp, caller, callee)

This commit is contained in:
Christopher Cookman 2024-12-16 16:59:08 -07:00
parent 7c7d96fbfd
commit a1fdfbf8e0
2 changed files with 21 additions and 5 deletions

View file

@ -622,6 +622,14 @@ app.get("/api/healthcheck", (req, res) => {
});
});
// logCall function (caller, callee)
const logCall = (caller, callee) => {
db.run('INSERT INTO callLogs (caller, callee, timestamp) VALUES (?, ?, ?)',
[caller, callee, Math.floor(Date.now() / 1000)],
(err) => {
if (err) console.error('Error logging call:', err);
});
}
// Query to get a route
app.get('/api/v1/route/:apiKey/:ani/:number', (req, res) => {
@ -643,6 +651,7 @@ app.get('/api/v1/route/:apiKey/:ani/:number', (req, res) => {
// Check if the ANI is within the block range
// If it is, return `local`
console.log(`New Call: ${ani} -> ${number}`);
logCall(ani, number);
// incriment estCallsMade analytics
addAnalytic("estCallsMade");
dailyAnalytic("dailyCallsMade");
@ -677,6 +686,7 @@ app.get('/api/v1', (req, res) => { // Backwards compatibility with TandmX cause
// Check if the ANI is within the block range
// If it is, return `local`
console.log(`New Call: ${ani} -> ${number}`);
logCall(ani, number);
addAnalytic("estCallsMade");
dailyAnalytic("dailyCallsMade");
if (ani >= row.block_start && ani <= row.block_start + row.block_length) {

View file

@ -0,0 +1,6 @@
CREATE TABLE callLogs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
caller TEXT NOT NULL,
callee TEXT NOT NULL
);