ae2a54f14138aeb95727f4d398d96921c0b2ecda
[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 _0xeb84=['voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]','./server','connection','syncho','../../config/environment','../../config/logger','agi','../../config/license/util','./rpc','./project','./events','EventEmitter','defaults','127.0.0.1','projectUpdate','nextTick','error','stack','findIndex','deleted','splice','push','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','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','arg_1','callerid','dnid','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','calleridname','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','createSquareReport','hasOwnProperty','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','hangup','find','production','handleUnpublished','initialize','then'];(function(_0x1a014b,_0x48acae){var _0x462258=function(_0x1473be){while(--_0x1473be){_0x1a014b['push'](_0x1a014b['shift']());}};_0x462258(++_0x48acae);}(_0xeb84,0x133));var _0x4eb8=function(_0x28fbbf,_0x11f896){_0x28fbbf=_0x28fbbf-0x0;var _0x543af6=_0xeb84[_0x28fbbf];return _0x543af6;};'use strict';var _=require('lodash');var syncho=require(_0x4eb8('0x0'));var util=require('util');var config=require(_0x4eb8('0x1'));var logger=require(_0x4eb8('0x2'))(_0x4eb8('0x3'));var utilLicense=require(_0x4eb8('0x4'));var rpc=require(_0x4eb8('0x5'));var Project=require(_0x4eb8('0x6'));var AGIEmitter=require(_0x4eb8('0x7'))[_0x4eb8('0x8')];var projects=[];config[_0x4eb8('0x3')]=_[_0x4eb8('0x9')](config[_0x4eb8('0x3')],{'ip':_0x4eb8('0xa'),'port':0x11dd});AGIEmitter['on'](_0x4eb8('0xb'),projectUpdateHandler);function connectionHandler(_0x793dc1){process[_0x4eb8('0xc')](function(){syncho(function(){try{setChannelVariables(_0x793dc1);agiHandler(_0x793dc1);}catch(_0x441587){logger[_0x4eb8('0xd')](_0x441587[_0x4eb8('0xe')]);}});});}function projectUpdateHandler(_0x53722b){try{var _0x4eecfd=_[_0x4eb8('0xf')](projects,['id',_0x53722b['id']]);if(_0x4eecfd>-0x1){if(_0x53722b[_0x4eb8('0x10')]===!![]){projects[_0x4eb8('0x11')](_0x4eecfd,0x1);}else{projects[_0x4eecfd]=_0x53722b;}}else{projects[_0x4eb8('0x12')](_0x53722b);}}catch(_0x36e2bd){logger['error'](_0x36e2bd['stack']);}}function listeningHandler(){console[_0x4eb8('0x13')](_0x4eb8('0x14'),config[_0x4eb8('0x3')][_0x4eb8('0x15')]);logger[_0x4eb8('0x16')](util[_0x4eb8('0x17')](_0x4eb8('0x18'),config[_0x4eb8('0x3')]['ip'],config[_0x4eb8('0x3')][_0x4eb8('0x15')]));}function errorHandler(_0x5349d9){if(_0x5349d9&&_0x5349d9['name']&&_0x5349d9[_0x4eb8('0x19')]){logger[_0x4eb8('0xd')](util[_0x4eb8('0x17')](_0x4eb8('0x1a'),_0x5349d9[_0x4eb8('0x1b')],_0x5349d9['message']));}else{logger['error'](util[_0x4eb8('0x17')](_0x4eb8('0x1c'),_0x5349d9['stack']));}}function closeHandler(){logger[_0x4eb8('0x16')](util[_0x4eb8('0x17')](_0x4eb8('0x1d'),this[_0x4eb8('0x1e')],this['calleridname'],this[_0x4eb8('0x1f')],this[_0x4eb8('0x20')],this[_0x4eb8('0x21')]));try{createSquareReport(this);}catch(_0x1f298d){logger[_0x4eb8('0xd')](_0x1f298d[_0x4eb8('0xe')]);}}function timeoutHandler(){logger[_0x4eb8('0x16')](util[_0x4eb8('0x17')](_0x4eb8('0x22'),this[_0x4eb8('0x1e')],this[_0x4eb8('0x23')],this[_0x4eb8('0x1f')],this[_0x4eb8('0x20')],this[_0x4eb8('0x21')]));}function hangupHandler(){logger['info'](util[_0x4eb8('0x17')](_0x4eb8('0x24'),this[_0x4eb8('0x1e')],this[_0x4eb8('0x23')],this[_0x4eb8('0x1f')],this[_0x4eb8('0x20')],this['uniqueid']));this[_0x4eb8('0x25')]=!![];}function createSquareReport(_0x406521,_0x590091){rpc[_0x4eb8('0x26')](_0x406521)['then'](function(_0x400dc7){if(_0x590091){_0x590091(null,_0x400dc7);}})['catch'](function(_0x4d729b){if(_0x590091){_0x590091(null,_0x4d729b);}});}function setChannelVariables(_0x5cdd6f){for(var _0x1dff92 in _0x5cdd6f){if(_0x5cdd6f[_0x4eb8('0x27')](_0x1dff92)){if(_0x1dff92['indexOf'](_0x4eb8('0x28'))===0x0){_0x5cdd6f[_0x1dff92[_0x4eb8('0x29')](0x4)]=_0x5cdd6f[_0x1dff92];delete _0x5cdd6f[_0x1dff92];}}}}function agiHandler(_0x620828){logger[_0x4eb8('0x2a')](_0x4eb8('0x2b'),JSON[_0x4eb8('0x2c')](_0x620828,null,0x2));logger[_0x4eb8('0x16')](util[_0x4eb8('0x17')](_0x4eb8('0x2d'),_0x620828['arg_1'],_0x620828[_0x4eb8('0x23')],_0x620828[_0x4eb8('0x1f')],_0x620828[_0x4eb8('0x20')],_0x620828[_0x4eb8('0x21')]));_0x620828['on'](_0x4eb8('0xd'),errorHandler);_0x620828['on'](_0x4eb8('0x2e'),closeHandler);_0x620828['on']('timeout',timeoutHandler);_0x620828[_0x4eb8('0x25')]=![];_0x620828['on'](_0x4eb8('0x2f'),hangupHandler);var _0x54abc3=_[_0x4eb8('0x30')](projects,['name',_0x620828['arg_1']]);if(!_0x54abc3)return Project['handleNotFound'](_0x620828);if(!_0x54abc3[_0x4eb8('0x31')])return Project[_0x4eb8('0x32')](_0x620828);return Project[_0x4eb8('0x33')](_0x54abc3,_0x620828);}function main(){var _0x95667b;return utilLicense['getLicense']()[_0x4eb8('0x34')](function(_0xeb194f){if(!_0xeb194f)return;if(_0xeb194f[_0x4eb8('0x35')]){if(_0xeb194f[_0x4eb8('0x36')]&&_0xeb194f[_0x4eb8('0x36')]>0x0){logger[_0x4eb8('0x16')](util[_0x4eb8('0x17')](_0x4eb8('0x37'),_0xeb194f[_0x4eb8('0x36')]));_0x95667b=_0xeb194f['callysquare'];}else{logger[_0x4eb8('0x16')](_0x4eb8('0x38'));}}else{logger['info']('[LICENSE]\x20VOICE\x20IS\x20DISABLED');_0x95667b=-0x1;}})['then'](function(){return Project['getAll']();})[_0x4eb8('0x34')](function(_0x1fc675){projects=_0x1fc675;return;})['catch'](function(_0x49e01a){logger['error'](_0x4eb8('0x39'),_0x49e01a[_0x4eb8('0xe')]);})['finally'](function(){var _0x4bb7a9=require(_0x4eb8('0x3a'))(config[_0x4eb8('0x3')][_0x4eb8('0x15')],config[_0x4eb8('0x3')]['ip'],_0x95667b);_0x4bb7a9['on'](_0x4eb8('0xd'),errorHandler);_0x4bb7a9['on']('listening',listeningHandler);_0x4bb7a9['on'](_0x4eb8('0x3b'),connectionHandler);_0x4bb7a9['on'](_0x4eb8('0x2e'),closeHandler);});}main();