260cc85417f35981fe37884b09c65b6218bf6ab6
[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 _0x1e19=['../../config/environment','agi','../../config/license/util','./rpc','./project','EventEmitter','defaults','127.0.0.1','projectUpdate','nextTick','stack','findIndex','splice','error','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','format','name','message','[ERROR]\x20%s','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','calleridname','callerid','uniqueid','info','[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','catch','hasOwnProperty','indexOf','agi_','substring','variables','stringify','close','timeout','hangup','handleNotFound','production','initialize','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20VOICE\x20IS\x20DISABLED','./server','port','listening','connection','lodash'];(function(_0x466e89,_0x237ae3){var _0x580986=function(_0x1ca46d){while(--_0x1ca46d){_0x466e89['push'](_0x466e89['shift']());}};_0x580986(++_0x237ae3);}(_0x1e19,0xa4));var _0x91e1=function(_0x169591,_0x94ab12){_0x169591=_0x169591-0x0;var _0x2cb673=_0x1e19[_0x169591];return _0x2cb673;};'use strict';var _=require(_0x91e1('0x0'));var syncho=require('syncho');var util=require('util');var config=require(_0x91e1('0x1'));var logger=require('../../config/logger')(_0x91e1('0x2'));var utilLicense=require(_0x91e1('0x3'));var rpc=require(_0x91e1('0x4'));var Project=require(_0x91e1('0x5'));var AGIEmitter=require('./events')[_0x91e1('0x6')];var projects=[];config[_0x91e1('0x2')]=_[_0x91e1('0x7')](config[_0x91e1('0x2')],{'ip':_0x91e1('0x8'),'port':0x11dd});AGIEmitter['on'](_0x91e1('0x9'),projectUpdateHandler);function connectionHandler(_0x4452a7){process[_0x91e1('0xa')](function(){syncho(function(){try{setChannelVariables(_0x4452a7);agiHandler(_0x4452a7);}catch(_0x19e56b){logger['error'](_0x19e56b[_0x91e1('0xb')]);}});});}function projectUpdateHandler(_0xfb6ab5){try{var _0x5f7f05=_[_0x91e1('0xc')](projects,['id',_0xfb6ab5['id']]);if(_0x5f7f05>-0x1){if(_0xfb6ab5['deleted']===!![]){projects[_0x91e1('0xd')](_0x5f7f05,0x1);}else{projects[_0x5f7f05]=_0xfb6ab5;}}else{projects['push'](_0xfb6ab5);}}catch(_0x324e95){logger[_0x91e1('0xe')](_0x324e95[_0x91e1('0xb')]);}}function listeningHandler(){console[_0x91e1('0xf')](_0x91e1('0x10'),config[_0x91e1('0x2')]['port']);logger['info'](util[_0x91e1('0x11')]('[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d',config[_0x91e1('0x2')]['ip'],config[_0x91e1('0x2')]['port']));}function errorHandler(_0x79029a){if(_0x79029a&&_0x79029a[_0x91e1('0x12')]&&_0x79029a[_0x91e1('0x13')]){logger[_0x91e1('0xe')](util[_0x91e1('0x11')]('[%s]\x20%s',_0x79029a[_0x91e1('0x12')],_0x79029a[_0x91e1('0x13')]));}else{logger['error'](util[_0x91e1('0x11')](_0x91e1('0x14'),_0x79029a[_0x91e1('0xb')]));}}function closeHandler(){logger['info'](util[_0x91e1('0x11')](_0x91e1('0x15'),this[_0x91e1('0x16')],this[_0x91e1('0x17')],this[_0x91e1('0x18')],this['dnid'],this[_0x91e1('0x19')]));try{createSquareReport(this);}catch(_0x572239){logger[_0x91e1('0xe')](_0x572239['stack']);}}function timeoutHandler(){logger[_0x91e1('0x1a')](util['format'](_0x91e1('0x1b'),this[_0x91e1('0x16')],this[_0x91e1('0x17')],this['callerid'],this[_0x91e1('0x1c')],this[_0x91e1('0x19')]));}function hangupHandler(){logger[_0x91e1('0x1a')](util[_0x91e1('0x11')](_0x91e1('0x1d'),this['arg_1'],this['calleridname'],this[_0x91e1('0x18')],this[_0x91e1('0x1c')],this[_0x91e1('0x19')]));this[_0x91e1('0x1e')]=!![];}function createSquareReport(_0x4cb0b1,_0x24a85a){rpc[_0x91e1('0x1f')](_0x4cb0b1)[_0x91e1('0x20')](function(_0x54eee3){if(_0x24a85a){_0x24a85a(null,_0x54eee3);}})[_0x91e1('0x21')](function(_0x86b008){if(_0x24a85a){_0x24a85a(null,_0x86b008);}});}function setChannelVariables(_0x53ded9){for(var _0x425ba4 in _0x53ded9){if(_0x53ded9[_0x91e1('0x22')](_0x425ba4)){if(_0x425ba4[_0x91e1('0x23')](_0x91e1('0x24'))===0x0){_0x53ded9[_0x425ba4[_0x91e1('0x25')](0x4)]=_0x53ded9[_0x425ba4];delete _0x53ded9[_0x425ba4];}}}}function agiHandler(_0x3204a8){logger['debug'](_0x91e1('0x26'),JSON[_0x91e1('0x27')](_0x3204a8,null,0x2));logger['info'](util['format']('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x3204a8['arg_1'],_0x3204a8[_0x91e1('0x17')],_0x3204a8[_0x91e1('0x18')],_0x3204a8[_0x91e1('0x1c')],_0x3204a8['uniqueid']));_0x3204a8['on'](_0x91e1('0xe'),errorHandler);_0x3204a8['on'](_0x91e1('0x28'),closeHandler);_0x3204a8['on'](_0x91e1('0x29'),timeoutHandler);_0x3204a8[_0x91e1('0x1e')]=![];_0x3204a8['on'](_0x91e1('0x2a'),hangupHandler);var _0xe51a1b=_['find'](projects,[_0x91e1('0x12'),_0x3204a8[_0x91e1('0x16')]]);if(!_0xe51a1b)return Project[_0x91e1('0x2b')](_0x3204a8);if(!_0xe51a1b[_0x91e1('0x2c')])return Project['handleUnpublished'](_0x3204a8);return Project[_0x91e1('0x2d')](_0xe51a1b,_0x3204a8);}function main(){var _0x850ecc;return utilLicense[_0x91e1('0x2e')]()[_0x91e1('0x20')](function(_0x3d195a){if(!_0x3d195a)return;if(_0x3d195a[_0x91e1('0x2f')]){if(_0x3d195a[_0x91e1('0x30')]&&_0x3d195a[_0x91e1('0x30')]>0x0){logger[_0x91e1('0x1a')](util['format'](_0x91e1('0x31'),_0x3d195a[_0x91e1('0x30')]));_0x850ecc=_0x3d195a[_0x91e1('0x30')];}else{logger['info']('[LICENSE]\x20CHANNELS:\x20UNLIMITED');}}else{logger[_0x91e1('0x1a')](_0x91e1('0x32'));_0x850ecc=-0x1;}})['then'](function(){return Project['getAll']();})[_0x91e1('0x20')](function(_0x33d167){projects=_0x33d167;return;})[_0x91e1('0x21')](function(_0x43559f){logger[_0x91e1('0xe')]('[LICENSE]',_0x43559f[_0x91e1('0xb')]);})['finally'](function(){var _0x28dda0=require(_0x91e1('0x33'))(config['agi'][_0x91e1('0x34')],config[_0x91e1('0x2')]['ip'],_0x850ecc);_0x28dda0['on'](_0x91e1('0xe'),errorHandler);_0x28dda0['on'](_0x91e1('0x35'),listeningHandler);_0x28dda0['on'](_0x91e1('0x36'),connectionHandler);_0x28dda0['on']('close',closeHandler);});}main();