diff --git a/index.js b/index.js index 0126722..05be0e7 100644 --- a/index.js +++ b/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] "` 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) { console.error(`Unexpected error: ${err}`); }