Skip to content

Commit

Permalink
Merge pull request #14 from nethesis/presence-errors
Browse files Browse the repository at this point in the history
Enhance extensions presence set

nethesis/dev#6211
  • Loading branch information
Sebastian authored Jul 10, 2023
2 parents ad43eef + 62bac03 commit b50151c
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 67 deletions.
2 changes: 1 addition & 1 deletion lib/plugins_command_13/cfSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins_command_13/cfVmSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins_command_13/cfbSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins_command_13/cfbVmSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins_command_13/cfuSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins_command_13/cfuVmSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
64 changes: 29 additions & 35 deletions lib/plugins_command_13/dndSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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._
*
Expand Down Expand Up @@ -55,7 +54,6 @@ var IDLOG = '[dndSet]';
* @static
*/
var dndSet = {

/**
* Execute asterisk action to set the DND status.
*
Expand All @@ -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);
}
Expand All @@ -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]) {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins_command_13/robSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
36 changes: 35 additions & 1 deletion lib/plugins_event_13/newexten.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
Expand Down
56 changes: 32 additions & 24 deletions lib/proxy_logic_13/proxy_logic_13.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -5325,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
Expand All @@ -5347,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 {
Expand Down Expand Up @@ -5594,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);
}
});

Expand Down Expand Up @@ -5638,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);
}
});

Expand Down Expand Up @@ -5729,9 +5729,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);
}
});

Expand Down Expand Up @@ -5773,9 +5775,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);
}
});

Expand Down Expand Up @@ -5818,9 +5822,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);
}
});

Expand Down Expand Up @@ -10282,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;
Expand Down

0 comments on commit b50151c

Please sign in to comment.