Built motion from commit ff78e754.|2.6.29
[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 _0x7a9d=['[ERROR]\x20%s','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','calleridname','callerid','dnid','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','createSquareReport','then','catch','hasOwnProperty','indexOf','agi_','substring','variables','stringify','info','[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','close','timeout','find','production','handleUnpublished','initialize','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','getAll','[LICENSE]','finally','./server','listening','connection','syncho','../../config/environment','../../config/logger','../../config/license/util','./rpc','./project','EventEmitter','agi','defaults','127.0.0.1','projectUpdate','nextTick','error','stack','findIndex','deleted','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','port','name','message','[%s]\x20%s'];(function(_0x3a1ca6,_0x2d40b5){var _0x1dfd64=function(_0x4d1a2c){while(--_0x4d1a2c){_0x3a1ca6['push'](_0x3a1ca6['shift']());}};_0x1dfd64(++_0x2d40b5);}(_0x7a9d,0xe4));var _0xd7a9=function(_0x2a3e51,_0x39f57e){_0x2a3e51=_0x2a3e51-0x0;var _0x1998ad=_0x7a9d[_0x2a3e51];return _0x1998ad;};'use strict';var _=require('lodash');var syncho=require(_0xd7a9('0x0'));var util=require('util');var config=require(_0xd7a9('0x1'));var logger=require(_0xd7a9('0x2'))('agi');var utilLicense=require(_0xd7a9('0x3'));var rpc=require(_0xd7a9('0x4'));var Project=require(_0xd7a9('0x5'));var AGIEmitter=require('./events')[_0xd7a9('0x6')];var projects=[];config[_0xd7a9('0x7')]=_[_0xd7a9('0x8')](config[_0xd7a9('0x7')],{'ip':_0xd7a9('0x9'),'port':0x11dd});AGIEmitter['on'](_0xd7a9('0xa'),projectUpdateHandler);function connectionHandler(_0x522bce){process[_0xd7a9('0xb')](function(){syncho(function(){try{setChannelVariables(_0x522bce);agiHandler(_0x522bce);}catch(_0x11121a){logger[_0xd7a9('0xc')](_0x11121a[_0xd7a9('0xd')]);}});});}function projectUpdateHandler(_0x279d7a){try{var _0x26220c=_[_0xd7a9('0xe')](projects,['id',_0x279d7a['id']]);if(_0x26220c>-0x1){if(_0x279d7a[_0xd7a9('0xf')]===!![]){projects['splice'](_0x26220c,0x1);}else{projects[_0x26220c]=_0x279d7a;}}else{projects['push'](_0x279d7a);}}catch(_0x2c15ed){logger['error'](_0x2c15ed[_0xd7a9('0xd')]);}}function listeningHandler(){console[_0xd7a9('0x10')](_0xd7a9('0x11'),config[_0xd7a9('0x7')]['port']);logger['info'](util[_0xd7a9('0x12')](_0xd7a9('0x13'),config['agi']['ip'],config[_0xd7a9('0x7')][_0xd7a9('0x14')]));}function errorHandler(_0x5c5945){if(_0x5c5945&&_0x5c5945[_0xd7a9('0x15')]&&_0x5c5945[_0xd7a9('0x16')]){logger[_0xd7a9('0xc')](util[_0xd7a9('0x12')](_0xd7a9('0x17'),_0x5c5945[_0xd7a9('0x15')],_0x5c5945['message']));}else{logger[_0xd7a9('0xc')](util[_0xd7a9('0x12')](_0xd7a9('0x18'),_0x5c5945[_0xd7a9('0xd')]));}}function closeHandler(){logger['info'](util[_0xd7a9('0x12')](_0xd7a9('0x19'),this['arg_1'],this[_0xd7a9('0x1a')],this[_0xd7a9('0x1b')],this[_0xd7a9('0x1c')],this[_0xd7a9('0x1d')]));try{createSquareReport(this);}catch(_0x51015a){logger['error'](_0x51015a[_0xd7a9('0xd')]);}}function timeoutHandler(){logger['info'](util[_0xd7a9('0x12')](_0xd7a9('0x1e'),this[_0xd7a9('0x1f')],this[_0xd7a9('0x1a')],this[_0xd7a9('0x1b')],this[_0xd7a9('0x1c')],this['uniqueid']));}function hangupHandler(){logger['info'](util[_0xd7a9('0x12')](_0xd7a9('0x20'),this[_0xd7a9('0x1f')],this[_0xd7a9('0x1a')],this['callerid'],this[_0xd7a9('0x1c')],this[_0xd7a9('0x1d')]));this[_0xd7a9('0x21')]=!![];}function createSquareReport(_0x3b197c,_0x4e63ce){rpc[_0xd7a9('0x22')](_0x3b197c)[_0xd7a9('0x23')](function(_0x25841a){if(_0x4e63ce){_0x4e63ce(null,_0x25841a);}})[_0xd7a9('0x24')](function(_0x43f89f){if(_0x4e63ce){_0x4e63ce(null,_0x43f89f);}});}function setChannelVariables(_0x343175){for(var _0x19bb9d in _0x343175){if(_0x343175[_0xd7a9('0x25')](_0x19bb9d)){if(_0x19bb9d[_0xd7a9('0x26')](_0xd7a9('0x27'))===0x0){_0x343175[_0x19bb9d[_0xd7a9('0x28')](0x4)]=_0x343175[_0x19bb9d];delete _0x343175[_0x19bb9d];}}}}function agiHandler(_0x2f866b){logger['debug'](_0xd7a9('0x29'),JSON[_0xd7a9('0x2a')](_0x2f866b,null,0x2));logger[_0xd7a9('0x2b')](util[_0xd7a9('0x12')](_0xd7a9('0x2c'),_0x2f866b[_0xd7a9('0x1f')],_0x2f866b[_0xd7a9('0x1a')],_0x2f866b[_0xd7a9('0x1b')],_0x2f866b['dnid'],_0x2f866b[_0xd7a9('0x1d')]));_0x2f866b['on'](_0xd7a9('0xc'),errorHandler);_0x2f866b['on'](_0xd7a9('0x2d'),closeHandler);_0x2f866b['on'](_0xd7a9('0x2e'),timeoutHandler);_0x2f866b['evtHangup']=![];_0x2f866b['on']('hangup',hangupHandler);var _0x7c0517=_[_0xd7a9('0x2f')](projects,[_0xd7a9('0x15'),_0x2f866b[_0xd7a9('0x1f')]]);if(!_0x7c0517)return Project['handleNotFound'](_0x2f866b);if(!_0x7c0517[_0xd7a9('0x30')])return Project[_0xd7a9('0x31')](_0x2f866b);return Project[_0xd7a9('0x32')](_0x7c0517,_0x2f866b);}function main(){var _0x4d3402;return utilLicense[_0xd7a9('0x33')]()[_0xd7a9('0x23')](function(_0x288249){if(!_0x288249)return;if(_0x288249[_0xd7a9('0x34')]){if(_0x288249[_0xd7a9('0x35')]&&_0x288249[_0xd7a9('0x35')]>0x0){logger[_0xd7a9('0x2b')](util['format'](_0xd7a9('0x36'),_0x288249[_0xd7a9('0x35')]));_0x4d3402=_0x288249[_0xd7a9('0x35')];}else{logger[_0xd7a9('0x2b')](_0xd7a9('0x37'));}}else{logger[_0xd7a9('0x2b')](_0xd7a9('0x38'));_0x4d3402=-0x1;}})[_0xd7a9('0x23')](function(){return Project[_0xd7a9('0x39')]();})[_0xd7a9('0x23')](function(_0x5ad93e){projects=_0x5ad93e;return;})['catch'](function(_0x4eaee6){logger[_0xd7a9('0xc')](_0xd7a9('0x3a'),_0x4eaee6[_0xd7a9('0xd')]);})[_0xd7a9('0x3b')](function(){var _0x543537=require(_0xd7a9('0x3c'))(config[_0xd7a9('0x7')][_0xd7a9('0x14')],config[_0xd7a9('0x7')]['ip'],_0x4d3402);_0x543537['on'](_0xd7a9('0xc'),errorHandler);_0x543537['on'](_0xd7a9('0x3d'),listeningHandler);_0x543537['on'](_0xd7a9('0x3e'),connectionHandler);_0x543537['on'](_0xd7a9('0x2d'),closeHandler);});}main();