gwug
This commit is contained in:
parent
07b1541e01
commit
5e603ec010
25
index.js
25
index.js
|
|
@ -47,6 +47,31 @@ function trigCall(pageType, phone, variables = {}) {
|
||||||
throw new Error(`Phone number is required for page type: ${pageType}`);
|
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) => {
|
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}`);
|
console.log(`Call originated: ${output}`);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ router.post("/trigger", global.apiAuth, (req, res) => {
|
||||||
|
|
||||||
router.post("/stop", global.apiAuth, (req, res) => {
|
router.post("/stop", global.apiAuth, (req, res) => {
|
||||||
console.log('Stopping all calls');
|
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) {
|
if (error) {
|
||||||
console.error(`Error stopping page: ${error}`);
|
console.error(`Error stopping page: ${error}`);
|
||||||
return res.status(500).send('Error stopping page');
|
return res.status(500).send('Error stopping page');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue