Built motion from commit 953226e6.|2.6.32
[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 _0x5ce0=['calleridname','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','[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','close','evtHangup','hangup','handleNotFound','production','initialize','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','getAll','[LICENSE]','finally','listening','connection','syncho','util','../../config/logger','agi','../../config/license/util','./rpc','./project','./events','EventEmitter','defaults','projectUpdate','nextTick','stack','findIndex','deleted','push','error','log','port','format','host.docker.internal','name','message','[%s]\x20%s','[ERROR]\x20%s','arg_1','callerid','dnid','info'];(function(_0x552866,_0x1fccda){var _0x6c426=function(_0x52f481){while(--_0x52f481){_0x552866['push'](_0x552866['shift']());}};_0x6c426(++_0x1fccda);}(_0x5ce0,0x145));var _0x05ce=function(_0x57fa33,_0x2b8222){_0x57fa33=_0x57fa33-0x0;var _0x12e724=_0x5ce0[_0x57fa33];return _0x12e724;};'use strict';var _=require('lodash');var syncho=require(_0x05ce('0x0'));var util=require(_0x05ce('0x1'));var config=require('../../config/environment');var logger=require(_0x05ce('0x2'))(_0x05ce('0x3'));var utilLicense=require(_0x05ce('0x4'));var rpc=require(_0x05ce('0x5'));var Project=require(_0x05ce('0x6'));var AGIEmitter=require(_0x05ce('0x7'))[_0x05ce('0x8')];var projects=[];config[_0x05ce('0x3')]=_[_0x05ce('0x9')](config['agi'],{'ip':'127.0.0.1','port':0x11dd});AGIEmitter['on'](_0x05ce('0xa'),projectUpdateHandler);function connectionHandler(_0x2c8352){process[_0x05ce('0xb')](function(){syncho(function(){try{setChannelVariables(_0x2c8352);agiHandler(_0x2c8352);}catch(_0x4ae736){logger['error'](_0x4ae736[_0x05ce('0xc')]);}});});}function projectUpdateHandler(_0x442ba7){try{var _0x16569a=_[_0x05ce('0xd')](projects,['id',_0x442ba7['id']]);if(_0x16569a>-0x1){if(_0x442ba7[_0x05ce('0xe')]===!![]){projects['splice'](_0x16569a,0x1);}else{projects[_0x16569a]=_0x442ba7;}}else{projects[_0x05ce('0xf')](_0x442ba7);}}catch(_0x33334f){logger[_0x05ce('0x10')](_0x33334f[_0x05ce('0xc')]);}}function listeningHandler(){var _0x167cdb=config['env']==='production'||![];console[_0x05ce('0x11')]('Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!',config['agi'][_0x05ce('0x12')]);logger['info'](util[_0x05ce('0x13')]('[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d',_0x167cdb?config['agi']['ip']:_0x05ce('0x14'),config[_0x05ce('0x3')][_0x05ce('0x12')]));}function errorHandler(_0x23f2b0){if(_0x23f2b0&&_0x23f2b0[_0x05ce('0x15')]&&_0x23f2b0[_0x05ce('0x16')]){logger[_0x05ce('0x10')](util[_0x05ce('0x13')](_0x05ce('0x17'),_0x23f2b0[_0x05ce('0x15')],_0x23f2b0[_0x05ce('0x16')]));}else{logger[_0x05ce('0x10')](util[_0x05ce('0x13')](_0x05ce('0x18'),_0x23f2b0[_0x05ce('0xc')]));}}function closeHandler(){logger['info'](util[_0x05ce('0x13')]('[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0x05ce('0x19')],this['calleridname'],this[_0x05ce('0x1a')],this[_0x05ce('0x1b')],this['uniqueid']));try{createSquareReport(this);}catch(_0x125487){logger[_0x05ce('0x10')](_0x125487[_0x05ce('0xc')]);}}function timeoutHandler(){logger[_0x05ce('0x1c')](util[_0x05ce('0x13')]('[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0x05ce('0x19')],this[_0x05ce('0x1d')],this[_0x05ce('0x1a')],this['dnid'],this[_0x05ce('0x1e')]));}function hangupHandler(){logger[_0x05ce('0x1c')](util[_0x05ce('0x13')](_0x05ce('0x1f'),this[_0x05ce('0x19')],this[_0x05ce('0x1d')],this[_0x05ce('0x1a')],this['dnid'],this['uniqueid']));this['evtHangup']=!![];}function createSquareReport(_0x475881,_0x4475d3){rpc[_0x05ce('0x20')](_0x475881)[_0x05ce('0x21')](function(_0x490200){if(_0x4475d3){_0x4475d3(null,_0x490200);}})[_0x05ce('0x22')](function(_0x4e8f32){if(_0x4475d3){_0x4475d3(null,_0x4e8f32);}});}function setChannelVariables(_0x190b29){for(var _0x3e45f2 in _0x190b29){if(_0x190b29[_0x05ce('0x23')](_0x3e45f2)){if(_0x3e45f2[_0x05ce('0x24')](_0x05ce('0x25'))===0x0){_0x190b29[_0x3e45f2[_0x05ce('0x26')](0x4)]=_0x190b29[_0x3e45f2];delete _0x190b29[_0x3e45f2];}}}}function agiHandler(_0x22b39d){logger[_0x05ce('0x27')](_0x05ce('0x28'),JSON['stringify'](_0x22b39d,null,0x2));logger[_0x05ce('0x1c')](util[_0x05ce('0x13')](_0x05ce('0x29'),_0x22b39d[_0x05ce('0x19')],_0x22b39d[_0x05ce('0x1d')],_0x22b39d[_0x05ce('0x1a')],_0x22b39d[_0x05ce('0x1b')],_0x22b39d['uniqueid']));_0x22b39d['on'](_0x05ce('0x10'),errorHandler);_0x22b39d['on'](_0x05ce('0x2a'),closeHandler);_0x22b39d['on']('timeout',timeoutHandler);_0x22b39d[_0x05ce('0x2b')]=![];_0x22b39d['on'](_0x05ce('0x2c'),hangupHandler);var _0x1824b1=_['find'](projects,[_0x05ce('0x15'),_0x22b39d[_0x05ce('0x19')]]);if(!_0x1824b1)return Project[_0x05ce('0x2d')](_0x22b39d);if(!_0x1824b1[_0x05ce('0x2e')])return Project['handleUnpublished'](_0x22b39d);return Project[_0x05ce('0x2f')](_0x1824b1,_0x22b39d);}function main(){var _0x18b23a;return utilLicense[_0x05ce('0x30')]()[_0x05ce('0x21')](function(_0x2e9423){if(!_0x2e9423)return;if(_0x2e9423[_0x05ce('0x31')]){if(_0x2e9423[_0x05ce('0x32')]&&_0x2e9423[_0x05ce('0x32')]>0x0){logger['info'](util[_0x05ce('0x13')](_0x05ce('0x33'),_0x2e9423[_0x05ce('0x32')]));_0x18b23a=_0x2e9423[_0x05ce('0x32')];}else{logger['info'](_0x05ce('0x34'));}}else{logger[_0x05ce('0x1c')](_0x05ce('0x35'));_0x18b23a=-0x1;}})[_0x05ce('0x21')](function(){return Project[_0x05ce('0x36')]();})[_0x05ce('0x21')](function(_0x599eb7){projects=_0x599eb7;return;})['catch'](function(_0x1f2205){logger[_0x05ce('0x10')](_0x05ce('0x37'),_0x1f2205['stack']);})[_0x05ce('0x38')](function(){var _0x252576=require('./server')(config[_0x05ce('0x3')][_0x05ce('0x12')],config[_0x05ce('0x3')]['ip'],_0x18b23a);_0x252576['on']('error',errorHandler);_0x252576['on'](_0x05ce('0x39'),listeningHandler);_0x252576['on'](_0x05ce('0x3a'),connectionHandler);_0x252576['on'](_0x05ce('0x2a'),closeHandler);});}main();