diff --git a/process/IncomingCallExecutor_lib/process.js b/process/IncomingCallExecutor_lib/process.js index 36a343b206de6eb40fc8fd40f41ce6936f626dc2..a1bff008b17d95cdbdd4d4cc47c06fb47f62b34e 100644 --- a/process/IncomingCallExecutor_lib/process.js +++ b/process/IncomingCallExecutor_lib/process.js @@ -55,6 +55,8 @@ function IncomingCallExecutor(pCallData) //key-value pairs of callstates-functions this._handlerFunctions = {}; + + this.notificationContentId = null; } @@ -163,20 +165,21 @@ IncomingCallExecutor.prototype.logData = function() }; /** - * helper function that will log different callData and collected data to standard-output - * The function does not specify any module, importance or else - * Needed for live-analytics of problems and errors. + * returns a basic configuration for phonecall-notifications + * + * @param {String} pUserName user-name (which is NOT the login but the internal id of a userobject) + * + * @return {Object} notification config as it is created in the notification.createConfig()-method * - * @return undefined */ IncomingCallExecutor.prototype.getNotificationBaseConfig = function(pUserName) { - if (!pUserName) + if (!pUserName || !this.notificationContentId) return null; var notificationConfig = notification.createConfig() .addUserWithId(pUserName) - .contentId(this.callData.callId)//group all notifications of one call together + .contentId(this.notificationContentId)//group all notifications of one call together .notificationType("_____SYSTEM_NOTIFICATION_PHONECALL"); return notificationConfig; diff --git a/process/ctiServerEvents/process.js b/process/ctiServerEvents/process.js index 896d6984593a3c2f79bd603f8db0a4932977b1b3..d343349643afa3050767b565d60c94e1dc28e7bb 100644 --- a/process/ctiServerEvents/process.js +++ b/process/ctiServerEvents/process.js @@ -32,7 +32,7 @@ var ringingHandlerFn = function() vals.push(affectedContactId); } db.insertData("AB_CTILOG", cols, null, vals); - + this.notificationContentId = vals[0]; if (this.callData.isIncomingCall) { @@ -75,7 +75,13 @@ var talkingHandlerFn = function() { var cols = ["DATE_EDIT", "ANSWERMODE"]; var vals = [datetime.date(), $KeywordRegistry.callAnswerMode$accepted()]; - db.updateData("AB_CTILOG", cols, null, vals, SqlCondition.begin().andPrepare("AB_CTILOG.CALLID", this.callData.callId).build()); + + var newestCtiLogId = _getNewestCtiLogId(this.callData.callId); + if (newestCtiLogId) + { + this.notificationContentId = newestCtiLogId;//currently not used but you never know + db.updateData("AB_CTILOG", cols, null, vals, newWhere("AB_CTILOG.AB_CTILOGID", newestCtiLogId).buildCondition()); + } //do not notify here since the user _should_ know when he accepts a call }; @@ -98,8 +104,13 @@ var disconnectingHandlerFn = function() cols.push("ANSWERMODE"); vals.push($KeywordRegistry.callAnswerMode$missed()); } - db.updateData("AB_CTILOG", cols, null, vals, sqlCond.build()); - + var newestCtiLogId = _getNewestCtiLogId(this.callData.callId); + if (newestCtiLogId) + { + this.notificationContentId = newestCtiLogId; + db.updateData("AB_CTILOG", cols, null, vals, newWhere("AB_CTILOG.AB_CTILOGID", newestCtiLogId).buildCondition()); + } + //do not notify the user when the call is outgoing since the user knows when he/she does initiate a call if (!this.callData.isIncomingCall) return null; @@ -160,6 +171,18 @@ var disconnectingHandlerFn = function() return null; }; +function _getNewestCtiLogId(pCallid) +{ + //get the newewst ctilogid for a given callid since the callid may not be unique in a telephon systems + //therefor sort descending by DATE_NEW and return that value + var ctiLogId = newSelect("AB_CTILOG.AB_CTILOGID") + .from("AB_CTILOG") + .where("AB_CTILOG.CALLID", pCallid) + .orderBy("AB_CTILOG.DATE_NEW desc") + .cell(); + return ctiLogId; +} + //collect all data from the various call information var callData = { action: vars.get("$local.action") @@ -178,7 +201,7 @@ var callData = { //callData.localAddress = "PJSIP/xyzExample"; var ic = new IncomingCallExecutor(callData); -//ic.logData(); +ic.logData(); ic.setHandlerRinging(ringingHandlerFn); ic.setHandlerTalking(talkingHandlerFn); ic.setHandlerDisconnect(disconnectingHandlerFn);