swap it around so it looks for the wav instead of the txt, it takes longest to write lol

This commit is contained in:
Christopher Cookman 2023-10-01 17:55:46 -06:00
parent 84d4c64ec0
commit 9df1f44fb5
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -96,37 +96,37 @@ const watcher = chokidar.watch(config.freepbx.voicemaildir, {
watched = []; watched = [];
watcher.on("add", async (filePath, stats) => { watcher.on("add", async (filePath, stats) => {
if (startup) return; if (startup) return;
// if the file is already being watched, ignore it, this stops spam from the watcher at startup
if (watched.includes(filePath)) return; if (watched.includes(filePath)) return;
watched.push(filePath); watched.push(filePath);
// extract file name from path
let filename = pathSplit(filePath)[pathSplit(filePath).length - 1]; let filename = pathSplit(filePath)[pathSplit(filePath).length - 1];
if (!filename.endsWith("txt")) return; // ignore anything that isn't a txt file (voicemail info file), we can get other file names based on the name without the extension if (!filename.endsWith("wav")) return;
let mailbox = pathSplit(filePath)[pathSplit(filePath).length - 2]; let mailbox = pathSplit(filePath)[pathSplit(filePath).length - 2];
if (mailbox !== "INBOX") return; // ignore anything that isn't in the inbox if (mailbox !== "INBOX") return;
vmData = fpbxFuncs.parseVoicemailInfo(fs.readFileSync(filePath, "utf8"))
// get the extension info from the origmailbox let txtFile = filePath.replace(".wav", ".txt");
if (!fs.existsSync(txtFile)) return;
vmData = fpbxFuncs.parseVoicemailInfo(fs.readFileSync(txtFile, "utf8"));
let extData = await lookupExtension(vmData.origmailbox, "ext").catch((error) => { let extData = await lookupExtension(vmData.origmailbox, "ext").catch((error) => {
console.log(error); console.log(error);
}); });
if(!extData) return; // The extension doesnt have a discord ID set, ignore it if (!extData) return;
let discordId = extData.result.fetchVoiceMail.email; let discordId = extData.result.fetchVoiceMail.email;
let discordUser = await client.users.fetch(discordId).catch((error) => { let discordUser = await client.users.fetch(discordId).catch((error) => {
console.log(error); console.log(error);
}); });
// parse callerid "john doe" <1234> into just john doe and 1234
let callerid = vmData.callerid; let callerid = vmData.callerid;
let calleridName = callerid.split(" <")[0].replaceAll("\"", ""); let calleridName = callerid.split(" <")[0].replaceAll("\"", "");
let calleridNumber = callerid.split(" <")[1].replace(">", ""); let calleridNumber = callerid.split(" <")[1].replace(">", "");
// format the callerid
vmData.callerid = `${calleridName} (${calleridNumber})`; vmData.callerid = `${calleridName} (${calleridNumber})`;
// get the voicemail file (.wav)
let vmFile = filePath.replace(".txt", ".wav");
await discordUser.send({ await discordUser.send({
content: `:mailbox_with_mail: New voicemail from ${vmData.callerid}!`, content: `:mailbox_with_mail: New voicemail from ${vmData.callerid}!`,
files: [{ files: [{
attachment: vmFile, attachment: filePath,
name: `voicemail.wav` name: `voicemail.wav`
}] }]
}).catch((error) => { }).catch((error) => {