test
This commit is contained in:
parent
3cb5ab9a5e
commit
85d9b8aeb8
34
index.js
34
index.js
|
@ -77,14 +77,16 @@ function generateTransactionNumber() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendAlert(accountNumber, transaction, placeName, systemName, zoneNumber, zoneName, event) {
|
function sendAlert(accountNumber, transaction, placeName, systemName, zoneNumber, zoneName, event) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
if (handledTransactions.includes(transaction)) {
|
if (handledTransactions.includes(transaction)) {
|
||||||
return; // Duplicate transaction
|
resolve(); // Duplicate transaction
|
||||||
}
|
} else {
|
||||||
handledTransactions.push(transaction);
|
handledTransactions.push(transaction);
|
||||||
// Check if the account exists and is verified
|
// Check if the account exists and is verified
|
||||||
db.get("SELECT * FROM accounts WHERE id = ? AND verified = 1", accountNumber, (err, row) => {
|
db.get("SELECT * FROM accounts WHERE id = ? AND verified = 1", accountNumber, (err, row) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
reject(err);
|
||||||
} else if (row) {
|
} else if (row) {
|
||||||
// Account exists and is verified
|
// Account exists and is verified
|
||||||
// Send the alert
|
// Send the alert
|
||||||
|
@ -95,15 +97,27 @@ function sendAlert(accountNumber, transaction, placeName, systemName, zoneNumber
|
||||||
|
|
||||||
runCommand(`/var/lib/asterisk/bin/originate ${row.phone} roblox.s.1 0 0 /tmp/${transaction}-alert "IktDQSBTZWN1cmlOZXQiIDw+"`).then(() => {
|
runCommand(`/var/lib/asterisk/bin/originate ${row.phone} roblox.s.1 0 0 /tmp/${transaction}-alert "IktDQSBTZWN1cmlOZXQiIDw+"`).then(() => {
|
||||||
console.log(`Alert sent to ${row.phone}`);
|
console.log(`Alert sent to ${row.phone}`);
|
||||||
})
|
resolve();
|
||||||
})
|
}).catch((error) => {
|
||||||
})
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return;
|
resolve();
|
||||||
// Account does not exist or is not verified
|
// Account does not exist or is not verified
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function sendVerificationCode(account) {
|
function sendVerificationCode(account) {
|
||||||
// Get verification code from database
|
// Get verification code from database
|
||||||
|
@ -301,9 +315,13 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
app.post("/api/v1/alert", (req, res) => {
|
app.post("/api/v1/alert", (req, res) => {
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
// send no content response
|
// send no content response
|
||||||
res.sendStatus(204);
|
sendAlert(req.body.accountNumber, req.body.transaction, req.body.placeName, req.body.systemName, req.body.zoneNumber, req.body.zoneName, req.body.event).then(() => {
|
||||||
|
res.status(204).send();
|
||||||
|
}).catch((error) => {
|
||||||
|
res.status(500).send();
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
sendAlert("6371787150", generateTransactionNumber(), "KCA Product Showcase", "Building Security", 1, "Front Door", "alarm");
|
// sendAlert("6371787150", generateTransactionNumber(), "KCA Product Showcase", "Building Security", 1, "Front Door", "alarm");
|
||||||
startTime = new Date();
|
startTime = new Date();
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
client.login(process.env.DISCORD_TOKEN);
|
Loading…
Reference in a new issue