Built motion from commit 1ea47bf4.|2.6.34
[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 _0x9f39=['[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','calleridname','callerid','dnid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','uniqueid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','createSquareReport','then','catch','hasOwnProperty','indexOf','agi_','substring','debug','variables','stringify','close','timeout','find','handleNotFound','handleUnpublished','initialize','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','getAll','[LICENSE]','finally','./server','listening','connection','lodash','syncho','util','../../config/environment','../../config/logger','agi','../../config/license/util','./rpc','./project','defaults','127.0.0.1','projectUpdate','error','stack','splice','env','production','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','[%s]\x20%s','name','[ERROR]\x20%s'];(function(_0x14909f,_0xe25f2e){var _0x19698c=function(_0x126280){while(--_0x126280){_0x14909f['push'](_0x14909f['shift']());}};_0x19698c(++_0xe25f2e);}(_0x9f39,0xa0));var _0x99f3=function(_0x384e1e,_0xe637b9){_0x384e1e=_0x384e1e-0x0;var _0x14d92c=_0x9f39[_0x384e1e];return _0x14d92c;};'use strict';var _=require(_0x99f3('0x0'));var syncho=require(_0x99f3('0x1'));var util=require(_0x99f3('0x2'));var config=require(_0x99f3('0x3'));var logger=require(_0x99f3('0x4'))(_0x99f3('0x5'));var utilLicense=require(_0x99f3('0x6'));var rpc=require(_0x99f3('0x7'));var Project=require(_0x99f3('0x8'));var AGIEmitter=require('./events')['EventEmitter'];var projects=[];config[_0x99f3('0x5')]=_[_0x99f3('0x9')](config[_0x99f3('0x5')],{'ip':_0x99f3('0xa'),'port':0x11dd});AGIEmitter['on'](_0x99f3('0xb'),projectUpdateHandler);function connectionHandler(_0x2ff7b2){process['nextTick'](function(){syncho(function(){try{setChannelVariables(_0x2ff7b2);agiHandler(_0x2ff7b2);}catch(_0x1954ac){logger[_0x99f3('0xc')](_0x1954ac[_0x99f3('0xd')]);}});});}function projectUpdateHandler(_0x5c11ec){try{var _0x21ceec=_['findIndex'](projects,['id',_0x5c11ec['id']]);if(_0x21ceec>-0x1){if(_0x5c11ec['deleted']===!![]){projects[_0x99f3('0xe')](_0x21ceec,0x1);}else{projects[_0x21ceec]=_0x5c11ec;}}else{projects['push'](_0x5c11ec);}}catch(_0x655735){logger['error'](_0x655735[_0x99f3('0xd')]);}}function listeningHandler(){var _0x224c4d=config[_0x99f3('0xf')]===_0x99f3('0x10')||![];console[_0x99f3('0x11')](_0x99f3('0x12'),config[_0x99f3('0x5')][_0x99f3('0x13')]);logger[_0x99f3('0x14')](util[_0x99f3('0x15')](_0x99f3('0x16'),_0x224c4d?config[_0x99f3('0x5')]['ip']:'host.docker.internal',config[_0x99f3('0x5')][_0x99f3('0x13')]));}function errorHandler(_0x2605af){if(_0x2605af&&_0x2605af['name']&&_0x2605af['message']){logger[_0x99f3('0xc')](util[_0x99f3('0x15')](_0x99f3('0x17'),_0x2605af[_0x99f3('0x18')],_0x2605af['message']));}else{logger[_0x99f3('0xc')](util[_0x99f3('0x15')](_0x99f3('0x19'),_0x2605af[_0x99f3('0xd')]));}}function closeHandler(){logger[_0x99f3('0x14')](util['format'](_0x99f3('0x1a'),this['arg_1'],this[_0x99f3('0x1b')],this[_0x99f3('0x1c')],this[_0x99f3('0x1d')],this['uniqueid']));try{createSquareReport(this);}catch(_0x22543e){logger[_0x99f3('0xc')](_0x22543e['stack']);}}function timeoutHandler(){logger['info'](util[_0x99f3('0x15')](_0x99f3('0x1e'),this[_0x99f3('0x1f')],this[_0x99f3('0x1b')],this[_0x99f3('0x1c')],this[_0x99f3('0x1d')],this[_0x99f3('0x20')]));}function hangupHandler(){logger[_0x99f3('0x14')](util['format'](_0x99f3('0x21'),this[_0x99f3('0x1f')],this['calleridname'],this[_0x99f3('0x1c')],this[_0x99f3('0x1d')],this[_0x99f3('0x20')]));this['evtHangup']=!![];}function createSquareReport(_0x48f01f,_0x149644){rpc[_0x99f3('0x22')](_0x48f01f)[_0x99f3('0x23')](function(_0x5f2f82){if(_0x149644){_0x149644(null,_0x5f2f82);}})[_0x99f3('0x24')](function(_0x12215c){if(_0x149644){_0x149644(null,_0x12215c);}});}function setChannelVariables(_0x429cda){for(var _0x1d4bcc in _0x429cda){if(_0x429cda[_0x99f3('0x25')](_0x1d4bcc)){if(_0x1d4bcc[_0x99f3('0x26')](_0x99f3('0x27'))===0x0){_0x429cda[_0x1d4bcc[_0x99f3('0x28')](0x4)]=_0x429cda[_0x1d4bcc];delete _0x429cda[_0x1d4bcc];}}}}function agiHandler(_0x108689){logger[_0x99f3('0x29')](_0x99f3('0x2a'),JSON[_0x99f3('0x2b')](_0x108689,null,0x2));logger[_0x99f3('0x14')](util[_0x99f3('0x15')]('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x108689[_0x99f3('0x1f')],_0x108689[_0x99f3('0x1b')],_0x108689[_0x99f3('0x1c')],_0x108689[_0x99f3('0x1d')],_0x108689[_0x99f3('0x20')]));_0x108689['on']('error',errorHandler);_0x108689['on'](_0x99f3('0x2c'),closeHandler);_0x108689['on'](_0x99f3('0x2d'),timeoutHandler);_0x108689['evtHangup']=![];_0x108689['on']('hangup',hangupHandler);var _0x25e789=_[_0x99f3('0x2e')](projects,[_0x99f3('0x18'),_0x108689[_0x99f3('0x1f')]]);if(!_0x25e789)return Project[_0x99f3('0x2f')](_0x108689);if(!_0x25e789[_0x99f3('0x10')])return Project[_0x99f3('0x30')](_0x108689);return Project[_0x99f3('0x31')](_0x25e789,_0x108689);}function main(){var _0x3c1def;return utilLicense[_0x99f3('0x32')]()['then'](function(_0x443f42){if(!_0x443f42)return;if(_0x443f42[_0x99f3('0x33')]){if(_0x443f42[_0x99f3('0x34')]&&_0x443f42[_0x99f3('0x34')]>0x0){logger[_0x99f3('0x14')](util[_0x99f3('0x15')](_0x99f3('0x35'),_0x443f42['callysquare']));_0x3c1def=_0x443f42[_0x99f3('0x34')];}else{logger[_0x99f3('0x14')](_0x99f3('0x36'));}}else{logger['info'](_0x99f3('0x37'));_0x3c1def=-0x1;}})[_0x99f3('0x23')](function(){return Project[_0x99f3('0x38')]();})['then'](function(_0x27bc3e){projects=_0x27bc3e;return;})[_0x99f3('0x24')](function(_0xfcd45f){logger[_0x99f3('0xc')](_0x99f3('0x39'),_0xfcd45f[_0x99f3('0xd')]);})[_0x99f3('0x3a')](function(){var _0x5bbf2b=require(_0x99f3('0x3b'))(config[_0x99f3('0x5')][_0x99f3('0x13')],config[_0x99f3('0x5')]['ip'],_0x3c1def);_0x5bbf2b['on'](_0x99f3('0xc'),errorHandler);_0x5bbf2b['on'](_0x99f3('0x3c'),listeningHandler);_0x5bbf2b['on'](_0x99f3('0x3d'),connectionHandler);_0x5bbf2b['on']('close',closeHandler);});}main();