Built motion from commit d1eab355.|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 _0xb0c5=['getAll','[LICENSE]','./server','listening','connection','lodash','util','../../config/environment','../../config/logger','agi','../../config/license/util','./rpc','./project','./events','EventEmitter','defaults','projectUpdate','nextTick','error','stack','findIndex','deleted','splice','push','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','info','format','message','[%s]\x20%s','name','[ERROR]\x20%s','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','calleridname','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','dnid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','indexOf','agi_','substring','debug','callerid','close','timeout','evtHangup','hangup','find','handleNotFound','production','handleUnpublished','getLicense','then','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED'];(function(_0x3336fb,_0x569e2a){var _0x24a95e=function(_0x397426){while(--_0x397426){_0x3336fb['push'](_0x3336fb['shift']());}};_0x24a95e(++_0x569e2a);}(_0xb0c5,0xf1));var _0x5b0c=function(_0x5d091f,_0x457a5e){_0x5d091f=_0x5d091f-0x0;var _0x581be9=_0xb0c5[_0x5d091f];return _0x581be9;};'use strict';var _=require(_0x5b0c('0x0'));var syncho=require('syncho');var util=require(_0x5b0c('0x1'));var config=require(_0x5b0c('0x2'));var logger=require(_0x5b0c('0x3'))(_0x5b0c('0x4'));var utilLicense=require(_0x5b0c('0x5'));var rpc=require(_0x5b0c('0x6'));var Project=require(_0x5b0c('0x7'));var AGIEmitter=require(_0x5b0c('0x8'))[_0x5b0c('0x9')];var projects=[];config[_0x5b0c('0x4')]=_[_0x5b0c('0xa')](config['agi'],{'ip':'127.0.0.1','port':0x11dd});AGIEmitter['on'](_0x5b0c('0xb'),projectUpdateHandler);function connectionHandler(_0x4e64f4){process[_0x5b0c('0xc')](function(){syncho(function(){try{setChannelVariables(_0x4e64f4);agiHandler(_0x4e64f4);}catch(_0x3017a9){logger[_0x5b0c('0xd')](_0x3017a9[_0x5b0c('0xe')]);}});});}function projectUpdateHandler(_0x518893){try{var _0x5ac5c1=_[_0x5b0c('0xf')](projects,['id',_0x518893['id']]);if(_0x5ac5c1>-0x1){if(_0x518893[_0x5b0c('0x10')]===!![]){projects[_0x5b0c('0x11')](_0x5ac5c1,0x1);}else{projects[_0x5ac5c1]=_0x518893;}}else{projects[_0x5b0c('0x12')](_0x518893);}}catch(_0x3615e5){logger[_0x5b0c('0xd')](_0x3615e5[_0x5b0c('0xe')]);}}function listeningHandler(){console[_0x5b0c('0x13')](_0x5b0c('0x14'),config[_0x5b0c('0x4')][_0x5b0c('0x15')]);logger[_0x5b0c('0x16')](util[_0x5b0c('0x17')]('[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d',config['agi']['ip'],config['agi'][_0x5b0c('0x15')]));}function errorHandler(_0x38d453){if(_0x38d453&&_0x38d453['name']&&_0x38d453[_0x5b0c('0x18')]){logger['error'](util['format'](_0x5b0c('0x19'),_0x38d453[_0x5b0c('0x1a')],_0x38d453[_0x5b0c('0x18')]));}else{logger['error'](util[_0x5b0c('0x17')](_0x5b0c('0x1b'),_0x38d453[_0x5b0c('0xe')]));}}function closeHandler(){logger[_0x5b0c('0x16')](util[_0x5b0c('0x17')](_0x5b0c('0x1c'),this['arg_1'],this[_0x5b0c('0x1d')],this['callerid'],this['dnid'],this[_0x5b0c('0x1e')]));try{createSquareReport(this);}catch(_0x3b61c2){logger['error'](_0x3b61c2['stack']);}}function timeoutHandler(){logger['info'](util[_0x5b0c('0x17')](_0x5b0c('0x1f'),this[_0x5b0c('0x20')],this[_0x5b0c('0x1d')],this['callerid'],this[_0x5b0c('0x21')],this[_0x5b0c('0x1e')]));}function hangupHandler(){logger[_0x5b0c('0x16')](util[_0x5b0c('0x17')](_0x5b0c('0x22'),this[_0x5b0c('0x20')],this['calleridname'],this['callerid'],this['dnid'],this[_0x5b0c('0x1e')]));this['evtHangup']=!![];}function createSquareReport(_0x47fa60,_0x2bee32){rpc['createSquareReport'](_0x47fa60)['then'](function(_0x22086a){if(_0x2bee32){_0x2bee32(null,_0x22086a);}})['catch'](function(_0x25c634){if(_0x2bee32){_0x2bee32(null,_0x25c634);}});}function setChannelVariables(_0x49b55c){for(var _0x200e23 in _0x49b55c){if(_0x49b55c['hasOwnProperty'](_0x200e23)){if(_0x200e23[_0x5b0c('0x23')](_0x5b0c('0x24'))===0x0){_0x49b55c[_0x200e23[_0x5b0c('0x25')](0x4)]=_0x49b55c[_0x200e23];delete _0x49b55c[_0x200e23];}}}}function agiHandler(_0x164b27){logger[_0x5b0c('0x26')]('variables',JSON['stringify'](_0x164b27,null,0x2));logger[_0x5b0c('0x16')](util[_0x5b0c('0x17')]('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x164b27['arg_1'],_0x164b27[_0x5b0c('0x1d')],_0x164b27[_0x5b0c('0x27')],_0x164b27[_0x5b0c('0x21')],_0x164b27[_0x5b0c('0x1e')]));_0x164b27['on'](_0x5b0c('0xd'),errorHandler);_0x164b27['on'](_0x5b0c('0x28'),closeHandler);_0x164b27['on'](_0x5b0c('0x29'),timeoutHandler);_0x164b27[_0x5b0c('0x2a')]=![];_0x164b27['on'](_0x5b0c('0x2b'),hangupHandler);var _0x3880a2=_[_0x5b0c('0x2c')](projects,[_0x5b0c('0x1a'),_0x164b27[_0x5b0c('0x20')]]);if(!_0x3880a2)return Project[_0x5b0c('0x2d')](_0x164b27);if(!_0x3880a2[_0x5b0c('0x2e')])return Project[_0x5b0c('0x2f')](_0x164b27);return Project['initialize'](_0x3880a2,_0x164b27);}function main(){var _0x58e1b2;return utilLicense[_0x5b0c('0x30')]()[_0x5b0c('0x31')](function(_0x59d392){if(!_0x59d392)return;if(_0x59d392[_0x5b0c('0x32')]){if(_0x59d392[_0x5b0c('0x33')]&&_0x59d392['callysquare']>0x0){logger[_0x5b0c('0x16')](util[_0x5b0c('0x17')](_0x5b0c('0x34'),_0x59d392[_0x5b0c('0x33')]));_0x58e1b2=_0x59d392[_0x5b0c('0x33')];}else{logger[_0x5b0c('0x16')](_0x5b0c('0x35'));}}else{logger[_0x5b0c('0x16')]('[LICENSE]\x20VOICE\x20IS\x20DISABLED');_0x58e1b2=-0x1;}})['then'](function(){return Project[_0x5b0c('0x36')]();})[_0x5b0c('0x31')](function(_0xacd1ae){projects=_0xacd1ae;return;})['catch'](function(_0x4183b3){logger['error'](_0x5b0c('0x37'),_0x4183b3[_0x5b0c('0xe')]);})['finally'](function(){var _0x2a8d0b=require(_0x5b0c('0x38'))(config[_0x5b0c('0x4')][_0x5b0c('0x15')],config['agi']['ip'],_0x58e1b2);_0x2a8d0b['on'](_0x5b0c('0xd'),errorHandler);_0x2a8d0b['on'](_0x5b0c('0x39'),listeningHandler);_0x2a8d0b['on'](_0x5b0c('0x3a'),connectionHandler);_0x2a8d0b['on'](_0x5b0c('0x28'),closeHandler);});}main();