Built motion from commit 10af8726.|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 _0xbfe4=['getLicense','then','voice','callysquare','[LICENSE]\x20CHANNELS:\x20UNLIMITED','finally','./server','listening','connection','lodash','syncho','util','../../config/logger','agi','./project','./events','EventEmitter','defaults','127.0.0.1','nextTick','error','stack','splice','push','env','production','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','host.docker.internal','name','message','[ERROR]\x20%s','info','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','calleridname','dnid','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','callerid','evtHangup','createSquareReport','hasOwnProperty','indexOf','agi_','substring','debug','variables','stringify','[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','close','timeout','hangup','handleNotFound','initialize'];(function(_0x2fc012,_0x503e5b){var _0x2891f9=function(_0x295f5e){while(--_0x295f5e){_0x2fc012['push'](_0x2fc012['shift']());}};_0x2891f9(++_0x503e5b);}(_0xbfe4,0xba));var _0x4bfe=function(_0x312830,_0x2cbe42){_0x312830=_0x312830-0x0;var _0x4ca09d=_0xbfe4[_0x312830];return _0x4ca09d;};'use strict';var _=require(_0x4bfe('0x0'));var syncho=require(_0x4bfe('0x1'));var util=require(_0x4bfe('0x2'));var config=require('../../config/environment');var logger=require(_0x4bfe('0x3'))(_0x4bfe('0x4'));var utilLicense=require('../../config/license/util');var rpc=require('./rpc');var Project=require(_0x4bfe('0x5'));var AGIEmitter=require(_0x4bfe('0x6'))[_0x4bfe('0x7')];var projects=[];config[_0x4bfe('0x4')]=_[_0x4bfe('0x8')](config['agi'],{'ip':_0x4bfe('0x9'),'port':0x11dd});AGIEmitter['on']('projectUpdate',projectUpdateHandler);function connectionHandler(_0x4c02be){process[_0x4bfe('0xa')](function(){syncho(function(){try{setChannelVariables(_0x4c02be);agiHandler(_0x4c02be);}catch(_0x6d1567){logger[_0x4bfe('0xb')](_0x6d1567[_0x4bfe('0xc')]);}});});}function projectUpdateHandler(_0xa06187){try{var _0x297d08=_['findIndex'](projects,['id',_0xa06187['id']]);if(_0x297d08>-0x1){if(_0xa06187['deleted']===!![]){projects[_0x4bfe('0xd')](_0x297d08,0x1);}else{projects[_0x297d08]=_0xa06187;}}else{projects[_0x4bfe('0xe')](_0xa06187);}}catch(_0x560c13){logger[_0x4bfe('0xb')](_0x560c13[_0x4bfe('0xc')]);}}function listeningHandler(){var _0x37b7b1=config[_0x4bfe('0xf')]===_0x4bfe('0x10')||![];console[_0x4bfe('0x11')](_0x4bfe('0x12'),config['agi'][_0x4bfe('0x13')]);logger['info'](util[_0x4bfe('0x14')](_0x4bfe('0x15'),_0x37b7b1?config[_0x4bfe('0x4')]['ip']:_0x4bfe('0x16'),config['agi'][_0x4bfe('0x13')]));}function errorHandler(_0x259d8c){if(_0x259d8c&&_0x259d8c['name']&&_0x259d8c['message']){logger[_0x4bfe('0xb')](util[_0x4bfe('0x14')]('[%s]\x20%s',_0x259d8c[_0x4bfe('0x17')],_0x259d8c[_0x4bfe('0x18')]));}else{logger['error'](util[_0x4bfe('0x14')](_0x4bfe('0x19'),_0x259d8c['stack']));}}function closeHandler(){logger[_0x4bfe('0x1a')](util[_0x4bfe('0x14')](_0x4bfe('0x1b'),this[_0x4bfe('0x1c')],this[_0x4bfe('0x1d')],this['callerid'],this[_0x4bfe('0x1e')],this[_0x4bfe('0x1f')]));try{createSquareReport(this);}catch(_0x21f60d){logger[_0x4bfe('0xb')](_0x21f60d[_0x4bfe('0xc')]);}}function timeoutHandler(){logger[_0x4bfe('0x1a')](util['format'](_0x4bfe('0x20'),this[_0x4bfe('0x1c')],this[_0x4bfe('0x1d')],this['callerid'],this[_0x4bfe('0x1e')],this[_0x4bfe('0x1f')]));}function hangupHandler(){logger[_0x4bfe('0x1a')](util['format'](_0x4bfe('0x21'),this[_0x4bfe('0x1c')],this[_0x4bfe('0x1d')],this[_0x4bfe('0x22')],this[_0x4bfe('0x1e')],this['uniqueid']));this[_0x4bfe('0x23')]=!![];}function createSquareReport(_0x4cf1d1,_0x326caa){rpc[_0x4bfe('0x24')](_0x4cf1d1)['then'](function(_0x164112){if(_0x326caa){_0x326caa(null,_0x164112);}})['catch'](function(_0x46510e){if(_0x326caa){_0x326caa(null,_0x46510e);}});}function setChannelVariables(_0x6bf183){for(var _0xb740c4 in _0x6bf183){if(_0x6bf183[_0x4bfe('0x25')](_0xb740c4)){if(_0xb740c4[_0x4bfe('0x26')](_0x4bfe('0x27'))===0x0){_0x6bf183[_0xb740c4[_0x4bfe('0x28')](0x4)]=_0x6bf183[_0xb740c4];delete _0x6bf183[_0xb740c4];}}}}function agiHandler(_0x5f7790){logger[_0x4bfe('0x29')](_0x4bfe('0x2a'),JSON[_0x4bfe('0x2b')](_0x5f7790,null,0x2));logger[_0x4bfe('0x1a')](util['format'](_0x4bfe('0x2c'),_0x5f7790[_0x4bfe('0x1c')],_0x5f7790[_0x4bfe('0x1d')],_0x5f7790['callerid'],_0x5f7790['dnid'],_0x5f7790[_0x4bfe('0x1f')]));_0x5f7790['on']('error',errorHandler);_0x5f7790['on'](_0x4bfe('0x2d'),closeHandler);_0x5f7790['on'](_0x4bfe('0x2e'),timeoutHandler);_0x5f7790[_0x4bfe('0x23')]=![];_0x5f7790['on'](_0x4bfe('0x2f'),hangupHandler);var _0x49d106=_['find'](projects,[_0x4bfe('0x17'),_0x5f7790[_0x4bfe('0x1c')]]);if(!_0x49d106)return Project[_0x4bfe('0x30')](_0x5f7790);if(!_0x49d106[_0x4bfe('0x10')])return Project['handleUnpublished'](_0x5f7790);return Project[_0x4bfe('0x31')](_0x49d106,_0x5f7790);}function main(){var _0x52b26b;return utilLicense[_0x4bfe('0x32')]()[_0x4bfe('0x33')](function(_0xf20524){if(!_0xf20524)return;if(_0xf20524[_0x4bfe('0x34')]){if(_0xf20524['callysquare']&&_0xf20524[_0x4bfe('0x35')]>0x0){logger[_0x4bfe('0x1a')](util['format']('[LICENSE]\x20CHANNELS:\x20%s',_0xf20524['callysquare']));_0x52b26b=_0xf20524[_0x4bfe('0x35')];}else{logger['info'](_0x4bfe('0x36'));}}else{logger[_0x4bfe('0x1a')]('[LICENSE]\x20VOICE\x20IS\x20DISABLED');_0x52b26b=-0x1;}})[_0x4bfe('0x33')](function(){return Project['getAll']();})['then'](function(_0x5f18ba){projects=_0x5f18ba;return;})['catch'](function(_0x4419cc){logger[_0x4bfe('0xb')]('[LICENSE]',_0x4419cc[_0x4bfe('0xc')]);})[_0x4bfe('0x37')](function(){var _0x2be248=require(_0x4bfe('0x38'))(config[_0x4bfe('0x4')][_0x4bfe('0x13')],config[_0x4bfe('0x4')]['ip'],_0x52b26b);_0x2be248['on'](_0x4bfe('0xb'),errorHandler);_0x2be248['on'](_0x4bfe('0x39'),listeningHandler);_0x2be248['on'](_0x4bfe('0x3a'),connectionHandler);_0x2be248['on']('close',closeHandler);});}main();