Built motion from commit (unavailable).|2.2.0
[motion2.git] / server / services / agi / channel.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 _0xdb5a=['length','match','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','pipe','command','function','write','destroy','prototype','answer','ANSWER','getData','beep','sendRequest','format','noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','isArray','EXEC\x20%s\x20%s','setContext','SET\x20CONTEXT\x20%s','setExtension','setPriority','SET\x20PRIORITY\x20%s','HANGUP','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','sayNumber','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','GOTO\x20%s\x20%s\x20%s','GET\x20VARIABLE\x20\x22%s\x22','recordFile','wav','BEEP','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','AGI','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','exports','lodash','events','EventEmitter','./reply','./error','call','setEncoding','utf8','setTimeout','headers','ready','line','toLowerCase','emit','hangup','substring','520-Invalid','520\x20End\x20of\x20proper','no\x20code','replace','result=','indexOf','substr','startsWith','split'];(function(_0x284a61,_0x231686){var _0x220e3c=function(_0x104496){while(--_0x104496){_0x284a61['push'](_0x284a61['shift']());}};_0x220e3c(++_0x231686);}(_0xdb5a,0x11b));var _0xadb5=function(_0x33f70d,_0x4e493d){_0x33f70d=_0x33f70d-0x0;var _0x1a87bb=_0xdb5a[_0x33f70d];return _0x1a87bb;};'use strict';var util=require('util');var _=require(_0xadb5('0x0'));var EventEmitter=require(_0xadb5('0x1'))[_0xadb5('0x2')];var AGIReply=require(_0xadb5('0x3'));var AGIError=require(_0xadb5('0x4'));function AGIChannel(_0x1ea855){var _0x43e921=this,_0x4ff339=new AGIReply(),_0x3d4ffb=![],_0x4b36d3={};EventEmitter[_0xadb5('0x5')](_0x43e921);_0x1ea855[_0xadb5('0x6')](_0xadb5('0x7'));_0x1ea855[_0xadb5('0x8')](0x8*0x3c*0x3c*0x3e8);_0x4ff339[_0xadb5('0x6')](_0xadb5('0x7'));_0x4ff339['on'](_0xadb5('0x9'),function(_0x9575a1){for(var _0x2c3b30 in _0x9575a1){_0x43e921[_0x2c3b30]=_0x9575a1[_0x2c3b30];}_0x43e921['emit'](_0xadb5('0xa'));});_0x4ff339['on'](_0xadb5('0xb'),function(_0x146e6b){if(_0x146e6b[_0xadb5('0xc')]()=='hangup'){_0x43e921[_0xadb5('0xd')](_0xadb5('0xe'));return;}if(_0x146e6b[_0xadb5('0xf')](0x0,0xb)==_0xadb5('0x10')){_0x3d4ffb=!![];}if(_0x3d4ffb){_0x4b36d3['rx']+=_0x146e6b+'\x0a';if(_0x146e6b['search'](_0xadb5('0x11'))!=-0x1){_0x3d4ffb=![];}}else{_0x4b36d3['rx']=_0x146e6b;}if(_0x3d4ffb){return;}if(typeof _0x4b36d3['cb']=='function'){var _0x58bcd9=_0x4b36d3['rx'][_0xadb5('0xf')](0x0,0x3),_0x231e86=null,_0x35963d=null;_0x58bcd9=parseInt(_0x58bcd9);if(isNaN(_0x58bcd9)){_0x4b36d3['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xadb5('0x12')});return;}if(_0x58bcd9!=0xc8){_0x4b36d3['cb'](null,{'code':_0x58bcd9,'result':-0x1,'extra':'KO'});return;}_0x231e86=_0x4b36d3['rx']['substring'](0x4)[_0xadb5('0x13')](_0xadb5('0x14'),'');if(_0x231e86[_0xadb5('0x15')]('\x20')!=-0x1){_0x231e86=_0x231e86[_0xadb5('0x16')](0x0,_0x231e86[_0xadb5('0x15')]('\x20'));}if(_[_0xadb5('0x17')](_0x231e86,'-1')){_0x231e86=parseInt(_0x231e86);}_0x35963d=_0x4b36d3['rx'][_0xadb5('0x18')]('\x20');if(_0x35963d['length']==0x3){_0x35963d=_0x35963d[0x2][_0xadb5('0xf')](0x1,_0x35963d[0x2]['length']-0x1);}else if(_0x35963d[_0xadb5('0x19')]>0x3){var _0x3d16bf=/\((.+)\)/;var _0x3e22e4=_0x4b36d3['rx'][_0xadb5('0x1a')](_0x3d16bf);if(_0x3e22e4){_0x35963d=_0x3e22e4[0x1];}else{_0x35963d=null;}}else{_0x35963d=null;}_0x4b36d3['cb'](null,{'code':_0x58bcd9,'result':_0x231e86,'extra':_0x35963d});}});_0x1ea855['on'](_0xadb5('0x1b'),function(_0x29b76b){_0x43e921[_0xadb5('0xd')](_0xadb5('0x1b'),new AGIError(_0xadb5('0x1c'),_0x29b76b[_0xadb5('0x1d')]));});_0x1ea855['on'](_0xadb5('0x1e'),function(){_0x43e921[_0xadb5('0xd')]('close',new AGIError(_0xadb5('0x1f')));});_0x1ea855['on'](_0xadb5('0x20'),function(){_0x43e921[_0xadb5('0xd')]('timeout',new AGIError(_0xadb5('0x21')));_0x1ea855['destroy']();});_0x1ea855[_0xadb5('0x22')](_0x4ff339);this[_0xadb5('0x23')]=function(_0x104a66,_0x3f370d){var _0x104a66=_0x104a66||'',_0x3f370d=typeof _0x3f370d==_0xadb5('0x24')?_0x3f370d:new Function();_0x4b36d3={'tx':_0x104a66,'rx':'','cb':_0x3f370d};_0x1ea855[_0xadb5('0x25')](_0x104a66+'\x0a');},this['close']=function(){_0x1ea855[_0xadb5('0x26')]();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel[_0xadb5('0x27')]['sendRequest']=function(_0x358177){return this[_0xadb5('0x23')]['sync'](this,_0x358177);};AGIChannel['prototype'][_0xadb5('0x28')]=function(){return this['sendRequest'](_0xadb5('0x29'));};AGIChannel[_0xadb5('0x27')][_0xadb5('0x2a')]=function(_0x37563b,_0x490192,_0x2fe33d){_0x37563b=_0x37563b===undefined?_0xadb5('0x2b'):_0x37563b;_0x490192=_0x490192===undefined?'5':_0x490192;_0x2fe33d=_0x2fe33d===undefined?'1':_0x2fe33d;return this[_0xadb5('0x2c')](util[_0xadb5('0x2d')]('GET\x20DATA\x20\x22%s\x22\x20%s\x20%s',_0x37563b,_0x490192*0x3e8,_0x2fe33d));};AGIChannel['prototype'][_0xadb5('0x2e')]=function(_0x2b1e1c){_0x2b1e1c=_0x2b1e1c||_0xadb5('0x2f');return this[_0xadb5('0x2c')](util[_0xadb5('0x2d')](_0xadb5('0x30'),_0x2b1e1c));};AGIChannel[_0xadb5('0x27')][_0xadb5('0x31')]=function(_0x2dc04e,_0x5666b6){if(_[_0xadb5('0x32')](_0x5666b6)){return this['sendRequest'](util[_0xadb5('0x2d')](_0xadb5('0x33'),_0x2dc04e,_0x5666b6['join'](',')));}return this['sendRequest'](util[_0xadb5('0x2d')](_0xadb5('0x33'),_0x2dc04e,_0x5666b6));};AGIChannel[_0xadb5('0x27')][_0xadb5('0x34')]=function(_0x38f092){return this['sendRequest'](util[_0xadb5('0x2d')](_0xadb5('0x35'),_0x38f092));};AGIChannel[_0xadb5('0x27')][_0xadb5('0x36')]=function(_0x1ab799){return this['sendRequest'](util[_0xadb5('0x2d')]('SET\x20EXTENSION\x20%s',_0x1ab799));};AGIChannel[_0xadb5('0x27')][_0xadb5('0x37')]=function(_0x1e434b){return this[_0xadb5('0x2c')](util['format'](_0xadb5('0x38'),_0x1e434b));};AGIChannel['prototype'][_0xadb5('0xe')]=function(){return this[_0xadb5('0x2c')](_0xadb5('0x39'));};AGIChannel[_0xadb5('0x27')]['setVariable']=function(_0x349865,_0x316dbe){return this['sendRequest'](util[_0xadb5('0x2d')](_0xadb5('0x3a'),_0x349865,_0x316dbe?_0x316dbe[_0xadb5('0x3b')]()[_0xadb5('0x13')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xadb5('0x27')][_0xadb5('0x3c')]=function(_0x37cc2f,_0x3fabdb){return this[_0xadb5('0x2c')](util['format']('SAY\x20NUMBER\x20%s\x20%s',_0x37cc2f,_0x3fabdb));};AGIChannel['prototype'][_0xadb5('0x3d')]=function(_0x494811,_0x5254a8){return this[_0xadb5('0x2c')](util[_0xadb5('0x2d')](_0xadb5('0x3e'),_0x494811,_0x5254a8));};AGIChannel[_0xadb5('0x27')][_0xadb5('0x3f')]=function(_0x1071aa,_0x4b670e){return this[_0xadb5('0x2c')](util[_0xadb5('0x2d')](_0xadb5('0x40'),_0x1071aa,_0x4b670e));};AGIChannel[_0xadb5('0x27')][_0xadb5('0x41')]=function(_0x22e6c8,_0x5b88ff,_0x1d75bc){_0x5b88ff=_0x5b88ff||this[_0xadb5('0x42')];_0x1d75bc=_0x1d75bc||0x1;this[_0xadb5('0x34')](_0x22e6c8);this[_0xadb5('0x36')](_0x5b88ff);this['setPriority'](_0x1d75bc);return this[_0xadb5('0x2e')](util[_0xadb5('0x2d')](_0xadb5('0x43'),_0x22e6c8,_0x5b88ff,_0x1d75bc));};AGIChannel['prototype']['getVariable']=function(_0x6b31a5){return this['sendRequest'](util[_0xadb5('0x2d')](_0xadb5('0x44'),_0x6b31a5));};AGIChannel['prototype'][_0xadb5('0x45')]=function(_0x4058da,_0x3c0398,_0x5c651e,_0x55e06d,_0x10d6ff,_0x35b078){_0x3c0398=_0x3c0398||_0xadb5('0x46');_0x5c651e=_0x5c651e||'';_0x55e06d=_0x55e06d===undefined?-0x1:_0x55e06d==='-1'?-0x1:_0x55e06d*0x3e8;_0x10d6ff=_0x10d6ff===undefined?'':'s='+_0x10d6ff;_0x35b078=_0x35b078?_0xadb5('0x47'):'';return this[_0xadb5('0x2c')](util[_0xadb5('0x2d')]('RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s',_0x4058da,_0x3c0398,_0x5c651e,_0x55e06d,_0x35b078,_0x10d6ff));};AGIChannel[_0xadb5('0x27')]['streamFile']=function(_0x46e35e,_0x3c2361){_0x3c2361=_0x3c2361||'';return this[_0xadb5('0x2c')](util[_0xadb5('0x2d')](_0xadb5('0x48'),_0x46e35e,_0x3c2361));};AGIChannel[_0xadb5('0x27')]['agi']=function(_0x3aa68f){return this[_0xadb5('0x31')](_0xadb5('0x49'),_0x3aa68f);};AGIChannel[_0xadb5('0x27')]['wait']=function(_0xf717bb){return this[_0xadb5('0x31')](_0xadb5('0x4a'),_0xf717bb);};AGIChannel['prototype'][_0xadb5('0x1b')]=function(_0x37f2e5,_0x36654f){this['noop'](util[_0xadb5('0x2d')](_0xadb5('0x4b'),_0x37f2e5['id'],_0x37f2e5['label'],_0x36654f));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xadb5('0x4c')]=AGIChannel;