Built motion from commit ae138b72.|2.6.28
[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 _0x0f98=['dnid','uniqueid','calleridname','callerid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','createSquareReport','catch','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','arg_1','close','timeout','evtHangup','hangup','find','handleNotFound','production','handleUnpublished','initialize','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20VOICE\x20IS\x20DISABLED','then','getAll','finally','connection','lodash','syncho','util','../../config/environment','../../config/logger','agi','../../config/license/util','./rpc','./project','./events','projectUpdate','nextTick','error','stack','deleted','splice','push','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','name','[%s]\x20%s','message','[ERROR]\x20%s','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s'];(function(_0xa25ed,_0x3b4a96){var _0x170865=function(_0x5b8229){while(--_0x5b8229){_0xa25ed['push'](_0xa25ed['shift']());}};_0x170865(++_0x3b4a96);}(_0x0f98,0x115));var _0x80f9=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x0f98[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0x80f9('0x0'));var syncho=require(_0x80f9('0x1'));var util=require(_0x80f9('0x2'));var config=require(_0x80f9('0x3'));var logger=require(_0x80f9('0x4'))(_0x80f9('0x5'));var utilLicense=require(_0x80f9('0x6'));var rpc=require(_0x80f9('0x7'));var Project=require(_0x80f9('0x8'));var AGIEmitter=require(_0x80f9('0x9'))['EventEmitter'];var projects=[];config[_0x80f9('0x5')]=_['defaults'](config[_0x80f9('0x5')],{'ip':'127.0.0.1','port':0x11dd});AGIEmitter['on'](_0x80f9('0xa'),projectUpdateHandler);function connectionHandler(_0x41efab){process[_0x80f9('0xb')](function(){syncho(function(){try{setChannelVariables(_0x41efab);agiHandler(_0x41efab);}catch(_0x491c4c){logger[_0x80f9('0xc')](_0x491c4c[_0x80f9('0xd')]);}});});}function projectUpdateHandler(_0x1afdc8){try{var _0x5eddf5=_['findIndex'](projects,['id',_0x1afdc8['id']]);if(_0x5eddf5>-0x1){if(_0x1afdc8[_0x80f9('0xe')]===!![]){projects[_0x80f9('0xf')](_0x5eddf5,0x1);}else{projects[_0x5eddf5]=_0x1afdc8;}}else{projects[_0x80f9('0x10')](_0x1afdc8);}}catch(_0x10983d){logger[_0x80f9('0xc')](_0x10983d['stack']);}}function listeningHandler(){console[_0x80f9('0x11')](_0x80f9('0x12'),config['agi'][_0x80f9('0x13')]);logger[_0x80f9('0x14')](util[_0x80f9('0x15')](_0x80f9('0x16'),config['agi']['ip'],config[_0x80f9('0x5')][_0x80f9('0x13')]));}function errorHandler(_0x28a2dc){if(_0x28a2dc&&_0x28a2dc[_0x80f9('0x17')]&&_0x28a2dc['message']){logger[_0x80f9('0xc')](util[_0x80f9('0x15')](_0x80f9('0x18'),_0x28a2dc['name'],_0x28a2dc[_0x80f9('0x19')]));}else{logger[_0x80f9('0xc')](util['format'](_0x80f9('0x1a'),_0x28a2dc[_0x80f9('0xd')]));}}function closeHandler(){logger[_0x80f9('0x14')](util['format'](_0x80f9('0x1b'),this['arg_1'],this['calleridname'],this['callerid'],this[_0x80f9('0x1c')],this[_0x80f9('0x1d')]));try{createSquareReport(this);}catch(_0x63297f){logger[_0x80f9('0xc')](_0x63297f['stack']);}}function timeoutHandler(){logger[_0x80f9('0x14')](util[_0x80f9('0x15')]('[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this['arg_1'],this[_0x80f9('0x1e')],this[_0x80f9('0x1f')],this[_0x80f9('0x1c')],this[_0x80f9('0x1d')]));}function hangupHandler(){logger[_0x80f9('0x14')](util[_0x80f9('0x15')](_0x80f9('0x20'),this['arg_1'],this[_0x80f9('0x1e')],this[_0x80f9('0x1f')],this[_0x80f9('0x1c')],this[_0x80f9('0x1d')]));this['evtHangup']=!![];}function createSquareReport(_0x201c6f,_0x5112c5){rpc[_0x80f9('0x21')](_0x201c6f)['then'](function(_0x1f6dff){if(_0x5112c5){_0x5112c5(null,_0x1f6dff);}})[_0x80f9('0x22')](function(_0x3e296b){if(_0x5112c5){_0x5112c5(null,_0x3e296b);}});}function setChannelVariables(_0x1777d8){for(var _0x3cc06a in _0x1777d8){if(_0x1777d8['hasOwnProperty'](_0x3cc06a)){if(_0x3cc06a[_0x80f9('0x23')](_0x80f9('0x24'))===0x0){_0x1777d8[_0x3cc06a[_0x80f9('0x25')](0x4)]=_0x1777d8[_0x3cc06a];delete _0x1777d8[_0x3cc06a];}}}}function agiHandler(_0x2dd9ab){logger[_0x80f9('0x26')](_0x80f9('0x27'),JSON[_0x80f9('0x28')](_0x2dd9ab,null,0x2));logger['info'](util[_0x80f9('0x15')](_0x80f9('0x29'),_0x2dd9ab[_0x80f9('0x2a')],_0x2dd9ab[_0x80f9('0x1e')],_0x2dd9ab[_0x80f9('0x1f')],_0x2dd9ab[_0x80f9('0x1c')],_0x2dd9ab[_0x80f9('0x1d')]));_0x2dd9ab['on']('error',errorHandler);_0x2dd9ab['on'](_0x80f9('0x2b'),closeHandler);_0x2dd9ab['on'](_0x80f9('0x2c'),timeoutHandler);_0x2dd9ab[_0x80f9('0x2d')]=![];_0x2dd9ab['on'](_0x80f9('0x2e'),hangupHandler);var _0x59d530=_[_0x80f9('0x2f')](projects,[_0x80f9('0x17'),_0x2dd9ab[_0x80f9('0x2a')]]);if(!_0x59d530)return Project[_0x80f9('0x30')](_0x2dd9ab);if(!_0x59d530[_0x80f9('0x31')])return Project[_0x80f9('0x32')](_0x2dd9ab);return Project[_0x80f9('0x33')](_0x59d530,_0x2dd9ab);}function main(){var _0x33893e;return utilLicense[_0x80f9('0x34')]()['then'](function(_0x2aad0f){if(!_0x2aad0f)return;if(_0x2aad0f[_0x80f9('0x35')]){if(_0x2aad0f['callysquare']&&_0x2aad0f[_0x80f9('0x36')]>0x0){logger[_0x80f9('0x14')](util['format'](_0x80f9('0x37'),_0x2aad0f[_0x80f9('0x36')]));_0x33893e=_0x2aad0f['callysquare'];}else{logger[_0x80f9('0x14')]('[LICENSE]\x20CHANNELS:\x20UNLIMITED');}}else{logger[_0x80f9('0x14')](_0x80f9('0x38'));_0x33893e=-0x1;}})[_0x80f9('0x39')](function(){return Project[_0x80f9('0x3a')]();})[_0x80f9('0x39')](function(_0x506fcb){projects=_0x506fcb;return;})['catch'](function(_0x3dabc0){logger[_0x80f9('0xc')]('[LICENSE]',_0x3dabc0['stack']);})[_0x80f9('0x3b')](function(){var _0x3b71ba=require('./server')(config[_0x80f9('0x5')][_0x80f9('0x13')],config[_0x80f9('0x5')]['ip'],_0x33893e);_0x3b71ba['on'](_0x80f9('0xc'),errorHandler);_0x3b71ba['on']('listening',listeningHandler);_0x3b71ba['on'](_0x80f9('0x3c'),connectionHandler);_0x3b71ba['on'](_0x80f9('0x2b'),closeHandler);});}main();