Built motion from commit 616d3211.|2.6.4
[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 _0x1c7b=['port','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','name','message','[%s]\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','dnid','uniqueid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','createSquareReport','then','catch','substring','debug','variables','stringify','close','timeout','hangup','find','handleNotFound','handleUnpublished','initialize','getLicense','callysquare','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','getAll','[LICENSE]','finally','lodash','util','../../config/logger','agi','./project','./events','defaults','127.0.0.1','nextTick','findIndex','deleted','splice','push','error','stack','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!'];(function(_0xd050c6,_0x58ffb4){var _0x7278a=function(_0x16d03e){while(--_0x16d03e){_0xd050c6['push'](_0xd050c6['shift']());}};_0x7278a(++_0x58ffb4);}(_0x1c7b,0xf8));var _0xb1c7=function(_0x14d477,_0x259495){_0x14d477=_0x14d477-0x0;var _0x1366f0=_0x1c7b[_0x14d477];return _0x1366f0;};'use strict';var _=require(_0xb1c7('0x0'));var syncho=require('syncho');var util=require(_0xb1c7('0x1'));var config=require('../../config/environment');var logger=require(_0xb1c7('0x2'))(_0xb1c7('0x3'));var utilLicense=require('../../config/license/util');var rpc=require('./rpc');var Project=require(_0xb1c7('0x4'));var AGIEmitter=require(_0xb1c7('0x5'))['EventEmitter'];var projects=[];config[_0xb1c7('0x3')]=_[_0xb1c7('0x6')](config[_0xb1c7('0x3')],{'ip':_0xb1c7('0x7'),'port':0x11dd});AGIEmitter['on']('projectUpdate',projectUpdateHandler);function connectionHandler(_0x5bef49){process[_0xb1c7('0x8')](function(){syncho(function(){try{setChannelVariables(_0x5bef49);agiHandler(_0x5bef49);}catch(_0x55d614){logger['error'](_0x55d614['stack']);}});});}function projectUpdateHandler(_0x4eded3){try{var _0x47314a=_[_0xb1c7('0x9')](projects,['id',_0x4eded3['id']]);if(_0x47314a>-0x1){if(_0x4eded3[_0xb1c7('0xa')]===!![]){projects[_0xb1c7('0xb')](_0x47314a,0x1);}else{projects[_0x47314a]=_0x4eded3;}}else{projects[_0xb1c7('0xc')](_0x4eded3);}}catch(_0x2b10cf){logger[_0xb1c7('0xd')](_0x2b10cf[_0xb1c7('0xe')]);}}function listeningHandler(){console[_0xb1c7('0xf')](_0xb1c7('0x10'),config[_0xb1c7('0x3')][_0xb1c7('0x11')]);logger[_0xb1c7('0x12')](util[_0xb1c7('0x13')](_0xb1c7('0x14'),config[_0xb1c7('0x3')]['ip'],config[_0xb1c7('0x3')]['port']));}function errorHandler(_0x354cf4){if(_0x354cf4&&_0x354cf4[_0xb1c7('0x15')]&&_0x354cf4[_0xb1c7('0x16')]){logger[_0xb1c7('0xd')](util[_0xb1c7('0x13')](_0xb1c7('0x17'),_0x354cf4[_0xb1c7('0x15')],_0x354cf4[_0xb1c7('0x16')]));}else{logger['error'](util[_0xb1c7('0x13')]('[ERROR]\x20%s',_0x354cf4['stack']));}}function closeHandler(){logger[_0xb1c7('0x12')](util[_0xb1c7('0x13')](_0xb1c7('0x18'),this[_0xb1c7('0x19')],this[_0xb1c7('0x1a')],this[_0xb1c7('0x1b')],this[_0xb1c7('0x1c')],this['uniqueid']));try{createSquareReport(this);}catch(_0x2dd226){logger[_0xb1c7('0xd')](_0x2dd226[_0xb1c7('0xe')]);}}function timeoutHandler(){logger['info'](util[_0xb1c7('0x13')]('[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0xb1c7('0x19')],this['calleridname'],this[_0xb1c7('0x1b')],this[_0xb1c7('0x1c')],this[_0xb1c7('0x1d')]));}function hangupHandler(){logger[_0xb1c7('0x12')](util[_0xb1c7('0x13')](_0xb1c7('0x1e'),this[_0xb1c7('0x19')],this['calleridname'],this[_0xb1c7('0x1b')],this[_0xb1c7('0x1c')],this[_0xb1c7('0x1d')]));this[_0xb1c7('0x1f')]=!![];}function createSquareReport(_0x2e838c,_0x1c4a52){rpc[_0xb1c7('0x20')](_0x2e838c)[_0xb1c7('0x21')](function(_0x10903a){if(_0x1c4a52){_0x1c4a52(null,_0x10903a);}})[_0xb1c7('0x22')](function(_0x10cb99){if(_0x1c4a52){_0x1c4a52(null,_0x10cb99);}});}function setChannelVariables(_0x51dc93){for(var _0xeaa451 in _0x51dc93){if(_0x51dc93['hasOwnProperty'](_0xeaa451)){if(_0xeaa451['indexOf']('agi_')===0x0){_0x51dc93[_0xeaa451[_0xb1c7('0x23')](0x4)]=_0x51dc93[_0xeaa451];delete _0x51dc93[_0xeaa451];}}}}function agiHandler(_0x146c34){logger[_0xb1c7('0x24')](_0xb1c7('0x25'),JSON[_0xb1c7('0x26')](_0x146c34,null,0x2));logger[_0xb1c7('0x12')](util['format']('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x146c34[_0xb1c7('0x19')],_0x146c34[_0xb1c7('0x1a')],_0x146c34[_0xb1c7('0x1b')],_0x146c34[_0xb1c7('0x1c')],_0x146c34[_0xb1c7('0x1d')]));_0x146c34['on'](_0xb1c7('0xd'),errorHandler);_0x146c34['on'](_0xb1c7('0x27'),closeHandler);_0x146c34['on'](_0xb1c7('0x28'),timeoutHandler);_0x146c34[_0xb1c7('0x1f')]=![];_0x146c34['on'](_0xb1c7('0x29'),hangupHandler);var _0x477055=_[_0xb1c7('0x2a')](projects,[_0xb1c7('0x15'),_0x146c34['arg_1']]);if(!_0x477055)return Project[_0xb1c7('0x2b')](_0x146c34);if(!_0x477055['production'])return Project[_0xb1c7('0x2c')](_0x146c34);return Project[_0xb1c7('0x2d')](_0x477055,_0x146c34);}function main(){var _0x3023af;return utilLicense[_0xb1c7('0x2e')]()[_0xb1c7('0x21')](function(_0x568dc7){if(!_0x568dc7)return;if(_0x568dc7['voice']){if(_0x568dc7[_0xb1c7('0x2f')]&&_0x568dc7[_0xb1c7('0x2f')]>0x0){logger[_0xb1c7('0x12')](util['format']('[LICENSE]\x20CHANNELS:\x20%s',_0x568dc7[_0xb1c7('0x2f')]));_0x3023af=_0x568dc7[_0xb1c7('0x2f')];}else{logger['info'](_0xb1c7('0x30'));}}else{logger[_0xb1c7('0x12')](_0xb1c7('0x31'));_0x3023af=-0x1;}})[_0xb1c7('0x21')](function(){return Project[_0xb1c7('0x32')]();})['then'](function(_0x11cf47){projects=_0x11cf47;return;})[_0xb1c7('0x22')](function(_0x3224ef){logger['error'](_0xb1c7('0x33'),_0x3224ef[_0xb1c7('0xe')]);})[_0xb1c7('0x34')](function(){var _0x566ef3=require('./server')(config[_0xb1c7('0x3')][_0xb1c7('0x11')],config[_0xb1c7('0x3')]['ip'],_0x3023af);_0x566ef3['on'](_0xb1c7('0xd'),errorHandler);_0x566ef3['on']('listening',listeningHandler);_0x566ef3['on']('connection',connectionHandler);_0x566ef3['on'](_0xb1c7('0x27'),closeHandler);});}main();