a95d6fcada1cafe6a6a30001a818bedbeb154b5e
[motion2.git] / server / services / agi / index.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x39de=['name','[ERROR]\x20%s','info','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','calleridname','callerid','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','dnid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','createSquareReport','then','indexOf','agi_','substring','debug','variables','stringify','[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','close','hangup','handleNotFound','handleUnpublished','initialize','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20VOICE\x20IS\x20DISABLED','getAll','catch','finally','./server','listening','connection','lodash','util','../../config/environment','../../config/logger','agi','../../config/license/util','./project','EventEmitter','defaults','nextTick','error','stack','deleted','splice','push','env','production','log','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','host.docker.internal','port','[%s]\x20%s'];(function(_0x5ce8e3,_0x35dfe2){var _0x8c9398=function(_0x3fd694){while(--_0x3fd694){_0x5ce8e3['push'](_0x5ce8e3['shift']());}};_0x8c9398(++_0x35dfe2);}(_0x39de,0x115));var _0xe39d=function(_0x2bf8ac,_0x4226be){_0x2bf8ac=_0x2bf8ac-0x0;var _0x3ef094=_0x39de[_0x2bf8ac];return _0x3ef094;};'use strict';var _=require(_0xe39d('0x0'));var syncho=require('syncho');var util=require(_0xe39d('0x1'));var config=require(_0xe39d('0x2'));var logger=require(_0xe39d('0x3'))(_0xe39d('0x4'));var utilLicense=require(_0xe39d('0x5'));var rpc=require('./rpc');var Project=require(_0xe39d('0x6'));var AGIEmitter=require('./events')[_0xe39d('0x7')];var projects=[];config[_0xe39d('0x4')]=_[_0xe39d('0x8')](config['agi'],{'ip':'127.0.0.1','port':0x11dd});AGIEmitter['on']('projectUpdate',projectUpdateHandler);function connectionHandler(_0x170e50){process[_0xe39d('0x9')](function(){syncho(function(){try{setChannelVariables(_0x170e50);agiHandler(_0x170e50);}catch(_0x30509c){logger[_0xe39d('0xa')](_0x30509c[_0xe39d('0xb')]);}});});}function projectUpdateHandler(_0x4c4250){try{var _0x5883e2=_['findIndex'](projects,['id',_0x4c4250['id']]);if(_0x5883e2>-0x1){if(_0x4c4250[_0xe39d('0xc')]===!![]){projects[_0xe39d('0xd')](_0x5883e2,0x1);}else{projects[_0x5883e2]=_0x4c4250;}}else{projects[_0xe39d('0xe')](_0x4c4250);}}catch(_0x105f00){logger[_0xe39d('0xa')](_0x105f00[_0xe39d('0xb')]);}}function listeningHandler(){var _0x1c79b0=config[_0xe39d('0xf')]===_0xe39d('0x10')||![];console[_0xe39d('0x11')]('Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!',config[_0xe39d('0x4')]['port']);logger['info'](util[_0xe39d('0x12')](_0xe39d('0x13'),_0x1c79b0?config[_0xe39d('0x4')]['ip']:_0xe39d('0x14'),config[_0xe39d('0x4')][_0xe39d('0x15')]));}function errorHandler(_0x458f25){if(_0x458f25&&_0x458f25['name']&&_0x458f25['message']){logger[_0xe39d('0xa')](util[_0xe39d('0x12')](_0xe39d('0x16'),_0x458f25[_0xe39d('0x17')],_0x458f25['message']));}else{logger[_0xe39d('0xa')](util[_0xe39d('0x12')](_0xe39d('0x18'),_0x458f25[_0xe39d('0xb')]));}}function closeHandler(){logger[_0xe39d('0x19')](util[_0xe39d('0x12')](_0xe39d('0x1a'),this[_0xe39d('0x1b')],this[_0xe39d('0x1c')],this[_0xe39d('0x1d')],this['dnid'],this[_0xe39d('0x1e')]));try{createSquareReport(this);}catch(_0x1b7f5b){logger[_0xe39d('0xa')](_0x1b7f5b[_0xe39d('0xb')]);}}function timeoutHandler(){logger[_0xe39d('0x19')](util[_0xe39d('0x12')](_0xe39d('0x1f'),this[_0xe39d('0x1b')],this[_0xe39d('0x1c')],this['callerid'],this[_0xe39d('0x20')],this[_0xe39d('0x1e')]));}function hangupHandler(){logger[_0xe39d('0x19')](util[_0xe39d('0x12')](_0xe39d('0x21'),this[_0xe39d('0x1b')],this['calleridname'],this[_0xe39d('0x1d')],this['dnid'],this[_0xe39d('0x1e')]));this[_0xe39d('0x22')]=!![];}function createSquareReport(_0x5e83c2,_0x4fd769){rpc[_0xe39d('0x23')](_0x5e83c2)[_0xe39d('0x24')](function(_0x27135f){if(_0x4fd769){_0x4fd769(null,_0x27135f);}})['catch'](function(_0x4c56e0){if(_0x4fd769){_0x4fd769(null,_0x4c56e0);}});}function setChannelVariables(_0x5988bc){for(var _0x28dc36 in _0x5988bc){if(_0x5988bc['hasOwnProperty'](_0x28dc36)){if(_0x28dc36[_0xe39d('0x25')](_0xe39d('0x26'))===0x0){_0x5988bc[_0x28dc36[_0xe39d('0x27')](0x4)]=_0x5988bc[_0x28dc36];delete _0x5988bc[_0x28dc36];}}}}function agiHandler(_0x3904f1){logger[_0xe39d('0x28')](_0xe39d('0x29'),JSON[_0xe39d('0x2a')](_0x3904f1,null,0x2));logger[_0xe39d('0x19')](util[_0xe39d('0x12')](_0xe39d('0x2b'),_0x3904f1[_0xe39d('0x1b')],_0x3904f1[_0xe39d('0x1c')],_0x3904f1['callerid'],_0x3904f1[_0xe39d('0x20')],_0x3904f1['uniqueid']));_0x3904f1['on'](_0xe39d('0xa'),errorHandler);_0x3904f1['on'](_0xe39d('0x2c'),closeHandler);_0x3904f1['on']('timeout',timeoutHandler);_0x3904f1['evtHangup']=![];_0x3904f1['on'](_0xe39d('0x2d'),hangupHandler);var _0x1a6efc=_['find'](projects,[_0xe39d('0x17'),_0x3904f1[_0xe39d('0x1b')]]);if(!_0x1a6efc)return Project[_0xe39d('0x2e')](_0x3904f1);if(!_0x1a6efc[_0xe39d('0x10')])return Project[_0xe39d('0x2f')](_0x3904f1);return Project[_0xe39d('0x30')](_0x1a6efc,_0x3904f1);}function main(){var _0xc13783;return utilLicense[_0xe39d('0x31')]()[_0xe39d('0x24')](function(_0x3b0369){if(!_0x3b0369)return;if(_0x3b0369[_0xe39d('0x32')]){if(_0x3b0369[_0xe39d('0x33')]&&_0x3b0369['callysquare']>0x0){logger[_0xe39d('0x19')](util[_0xe39d('0x12')](_0xe39d('0x34'),_0x3b0369[_0xe39d('0x33')]));_0xc13783=_0x3b0369[_0xe39d('0x33')];}else{logger[_0xe39d('0x19')]('[LICENSE]\x20CHANNELS:\x20UNLIMITED');}}else{logger[_0xe39d('0x19')](_0xe39d('0x35'));_0xc13783=-0x1;}})[_0xe39d('0x24')](function(){return Project[_0xe39d('0x36')]();})[_0xe39d('0x24')](function(_0x2d3e90){projects=_0x2d3e90;return;})[_0xe39d('0x37')](function(_0x256639){logger[_0xe39d('0xa')]('[LICENSE]',_0x256639[_0xe39d('0xb')]);})[_0xe39d('0x38')](function(){var _0xc9bb90=require(_0xe39d('0x39'))(config['agi'][_0xe39d('0x15')],config['agi']['ip'],_0xc13783);_0xc9bb90['on'](_0xe39d('0xa'),errorHandler);_0xc9bb90['on'](_0xe39d('0x3a'),listeningHandler);_0xc9bb90['on'](_0xe39d('0x3b'),connectionHandler);_0xc9bb90['on'](_0xe39d('0x2c'),closeHandler);});}main();