diff --git a/index.js b/index.js index 6fabe5e..59446c2 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,56 @@ const { exec } = require('child_process'); require('dotenv').config(); +const contexts = { + "A1": { + context: 'custom-emergency.9001.1', + timeout: 30000, + cid: 'Live Page' + }, + "E1": { + context: 'custom-emergency.9002.1', + timeout: 30000, + cid: 'Emergency Live Page' + }, + "A2": { + context: 'custom-emergency.9003.1', + timeout: 30000, + cid: 'Announcement 2', + number: '2000' // Direct to page group, no phone needed + }, + "E2": { + context: 'custom-emergency.9004.1', + timeout: 30000, + cid: 'Emergency 2', + number: '2000' // Direct to page group, no phone needed + }, + "A3": { + context: 'custom-emergency.9005.1', + timeout: 30000, + cid: 'Announcement 3', + number: '2000' // Direct to page group, no phone needed + }, + "E3": { + context: 'custom-emergency.9006.1', + timeout: 30000, + cid: 'Emergency 3', + number: '2000' // Direct to page group, no phone needed + } +} + +function trigCall(pageType, phone) { + // If contexts[pageType] does not exist, return an error + if (!contexts[pageType]) { + throw new Error(`Invalid page type: ${pageType}`); + } + const { context, timeout, cid, number } = contexts[pageType]; + const targetNumber = number || phone; + if (!targetNumber) { + throw new Error(`Phone number is required for page type: ${pageType}`); + } + return originateCall(targetNumber, context, 0, timeout, cid); +} + function originateCall(number, context, delay, timeout, cid, variables = {}) { // Build the base command let command = `/usr/bin/ast_originate ${number} ${context} ${delay} ${timeout} ${Buffer.from(cid).toString('base64')}`; @@ -52,25 +102,12 @@ function auth(req, res, next) { next(); } -app.get('/', auth, (req, res) => { +app.get('/', (req, res) => { res.render('index', { session: req.session }); }); -app.get('/login', (req, res) => { - if (req.session && req.session.authenticated) { - return res.redirect('/'); - } - res.render('login'); -}); - -app.post('/login', (req, res) => { - const { username, password } = req.body; - if (username === process.env.USER && password === process.env.PASS) { - req.session.authenticated = true; - req.session.username = username; - return res.redirect('/'); - } - res.redirect('/login'); +app.post('/trig', async (req, res) => { + console.log('Triggering call with data:', req.body); }); app.listen(PORT, HOST, () => { diff --git a/views/index.ejs b/views/index.ejs index b24cf8c..7868a9b 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -7,11 +7,66 @@
This is a simple web page to demonstrate EJS templating with Bootstrap styling.
- +Normal Announcements |
+ Emergency Announcements |
+
|---|---|
| + + | ++ + | +
| + + | ++ + | +
| + + | ++ + | +