Built motion from commit 10af8726.|2.6.34
[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 _0x3ec7=['substring','search','function','no\x20code','replace','result=','indexOf','substr','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','command','write','prototype','sendRequest','sync','answer','ANSWER','getData','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','format','exec','isArray','EXEC\x20%s\x20%s','join','setContext','SET\x20CONTEXT\x20%s','SET\x20EXTENSION\x20%s','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isBoolean','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','continueAt','extension','setExtension','GET\x20VARIABLE\x20\x22%s\x22','recordFile','wav','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','AGI','wait','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','util','lodash','events','EventEmitter','./reply','./error','call','setEncoding','utf8','setTimeout','emit','hangup'];(function(_0x86f46,_0x505656){var _0x2a6d08=function(_0x2bc67f){while(--_0x2bc67f){_0x86f46['push'](_0x86f46['shift']());}};_0x2a6d08(++_0x505656);}(_0x3ec7,0xd5));var _0x73ec=function(_0x45bafa,_0x1caa2a){_0x45bafa=_0x45bafa-0x0;var _0x44b30a=_0x3ec7[_0x45bafa];return _0x44b30a;};'use strict';var util=require(_0x73ec('0x0'));var _=require(_0x73ec('0x1'));var EventEmitter=require(_0x73ec('0x2'))[_0x73ec('0x3')];var AGIReply=require(_0x73ec('0x4'));var AGIError=require(_0x73ec('0x5'));function AGIChannel(_0x249da6){var _0x38b07a=this,_0x16f7d9=new AGIReply(),_0xd22f9f=![],_0x1dbe3b={};EventEmitter[_0x73ec('0x6')](_0x38b07a);_0x249da6[_0x73ec('0x7')](_0x73ec('0x8'));_0x249da6[_0x73ec('0x9')](0x8*0x3c*0x3c*0x3e8);_0x16f7d9['setEncoding'](_0x73ec('0x8'));_0x16f7d9['on']('headers',function(_0x3e1787){for(var _0x1187ed in _0x3e1787){_0x38b07a[_0x1187ed]=_0x3e1787[_0x1187ed];}_0x38b07a[_0x73ec('0xa')]('ready');});_0x16f7d9['on']('line',function(_0x2e36dc){if(_0x2e36dc['toLowerCase']()==_0x73ec('0xb')){_0x38b07a[_0x73ec('0xa')](_0x73ec('0xb'));return;}if(_0x2e36dc[_0x73ec('0xc')](0x0,0xb)=='520-Invalid'){_0xd22f9f=!![];}if(_0xd22f9f){_0x1dbe3b['rx']+=_0x2e36dc+'\x0a';if(_0x2e36dc[_0x73ec('0xd')]('520\x20End\x20of\x20proper')!=-0x1){_0xd22f9f=![];}}else{_0x1dbe3b['rx']=_0x2e36dc;}if(_0xd22f9f){return;}if(typeof _0x1dbe3b['cb']==_0x73ec('0xe')){var _0x26ce48=_0x1dbe3b['rx'][_0x73ec('0xc')](0x0,0x3),_0x37d931=null,_0xae6f7a=null;_0x26ce48=parseInt(_0x26ce48);if(isNaN(_0x26ce48)){_0x1dbe3b['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x73ec('0xf')});return;}if(_0x26ce48!=0xc8){_0x1dbe3b['cb'](null,{'code':_0x26ce48,'result':-0x1,'extra':'KO'});return;}_0x37d931=_0x1dbe3b['rx']['substring'](0x4)[_0x73ec('0x10')](_0x73ec('0x11'),'');if(_0x37d931[_0x73ec('0x12')]('\x20')!=-0x1){_0x37d931=_0x37d931[_0x73ec('0x13')](0x0,_0x37d931[_0x73ec('0x12')]('\x20'));}if(_[_0x73ec('0x14')](_0x37d931,'-1')){_0x37d931=parseInt(_0x37d931);}_0xae6f7a=_0x1dbe3b['rx'][_0x73ec('0x15')]('\x20');if(_0xae6f7a[_0x73ec('0x16')]==0x3){_0xae6f7a=_0xae6f7a[0x2][_0x73ec('0xc')](0x1,_0xae6f7a[0x2][_0x73ec('0x16')]-0x1);}else if(_0xae6f7a[_0x73ec('0x16')]>0x3){var _0x30f723=/\((.+)\)/;var _0x3020de=_0x1dbe3b['rx'][_0x73ec('0x17')](_0x30f723);if(_0x3020de){_0xae6f7a=_0x3020de[0x1];}else{_0xae6f7a=null;}}else{_0xae6f7a=null;}_0x1dbe3b['cb'](null,{'code':_0x26ce48,'result':_0x37d931,'extra':_0xae6f7a});}});_0x249da6['on'](_0x73ec('0x18'),function(_0x38d22a){_0x38b07a['emit'](_0x73ec('0x18'),new AGIError(_0x73ec('0x19'),_0x38d22a[_0x73ec('0x1a')]));});_0x249da6['on']('close',function(){_0x38b07a[_0x73ec('0xa')](_0x73ec('0x1b'),new AGIError(_0x73ec('0x1c')));});_0x249da6['on']('timeout',function(){_0x38b07a[_0x73ec('0xa')](_0x73ec('0x1d'),new AGIError(_0x73ec('0x1e')));_0x249da6[_0x73ec('0x1f')]();});_0x249da6[_0x73ec('0x20')](_0x16f7d9);this[_0x73ec('0x21')]=function(_0x1d57f,_0x5756a1){var _0x1d57f=_0x1d57f||'',_0x5756a1=typeof _0x5756a1==_0x73ec('0xe')?_0x5756a1:new Function();_0x1dbe3b={'tx':_0x1d57f,'rx':'','cb':_0x5756a1};_0x249da6[_0x73ec('0x22')](_0x1d57f+'\x0a');},this[_0x73ec('0x1b')]=function(){_0x249da6['destroy']();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel[_0x73ec('0x23')][_0x73ec('0x24')]=function(_0x2f6d1f){return this[_0x73ec('0x21')][_0x73ec('0x25')](this,_0x2f6d1f);};AGIChannel['prototype'][_0x73ec('0x26')]=function(){return this['sendRequest'](_0x73ec('0x27'));};AGIChannel[_0x73ec('0x23')][_0x73ec('0x28')]=function(_0x934e17,_0x596b78,_0x5e091f){_0x934e17=_0x934e17===undefined?'beep':_0x934e17;_0x596b78=_0x596b78===undefined?'5':_0x596b78;_0x5e091f=_0x5e091f===undefined?'1':_0x5e091f;return this['sendRequest'](util['format'](_0x73ec('0x29'),_0x934e17,_0x596b78*0x3e8,_0x5e091f));};AGIChannel[_0x73ec('0x23')][_0x73ec('0x2a')]=function(_0x27546b){_0x27546b=_0x27546b||'NO\x20MESSAGE';return this[_0x73ec('0x24')](util[_0x73ec('0x2b')]('VERBOSE\x20\x22%s\x22',_0x27546b));};AGIChannel[_0x73ec('0x23')][_0x73ec('0x2c')]=function(_0x4d2f1c,_0x1c966d){if(_[_0x73ec('0x2d')](_0x1c966d)){return this[_0x73ec('0x24')](util[_0x73ec('0x2b')](_0x73ec('0x2e'),_0x4d2f1c,_0x1c966d[_0x73ec('0x2f')](',')));}return this['sendRequest'](util[_0x73ec('0x2b')](_0x73ec('0x2e'),_0x4d2f1c,_0x1c966d));};AGIChannel[_0x73ec('0x23')][_0x73ec('0x30')]=function(_0x4a0725){return this['sendRequest'](util[_0x73ec('0x2b')](_0x73ec('0x31'),_0x4a0725));};AGIChannel[_0x73ec('0x23')]['setExtension']=function(_0x21da9c){return this[_0x73ec('0x24')](util[_0x73ec('0x2b')](_0x73ec('0x32'),_0x21da9c));};AGIChannel[_0x73ec('0x23')]['setPriority']=function(_0x30cba4){return this[_0x73ec('0x24')](util[_0x73ec('0x2b')](_0x73ec('0x33'),_0x30cba4));};AGIChannel[_0x73ec('0x23')]['hangup']=function(){return this[_0x73ec('0x24')](_0x73ec('0x34'));};AGIChannel[_0x73ec('0x23')][_0x73ec('0x35')]=function(_0x104f59,_0x365a95){var _0x1f616b=_[_0x73ec('0x36')](_0x365a95)||_[_0x73ec('0x37')](_0x365a95)?_0x365a95[_0x73ec('0x38')]():_0x365a95;return this[_0x73ec('0x24')](util[_0x73ec('0x2b')](_0x73ec('0x39'),_0x104f59,_0x1f616b?_0x1f616b[_0x73ec('0x38')]()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x73ec('0x23')]['sayNumber']=function(_0x2793a0,_0x33a141){return this[_0x73ec('0x24')](util[_0x73ec('0x2b')]('SAY\x20NUMBER\x20%s\x20%s',_0x2793a0,_0x33a141));};AGIChannel[_0x73ec('0x23')]['sayDigits']=function(_0x40f8c2,_0x2fbe0c){return this[_0x73ec('0x24')](util[_0x73ec('0x2b')](_0x73ec('0x3a'),_0x40f8c2,_0x2fbe0c));};AGIChannel[_0x73ec('0x23')][_0x73ec('0x3b')]=function(_0x2c9666,_0x306be0){return this['sendRequest'](util[_0x73ec('0x2b')]('SAY\x20PHONETIC\x20\x22%s\x22\x20%s',_0x2c9666,_0x306be0));};AGIChannel[_0x73ec('0x23')][_0x73ec('0x3c')]=function(_0x8ed6dd,_0x4bfeea,_0x36997a){_0x4bfeea=_0x4bfeea||this[_0x73ec('0x3d')];_0x36997a=_0x36997a||0x1;this['setContext'](_0x8ed6dd);this[_0x73ec('0x3e')](_0x4bfeea);this['setPriority'](_0x36997a);return this[_0x73ec('0x2a')](util[_0x73ec('0x2b')]('GOTO\x20%s\x20%s\x20%s',_0x8ed6dd,_0x4bfeea,_0x36997a));};AGIChannel[_0x73ec('0x23')]['getVariable']=function(_0x33ad07){return this[_0x73ec('0x24')](util[_0x73ec('0x2b')](_0x73ec('0x3f'),_0x33ad07));};AGIChannel['prototype'][_0x73ec('0x40')]=function(_0x14069d,_0x29d260,_0x474be1,_0x3851c0,_0x1a059e,_0x519f51){_0x29d260=_0x29d260||_0x73ec('0x41');_0x474be1=_0x474be1||'';_0x3851c0=_0x3851c0===undefined?-0x1:_0x3851c0==='-1'?-0x1:_0x3851c0*0x3e8;_0x1a059e=_0x1a059e===undefined?'':'s='+_0x1a059e;_0x519f51=_0x519f51?_0x73ec('0x42'):'';return this[_0x73ec('0x24')](util[_0x73ec('0x2b')](_0x73ec('0x43'),_0x14069d,_0x29d260,_0x474be1,_0x3851c0,_0x519f51,_0x1a059e));};AGIChannel[_0x73ec('0x23')]['streamFile']=function(_0x2d43be,_0x1703f0){_0x1703f0=_0x1703f0||'';return this[_0x73ec('0x24')](util[_0x73ec('0x2b')](_0x73ec('0x44'),_0x2d43be,_0x1703f0));};AGIChannel[_0x73ec('0x23')]['agi']=function(_0x3c3498){return this[_0x73ec('0x2c')](_0x73ec('0x45'),_0x3c3498);};AGIChannel[_0x73ec('0x23')][_0x73ec('0x46')]=function(_0x9d1a3a){return this[_0x73ec('0x2c')](_0x73ec('0x47'),_0x9d1a3a);};AGIChannel['prototype'][_0x73ec('0x18')]=function(_0x15b1d0,_0x41b3a2){this[_0x73ec('0x2a')](util[_0x73ec('0x2b')](_0x73ec('0x48'),_0x15b1d0['id'],_0x15b1d0[_0x73ec('0x49')],_0x41b3a2));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x73ec('0x4a')]=AGIChannel;