Add delete logic
This commit is contained in:
parent
1a430e1b4a
commit
daceb05d52
15
index.js
15
index.js
|
|
@ -33,7 +33,20 @@ const main = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("Call forwards:", forwards);
|
|
||||||
|
// Search all forwards for any target that is between 700 and 800. If it exists, log to console and run `asterisk -x "database del CF[U/B] <ext>"` to delete it
|
||||||
|
for (const [key, target] of Object.entries(forwards)) {
|
||||||
|
const targetExt = parseInt(target, 10);
|
||||||
|
if (targetExt >= 700 && targetExt < 800) {
|
||||||
|
console.log(`Deleting forward ${key} to target ${target}`);
|
||||||
|
const delCommand = `asterisk -x "database del ${key.replace('/', ' ')}"`;
|
||||||
|
const { error, stdout, stderr } = await runAsterisk(delCommand);
|
||||||
|
if (error) {
|
||||||
|
console.error(`Error executing command "${delCommand}": ${error}`);
|
||||||
|
} else {
|
||||||
|
console.log(`Successfully deleted forward ${key}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Unexpected error: ${err}`);
|
console.error(`Unexpected error: ${err}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue