From 5e603ec01011bd4ca0593c2d14ca9a97982d8e1a Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 11 Jan 2026 10:09:21 -0700 Subject: [PATCH] gwug --- index.js | 25 +++++++++++++++++++++++++ routes/api/portal.js | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a376864..9677a98 100644 --- a/index.js +++ b/index.js @@ -47,6 +47,31 @@ function trigCall(pageType, phone, variables = {}) { throw new Error(`Phone number is required for page type: ${pageType}`); } + // Sling message + if (sling_chat_id && sling_chat_message && global.slingToken) { + const replacedMessage = typeof sling_chat_message === 'string' + ? sling_chat_message.replace(/%initiatingUser%/g, variables.initiatingUser || '') + : sling_chat_message; + fetch(`https://api.getsling.com/v1/conversations/${sling_chat_id}/messages`, { + method: 'POST', + headers: { + 'Authorization': `${global.slingToken}`, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + 'content': replacedMessage + }) + }).then(res => res.json()).then(data => { + if (data && data.success) { + console.log('Sling chat message sent successfully.'); + } else { + console.error('Error sending Sling chat message:', data); + } + }).catch(error => { + console.error('Error sending Sling chat message:', error); + }); + } + originateCall(targetNumber, context, 0, timeout, cid, {initiatingUser: variables.username, slingChannel: sling_chat_id || undefined, slingMessage: sling_chat_message || undefined}).then((output) => { console.log(`Call originated: ${output}`); }).catch((error) => { diff --git a/routes/api/portal.js b/routes/api/portal.js index 7b74452..aeab499 100644 --- a/routes/api/portal.js +++ b/routes/api/portal.js @@ -12,7 +12,7 @@ router.post("/trigger", global.apiAuth, (req, res) => { router.post("/stop", global.apiAuth, (req, res) => { console.log('Stopping all calls'); - global.exec(`/usr/bin/ast_drop ${process.env.PAGE_GROUP || '9000'}`, (error, stdout, stderr) => { + global.exec(`/usr/sbin/asterisk -x "confbridge kick rsc_page all"`, (error, stdout, stderr) => { if (error) { console.error(`Error stopping page: ${error}`); return res.status(500).send('Error stopping page');