From 60359ab0f1acdb0edcf5cb4435b7b7e04b627829 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 26 Jun 2023 22:05:39 +0200 Subject: [PATCH 1/3] Fix presence actions error messages --- lib/plugins_command_13/cfSet.js | 2 +- lib/plugins_command_13/cfVmSet.js | 2 +- lib/plugins_command_13/cfbSet.js | 2 +- lib/plugins_command_13/cfbVmSet.js | 2 +- lib/plugins_command_13/cfuSet.js | 2 +- lib/plugins_command_13/cfuVmSet.js | 2 +- lib/plugins_command_13/dndSet.js | 64 +++++++++++++--------------- lib/plugins_command_13/robSet.js | 2 +- lib/proxy_logic_13/proxy_logic_13.js | 1 - 9 files changed, 36 insertions(+), 43 deletions(-) diff --git a/lib/plugins_command_13/cfSet.js b/lib/plugins_command_13/cfSet.js index eb402c4..d40f307 100644 --- a/lib/plugins_command_13/cfSet.js +++ b/lib/plugins_command_13/cfSet.js @@ -116,7 +116,7 @@ var IDLOG = '[cfSet]'; delete map[data.actionid]; // remove association ActionID-callback } else if (map[data.actionid] && data.response === 'Error') { - map[data.actionid](new Error('error')); + map[data.actionid](new Error(data.message || 'unknown error')); delete map[data.actionid]; // remove association ActionID-callback } diff --git a/lib/plugins_command_13/cfVmSet.js b/lib/plugins_command_13/cfVmSet.js index 2dde573..091861f 100644 --- a/lib/plugins_command_13/cfVmSet.js +++ b/lib/plugins_command_13/cfVmSet.js @@ -123,7 +123,7 @@ var IDLOG = '[cfVmSet]'; delete map[data.actionid]; // remove association ActionID-callback } else if (map[data.actionid] && data.response === 'Error') { - map[data.actionid](new Error('error')); + map[data.actionid](new Error(data.message || 'unknown error')); delete map[data.actionid]; // remove association ActionID-callback } diff --git a/lib/plugins_command_13/cfbSet.js b/lib/plugins_command_13/cfbSet.js index 61e82b6..fb45e4e 100644 --- a/lib/plugins_command_13/cfbSet.js +++ b/lib/plugins_command_13/cfbSet.js @@ -116,7 +116,7 @@ var IDLOG = '[cfbSet]'; delete map[data.actionid]; // remove association ActionID-callback } else if (map[data.actionid] && data.response === 'Error') { - map[data.actionid](new Error('error')); + map[data.actionid](new Error(data.message || 'unknown error')); delete map[data.actionid]; // remove association ActionID-callback } diff --git a/lib/plugins_command_13/cfbVmSet.js b/lib/plugins_command_13/cfbVmSet.js index 56fa122..4ca8512 100644 --- a/lib/plugins_command_13/cfbVmSet.js +++ b/lib/plugins_command_13/cfbVmSet.js @@ -124,7 +124,7 @@ var IDLOG = '[cfbVmSet]'; delete map[data.actionid]; // remove association ActionID-callback } else if (map[data.actionid] && data.response === 'Error') { - map[data.actionid](new Error('error')); + map[data.actionid](new Error(data.message || 'unknown error')); delete map[data.actionid]; // remove association ActionID-callback } diff --git a/lib/plugins_command_13/cfuSet.js b/lib/plugins_command_13/cfuSet.js index 9fb4cfe..f845e83 100644 --- a/lib/plugins_command_13/cfuSet.js +++ b/lib/plugins_command_13/cfuSet.js @@ -117,7 +117,7 @@ var IDLOG = '[cfuSet]'; delete map[data.actionid]; // remove association ActionID-callback } else if (map[data.actionid] && data.response === 'Error') { - map[data.actionid](new Error('error')); + map[data.actionid](new Error(data.message || 'unknown error')); delete map[data.actionid]; // remove association ActionID-callback } diff --git a/lib/plugins_command_13/cfuVmSet.js b/lib/plugins_command_13/cfuVmSet.js index 5e038cb..c471a65 100644 --- a/lib/plugins_command_13/cfuVmSet.js +++ b/lib/plugins_command_13/cfuVmSet.js @@ -124,7 +124,7 @@ var IDLOG = '[cfuVmSet]'; delete map[data.actionid]; // remove association ActionID-callback } else if (map[data.actionid] && data.response === 'Error') { - map[data.actionid](new Error('error')); + map[data.actionid](new Error(data.message || 'unknown error')); delete map[data.actionid]; // remove association ActionID-callback } diff --git a/lib/plugins_command_13/dndSet.js b/lib/plugins_command_13/dndSet.js index 9796f45..8d406ff 100644 --- a/lib/plugins_command_13/dndSet.js +++ b/lib/plugins_command_13/dndSet.js @@ -2,7 +2,7 @@ * @module astproxy * @submodule plugins_command_13 */ -var action = require('../action'); +var action = require("../action"); /** * The module identifier used by the logger. @@ -14,10 +14,9 @@ var action = require('../action'); * @readOnly * @default [dndSet] */ -var IDLOG = '[dndSet]'; - -(function() { +var IDLOG = "[dndSet]"; +(function () { /** * The logger. It must have at least three methods: _info, warn and error._ * @@ -55,7 +54,6 @@ var IDLOG = '[dndSet]'; * @static */ var dndSet = { - /** * Execute asterisk action to set the DND status. * @@ -65,34 +63,33 @@ var IDLOG = '[dndSet]'; * @param {function} cb The callback function * @static */ - execute: function(am, args, cb) { + execute: function (am, args, cb) { try { var act; // action for asterisk if (args.activate) { act = { - Action: 'DBPut', - Family: 'DND', + Action: "DBPut", + Family: "DND", Key: args.exten, - Val: 'YES' + Val: "YES", }; } else { act = { - Action: 'DBDel', - Family: 'DND', - Key: args.exten + Action: "DBDel", + Family: "DND", + Key: args.exten, }; } // set the action identifier - act.ActionID = action.getActionId('dndSet'); + act.ActionID = action.getActionId("dndSet"); // add association ActionID-callback map[act.ActionID] = cb; // send action to asterisk am.send(act); - } catch (err) { logger.error(IDLOG, err.stack); } @@ -106,24 +103,21 @@ var IDLOG = '[dndSet]'; * @param {object} data The asterisk data for the current command * @static */ - data: function(data) { + data: function (data) { try { // check callback and info presence and execute it - if (map[data.actionid] && - ( - data.message === 'Updated database successfully' || - data.message === 'Key deleted successfully' - ) && - data.response === 'Success') { - + if ( + map[data.actionid] && + (data.message === "Updated database successfully" || + data.message === "Key deleted successfully") && + data.response === "Success" + ) { map[data.actionid](null); delete map[data.actionid]; // remove association ActionID-callback - - } else if (map[data.actionid] && data.response === 'Error') { - map[data.actionid](new Error('error')); + } else if (map[data.actionid] && data.response === "Error") { + map[data.actionid](new Error(data.message || "unknown error")); delete map[data.actionid]; // remove association ActionID-callback } - } catch (err) { logger.error(IDLOG, err.stack); if (map[data.actionid]) { @@ -141,28 +135,28 @@ var IDLOG = '[dndSet]'; * three methods: _info, warn and error_ * @static */ - setLogger: function(log) { + setLogger: function (log) { try { - if (typeof log === 'object' && - typeof log.info === 'function' && - typeof log.warn === 'function' && - typeof log.error === 'function') { - + if ( + typeof log === "object" && + typeof log.info === "function" && + typeof log.warn === "function" && + typeof log.error === "function" + ) { logger = log; } else { - throw new Error('wrong logger object'); + throw new Error("wrong logger object"); } } catch (err) { logger.error(IDLOG, err.stack); } - } + }, }; // public interface exports.data = dndSet.data; exports.execute = dndSet.execute; exports.setLogger = dndSet.setLogger; - } catch (err) { logger.error(IDLOG, err.stack); } diff --git a/lib/plugins_command_13/robSet.js b/lib/plugins_command_13/robSet.js index 92899fa..69d7196 100644 --- a/lib/plugins_command_13/robSet.js +++ b/lib/plugins_command_13/robSet.js @@ -110,7 +110,7 @@ var IDLOG = '[robSet]'; delete map[data.actionid]; // remove association ActionID-callback } else if (map[data.actionid] && data.response === 'Error') { - map[data.actionid](new Error('error')); + map[data.actionid](new Error(data.message || 'unknown error')); delete map[data.actionid]; // remove association ActionID-callback } } catch (err) { diff --git a/lib/proxy_logic_13/proxy_logic_13.js b/lib/proxy_logic_13/proxy_logic_13.js index 3832ca2..7ba7046 100644 --- a/lib/proxy_logic_13/proxy_logic_13.js +++ b/lib/proxy_logic_13/proxy_logic_13.js @@ -5236,7 +5236,6 @@ function evtExtenCfbVmChanged(exten, enabled, vm) { enabled: enabled, vm: vm }); - } else { logger.warn(IDLOG, 'try to set call forward busy to voicemail status of non existent extension ' + exten); } From a5972e8102684a18fdfaebf2ceb3688ecea514bd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 6 Jul 2023 14:38:58 +0200 Subject: [PATCH 2/3] Manage extensions statuses update --- lib/proxy_logic_13/proxy_logic_13.js | 44 ++++++++++++++++------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/proxy_logic_13/proxy_logic_13.js b/lib/proxy_logic_13/proxy_logic_13.js index 7ba7046..db9b35f 100644 --- a/lib/proxy_logic_13/proxy_logic_13.js +++ b/lib/proxy_logic_13/proxy_logic_13.js @@ -5324,8 +5324,6 @@ function isExten(id) { /** * Enable/disable the do not disturb status of the endpoint. - * The used plugin command _dndSet_ does not generate any - * asterisk events, so simulates it. * * @method setDnd * @param {string} exten The extension number @@ -5346,11 +5344,12 @@ function setDnd(exten, activate, cb) { command: 'dndSet', exten: exten, activate: activate - }, function (err) { - cb(err); - if (err === null) { - evtExtenDndChanged(exten, activate); + if (err) { + cb(err); + } else { + // Update the dnd status of the extension + getDndExten(exten)(cb); } }); } else { @@ -5593,10 +5592,11 @@ function setUnconditionalCf(exten, activate, to, cb) { activate: activate, val: to }, function (err) { - - cb(err); - if (err === null) { - evtExtenUnconditionalCfChanged(exten, activate, to); + if (err) { + cb(err); + } else { + // Update the callforward status of the extension + getCfExten(exten)(cb); } }); @@ -5728,9 +5728,11 @@ function setCfuVm(exten, activate, to, cb) { val: to }, function (err, resp) { - cb(err, resp); - if (err === null) { - evtExtenCfuVmChanged(exten, activate, to); + if (err) { + cb(err); + } else { + // Update the callforward on unavailable status of the extension + getCfuVmExten(exten)(cb); } }); @@ -5772,9 +5774,11 @@ function setCfu(exten, activate, to, cb) { val: to }, function (err) { - cb(err); - if (err === null) { - evtExtenCfuChanged(exten, activate, to); + if (err) { + cb(err); + } else { + // Update the callforward on unavailable status of the extension + getCfuExten(exten)(cb); } }); @@ -5817,9 +5821,11 @@ function setUnconditionalCfVm(exten, activate, to, cb) { val: to }, function (err, resp) { - cb(err, resp); - if (err === null) { - evtExtenUnconditionalCfVmChanged(exten, activate, to); + if (err) { + cb(err); + } else { + // Update the voicemail status of the extension + getCfVmExten(exten)(cb); } }); From 62bac0351138b72e724f06544baa8186302f7247 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 7 Jul 2023 16:39:53 +0200 Subject: [PATCH 3/3] Handle CFU and CFB change event --- lib/plugins_event_13/newexten.js | 36 +++++++++++++++++++++++++++- lib/proxy_logic_13/proxy_logic_13.js | 11 +++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/plugins_event_13/newexten.js b/lib/plugins_event_13/newexten.js index 6dd143d..9a0f779 100644 --- a/lib/plugins_event_13/newexten.js +++ b/lib/plugins_event_13/newexten.js @@ -118,7 +118,41 @@ var astProxy; astProxy.proxyLogic.evtExtenUnconditionalCfChanged(ext, false); astProxy.proxyLogic.evtExtenUnconditionalCfVmChanged(ext, false); } - } catch (err) { + // CFU on (e.g. data.appdata = 'DB(CFU/92211)=123') + else if (data.event === 'Newexten' && data.appdata && + data.appdata.indexOf('DB(CFU/') === 0) { + + ext = (data.appdata.split('/')[1]).split(')')[0]; + var to = data.appdata.split('=')[1]; + logger.info(IDLOG, 'received event CFU "on" for extension ' + ext); + astProxy.proxyLogic.evtExtenCfuChanged(ext, true, to); + } + // CFU off (e.g. data.appdata = 'Deleting: CFU/92211 123') + else if (data.event === 'Newexten' && data.appdata && + data.appdata.indexOf('Deleting: CFU/') === 0) { + + ext = (data.appdata.split('/')[1]).split(' ')[0]; + logger.info(IDLOG, 'received event CFU "off" for extension ' + ext); + astProxy.proxyLogic.evtExtenCfuChanged(ext, false); + } + // CFB on (e.g. data.appdata = 'DB(CFB/92211)=123') + else if (data.event === 'Newexten' && data.appdata && + data.appdata.indexOf('DB(CFB/') === 0) { + + ext = (data.appdata.split('/')[1]).split(')')[0]; + var to = data.appdata.split('=')[1]; + logger.info(IDLOG, 'received event CFB "on" for extension ' + ext); + astProxy.proxyLogic.evtExtenCfbChanged(ext, true, to); + } + // CFB off (e.g. data.appdata = 'Deleting: CFB/92211 123') + else if (data.event === 'Newexten' && data.appdata && + data.appdata.indexOf('Deleting: CFB/') === 0) { + + ext = (data.appdata.split('/')[1]).split(' ')[0]; + logger.info(IDLOG, 'received event CFB "off" for extension ' + ext); + astProxy.proxyLogic.evtExtenCfbChanged(ext, false); + } + } catch (err) { logger.error(IDLOG, err.stack); } }, diff --git a/lib/proxy_logic_13/proxy_logic_13.js b/lib/proxy_logic_13/proxy_logic_13.js index db9b35f..3e30063 100644 --- a/lib/proxy_logic_13/proxy_logic_13.js +++ b/lib/proxy_logic_13/proxy_logic_13.js @@ -5637,10 +5637,11 @@ function setCfb(exten, activate, to, cb) { activate: activate, val: to }, function (err) { - - cb(err); - if (err === null) { - evtExtenCfbChanged(exten, activate, to); + if (err) { + cb(err); + } else { + // Update the callforward on busy status of the extension + getCfbExten(exten)(cb); } }); @@ -10287,6 +10288,8 @@ exports.hangupConversation = hangupConversation; exports.evtNewExternalCall = evtNewExternalCall; exports.pickupConversation = pickupConversation; exports.evtExtenDndChanged = evtExtenDndChanged; +exports.evtExtenCfuChanged = evtExtenCfuChanged; +exports.evtExtenCfbChanged = evtExtenCfbChanged; exports.muteUserMeetmeConf = muteUserMeetmeConf; exports.hangupMainExtension = hangupMainExtension; exports.evtConversationUnhold = evtConversationUnhold;