Built motion from commit 44b1f254.|2.6.26
[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 _0x4b07=['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','callerid','dnid','uniqueid','calleridname','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','then','catch','hasOwnProperty','indexOf','agi_','substring','variables','close','timeout','hangup','find','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','[LICENSE]','./server','listening','connection','syncho','../../config/environment','../../config/logger','agi','./project','defaults','127.0.0.1','projectUpdate','nextTick','error','findIndex','deleted','splice','stack','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x4b07,0x159));var _0x74b0=function(_0x3de96c,_0x16d992){_0x3de96c=_0x3de96c-0x0;var _0x2db40e=_0x4b07[_0x3de96c];return _0x2db40e;};'use strict';var _=require('lodash');var syncho=require(_0x74b0('0x0'));var util=require('util');var config=require(_0x74b0('0x1'));var logger=require(_0x74b0('0x2'))(_0x74b0('0x3'));var utilLicense=require('../../config/license/util');var rpc=require('./rpc');var Project=require(_0x74b0('0x4'));var AGIEmitter=require('./events')['EventEmitter'];var projects=[];config[_0x74b0('0x3')]=_[_0x74b0('0x5')](config[_0x74b0('0x3')],{'ip':_0x74b0('0x6'),'port':0x11dd});AGIEmitter['on'](_0x74b0('0x7'),projectUpdateHandler);function connectionHandler(_0x11223e){process[_0x74b0('0x8')](function(){syncho(function(){try{setChannelVariables(_0x11223e);agiHandler(_0x11223e);}catch(_0x58ea33){logger[_0x74b0('0x9')](_0x58ea33['stack']);}});});}function projectUpdateHandler(_0x16093a){try{var _0xe549ed=_[_0x74b0('0xa')](projects,['id',_0x16093a['id']]);if(_0xe549ed>-0x1){if(_0x16093a[_0x74b0('0xb')]===!![]){projects[_0x74b0('0xc')](_0xe549ed,0x1);}else{projects[_0xe549ed]=_0x16093a;}}else{projects['push'](_0x16093a);}}catch(_0x2edbd8){logger[_0x74b0('0x9')](_0x2edbd8[_0x74b0('0xd')]);}}function listeningHandler(){console[_0x74b0('0xe')](_0x74b0('0xf'),config[_0x74b0('0x3')][_0x74b0('0x10')]);logger['info'](util[_0x74b0('0x11')](_0x74b0('0x12'),config['agi']['ip'],config['agi'][_0x74b0('0x10')]));}function errorHandler(_0x5ce8b1){if(_0x5ce8b1&&_0x5ce8b1[_0x74b0('0x13')]&&_0x5ce8b1['message']){logger[_0x74b0('0x9')](util[_0x74b0('0x11')]('[%s]\x20%s',_0x5ce8b1['name'],_0x5ce8b1[_0x74b0('0x14')]));}else{logger[_0x74b0('0x9')](util[_0x74b0('0x11')](_0x74b0('0x15'),_0x5ce8b1[_0x74b0('0xd')]));}}function closeHandler(){logger[_0x74b0('0x16')](util[_0x74b0('0x11')](_0x74b0('0x17'),this[_0x74b0('0x18')],this['calleridname'],this[_0x74b0('0x19')],this[_0x74b0('0x1a')],this[_0x74b0('0x1b')]));try{createSquareReport(this);}catch(_0xfbb5b){logger['error'](_0xfbb5b[_0x74b0('0xd')]);}}function timeoutHandler(){logger[_0x74b0('0x16')](util[_0x74b0('0x11')]('[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0x74b0('0x18')],this[_0x74b0('0x1c')],this[_0x74b0('0x19')],this[_0x74b0('0x1a')],this[_0x74b0('0x1b')]));}function hangupHandler(){logger[_0x74b0('0x16')](util['format'](_0x74b0('0x1d'),this[_0x74b0('0x18')],this[_0x74b0('0x1c')],this[_0x74b0('0x19')],this['dnid'],this[_0x74b0('0x1b')]));this[_0x74b0('0x1e')]=!![];}function createSquareReport(_0x11ab7e,_0x3ebbec){rpc['createSquareReport'](_0x11ab7e)[_0x74b0('0x1f')](function(_0x205e4b){if(_0x3ebbec){_0x3ebbec(null,_0x205e4b);}})[_0x74b0('0x20')](function(_0x219fed){if(_0x3ebbec){_0x3ebbec(null,_0x219fed);}});}function setChannelVariables(_0x145488){for(var _0x28975a in _0x145488){if(_0x145488[_0x74b0('0x21')](_0x28975a)){if(_0x28975a[_0x74b0('0x22')](_0x74b0('0x23'))===0x0){_0x145488[_0x28975a[_0x74b0('0x24')](0x4)]=_0x145488[_0x28975a];delete _0x145488[_0x28975a];}}}}function agiHandler(_0x94280b){logger['debug'](_0x74b0('0x25'),JSON['stringify'](_0x94280b,null,0x2));logger[_0x74b0('0x16')](util[_0x74b0('0x11')]('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x94280b[_0x74b0('0x18')],_0x94280b[_0x74b0('0x1c')],_0x94280b[_0x74b0('0x19')],_0x94280b[_0x74b0('0x1a')],_0x94280b[_0x74b0('0x1b')]));_0x94280b['on'](_0x74b0('0x9'),errorHandler);_0x94280b['on'](_0x74b0('0x26'),closeHandler);_0x94280b['on'](_0x74b0('0x27'),timeoutHandler);_0x94280b[_0x74b0('0x1e')]=![];_0x94280b['on'](_0x74b0('0x28'),hangupHandler);var _0x2c6a19=_[_0x74b0('0x29')](projects,['name',_0x94280b['arg_1']]);if(!_0x2c6a19)return Project['handleNotFound'](_0x94280b);if(!_0x2c6a19['production'])return Project['handleUnpublished'](_0x94280b);return Project['initialize'](_0x2c6a19,_0x94280b);}function main(){var _0x5ecbce;return utilLicense[_0x74b0('0x2a')]()[_0x74b0('0x1f')](function(_0x1d9c93){if(!_0x1d9c93)return;if(_0x1d9c93[_0x74b0('0x2b')]){if(_0x1d9c93['callysquare']&&_0x1d9c93[_0x74b0('0x2c')]>0x0){logger[_0x74b0('0x16')](util[_0x74b0('0x11')](_0x74b0('0x2d'),_0x1d9c93['callysquare']));_0x5ecbce=_0x1d9c93[_0x74b0('0x2c')];}else{logger['info'](_0x74b0('0x2e'));}}else{logger['info'](_0x74b0('0x2f'));_0x5ecbce=-0x1;}})[_0x74b0('0x1f')](function(){return Project['getAll']();})[_0x74b0('0x1f')](function(_0x2b5dea){projects=_0x2b5dea;return;})[_0x74b0('0x20')](function(_0x13a1c8){logger[_0x74b0('0x9')](_0x74b0('0x30'),_0x13a1c8['stack']);})['finally'](function(){var _0x4351d8=require(_0x74b0('0x31'))(config[_0x74b0('0x3')][_0x74b0('0x10')],config[_0x74b0('0x3')]['ip'],_0x5ecbce);_0x4351d8['on']('error',errorHandler);_0x4351d8['on'](_0x74b0('0x32'),listeningHandler);_0x4351d8['on'](_0x74b0('0x33'),connectionHandler);_0x4351d8['on'](_0x74b0('0x26'),closeHandler);});}main();