Built motion from commit da617fac.|2.6.6
[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 _0x7de7=['arg_1','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','then','catch','hasOwnProperty','indexOf','agi_','substring','debug','variables','[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','close','timeout','evtHangup','initialize','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','[LICENSE]','finally','./server','connection','syncho','../../config/environment','../../config/logger','agi','../../config/license/util','./project','./events','EventEmitter','defaults','127.0.0.1','projectUpdate','nextTick','findIndex','deleted','push','error','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','name','format','[%s]\x20%s','[ERROR]\x20%s','stack','info','[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'];(function(_0x2a7059,_0x5b40b9){var _0x1913b1=function(_0x5a5924){while(--_0x5a5924){_0x2a7059['push'](_0x2a7059['shift']());}};_0x1913b1(++_0x5b40b9);}(_0x7de7,0x162));var _0x77de=function(_0x3b90ab,_0x174a22){_0x3b90ab=_0x3b90ab-0x0;var _0x206e92=_0x7de7[_0x3b90ab];return _0x206e92;};'use strict';var _=require('lodash');var syncho=require(_0x77de('0x0'));var util=require('util');var config=require(_0x77de('0x1'));var logger=require(_0x77de('0x2'))(_0x77de('0x3'));var utilLicense=require(_0x77de('0x4'));var rpc=require('./rpc');var Project=require(_0x77de('0x5'));var AGIEmitter=require(_0x77de('0x6'))[_0x77de('0x7')];var projects=[];config[_0x77de('0x3')]=_[_0x77de('0x8')](config[_0x77de('0x3')],{'ip':_0x77de('0x9'),'port':0x11dd});AGIEmitter['on'](_0x77de('0xa'),projectUpdateHandler);function connectionHandler(_0x31096f){process[_0x77de('0xb')](function(){syncho(function(){try{setChannelVariables(_0x31096f);agiHandler(_0x31096f);}catch(_0x3e6fbf){logger['error'](_0x3e6fbf['stack']);}});});}function projectUpdateHandler(_0x575a50){try{var _0x4d3c26=_[_0x77de('0xc')](projects,['id',_0x575a50['id']]);if(_0x4d3c26>-0x1){if(_0x575a50[_0x77de('0xd')]===!![]){projects['splice'](_0x4d3c26,0x1);}else{projects[_0x4d3c26]=_0x575a50;}}else{projects[_0x77de('0xe')](_0x575a50);}}catch(_0x5ac3f5){logger[_0x77de('0xf')](_0x5ac3f5['stack']);}}function listeningHandler(){console[_0x77de('0x10')](_0x77de('0x11'),config[_0x77de('0x3')][_0x77de('0x12')]);logger['info'](util['format']('[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d',config['agi']['ip'],config['agi']['port']));}function errorHandler(_0x428db6){if(_0x428db6&&_0x428db6[_0x77de('0x13')]&&_0x428db6['message']){logger[_0x77de('0xf')](util[_0x77de('0x14')](_0x77de('0x15'),_0x428db6['name'],_0x428db6['message']));}else{logger[_0x77de('0xf')](util[_0x77de('0x14')](_0x77de('0x16'),_0x428db6[_0x77de('0x17')]));}}function closeHandler(){logger[_0x77de('0x18')](util[_0x77de('0x14')](_0x77de('0x19'),this['arg_1'],this[_0x77de('0x1a')],this[_0x77de('0x1b')],this[_0x77de('0x1c')],this[_0x77de('0x1d')]));try{createSquareReport(this);}catch(_0x508b10){logger['error'](_0x508b10[_0x77de('0x17')]);}}function timeoutHandler(){logger[_0x77de('0x18')](util[_0x77de('0x14')](_0x77de('0x1e'),this[_0x77de('0x1f')],this['calleridname'],this[_0x77de('0x1b')],this[_0x77de('0x1c')],this[_0x77de('0x1d')]));}function hangupHandler(){logger['info'](util['format'](_0x77de('0x20'),this[_0x77de('0x1f')],this[_0x77de('0x1a')],this['callerid'],this[_0x77de('0x1c')],this[_0x77de('0x1d')]));this['evtHangup']=!![];}function createSquareReport(_0x4b9210,_0x1833ae){rpc['createSquareReport'](_0x4b9210)[_0x77de('0x21')](function(_0x3e775b){if(_0x1833ae){_0x1833ae(null,_0x3e775b);}})[_0x77de('0x22')](function(_0x260684){if(_0x1833ae){_0x1833ae(null,_0x260684);}});}function setChannelVariables(_0x2e82e7){for(var _0x4bd2c1 in _0x2e82e7){if(_0x2e82e7[_0x77de('0x23')](_0x4bd2c1)){if(_0x4bd2c1[_0x77de('0x24')](_0x77de('0x25'))===0x0){_0x2e82e7[_0x4bd2c1[_0x77de('0x26')](0x4)]=_0x2e82e7[_0x4bd2c1];delete _0x2e82e7[_0x4bd2c1];}}}}function agiHandler(_0x38d012){logger[_0x77de('0x27')](_0x77de('0x28'),JSON['stringify'](_0x38d012,null,0x2));logger[_0x77de('0x18')](util['format'](_0x77de('0x29'),_0x38d012[_0x77de('0x1f')],_0x38d012[_0x77de('0x1a')],_0x38d012[_0x77de('0x1b')],_0x38d012[_0x77de('0x1c')],_0x38d012[_0x77de('0x1d')]));_0x38d012['on'](_0x77de('0xf'),errorHandler);_0x38d012['on'](_0x77de('0x2a'),closeHandler);_0x38d012['on'](_0x77de('0x2b'),timeoutHandler);_0x38d012[_0x77de('0x2c')]=![];_0x38d012['on']('hangup',hangupHandler);var _0x20f96b=_['find'](projects,['name',_0x38d012[_0x77de('0x1f')]]);if(!_0x20f96b)return Project['handleNotFound'](_0x38d012);if(!_0x20f96b['production'])return Project['handleUnpublished'](_0x38d012);return Project[_0x77de('0x2d')](_0x20f96b,_0x38d012);}function main(){var _0x4e59d0;return utilLicense['getLicense']()[_0x77de('0x21')](function(_0x3fd31e){if(!_0x3fd31e)return;if(_0x3fd31e[_0x77de('0x2e')]){if(_0x3fd31e['callysquare']&&_0x3fd31e[_0x77de('0x2f')]>0x0){logger[_0x77de('0x18')](util[_0x77de('0x14')](_0x77de('0x30'),_0x3fd31e[_0x77de('0x2f')]));_0x4e59d0=_0x3fd31e[_0x77de('0x2f')];}else{logger[_0x77de('0x18')](_0x77de('0x31'));}}else{logger['info'](_0x77de('0x32'));_0x4e59d0=-0x1;}})[_0x77de('0x21')](function(){return Project['getAll']();})[_0x77de('0x21')](function(_0x1a400a){projects=_0x1a400a;return;})['catch'](function(_0x8fcdbc){logger['error'](_0x77de('0x33'),_0x8fcdbc['stack']);})[_0x77de('0x34')](function(){var _0x5ea783=require(_0x77de('0x35'))(config[_0x77de('0x3')]['port'],config[_0x77de('0x3')]['ip'],_0x4e59d0);_0x5ea783['on'](_0x77de('0xf'),errorHandler);_0x5ea783['on']('listening',listeningHandler);_0x5ea783['on'](_0x77de('0x36'),connectionHandler);_0x5ea783['on'](_0x77de('0x2a'),closeHandler);});}main();