Built motion from commit 9e1ec266.|2.6.28
[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 _0xba29=['AGI','wait','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','util','lodash','events','EventEmitter','./reply','./error','setEncoding','utf8','setTimeout','headers','ready','line','toLowerCase','hangup','search','function','replace','split','length','substring','match','error','E_AGI_SOCKET_ERROR','code','close','emit','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','pipe','write','destroy','sendRequest','command','sync','prototype','answer','ANSWER','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','VERBOSE\x20\x22%s\x22','isArray','EXEC\x20%s\x20%s','join','setContext','SET\x20EXTENSION\x20%s','setPriority','HANGUP','setVariable','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','sayNumber','SAY\x20NUMBER\x20%s\x20%s','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','setExtension','GOTO\x20%s\x20%s\x20%s','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','streamFile','agi','exec'];(function(_0x22dc81,_0x1f9066){var _0x2ccdba=function(_0x12cc15){while(--_0x12cc15){_0x22dc81['push'](_0x22dc81['shift']());}};_0x2ccdba(++_0x1f9066);}(_0xba29,0x9e));var _0x9ba2=function(_0x34febf,_0x48f9a5){_0x34febf=_0x34febf-0x0;var _0x73784a=_0xba29[_0x34febf];return _0x73784a;};'use strict';var util=require(_0x9ba2('0x0'));var _=require(_0x9ba2('0x1'));var EventEmitter=require(_0x9ba2('0x2'))[_0x9ba2('0x3')];var AGIReply=require(_0x9ba2('0x4'));var AGIError=require(_0x9ba2('0x5'));function AGIChannel(_0x5cdbb2){var _0x55d157=this,_0x4e8cc7=new AGIReply(),_0x27d3f5=![],_0x216ed9={};EventEmitter['call'](_0x55d157);_0x5cdbb2[_0x9ba2('0x6')](_0x9ba2('0x7'));_0x5cdbb2[_0x9ba2('0x8')](0x8*0x3c*0x3c*0x3e8);_0x4e8cc7[_0x9ba2('0x6')](_0x9ba2('0x7'));_0x4e8cc7['on'](_0x9ba2('0x9'),function(_0x1664b7){for(var _0x7b6458 in _0x1664b7){_0x55d157[_0x7b6458]=_0x1664b7[_0x7b6458];}_0x55d157['emit'](_0x9ba2('0xa'));});_0x4e8cc7['on'](_0x9ba2('0xb'),function(_0x156d4a){if(_0x156d4a[_0x9ba2('0xc')]()==_0x9ba2('0xd')){_0x55d157['emit'](_0x9ba2('0xd'));return;}if(_0x156d4a['substring'](0x0,0xb)=='520-Invalid'){_0x27d3f5=!![];}if(_0x27d3f5){_0x216ed9['rx']+=_0x156d4a+'\x0a';if(_0x156d4a[_0x9ba2('0xe')]('520\x20End\x20of\x20proper')!=-0x1){_0x27d3f5=![];}}else{_0x216ed9['rx']=_0x156d4a;}if(_0x27d3f5){return;}if(typeof _0x216ed9['cb']==_0x9ba2('0xf')){var _0x44849b=_0x216ed9['rx']['substring'](0x0,0x3),_0x83917a=null,_0x112800=null;_0x44849b=parseInt(_0x44849b);if(isNaN(_0x44849b)){_0x216ed9['cb'](null,{'code':0x1f4,'result':-0x1,'extra':'no\x20code'});return;}if(_0x44849b!=0xc8){_0x216ed9['cb'](null,{'code':_0x44849b,'result':-0x1,'extra':'KO'});return;}_0x83917a=_0x216ed9['rx']['substring'](0x4)[_0x9ba2('0x10')]('result=','');if(_0x83917a['indexOf']('\x20')!=-0x1){_0x83917a=_0x83917a['substr'](0x0,_0x83917a['indexOf']('\x20'));}if(_['startsWith'](_0x83917a,'-1')){_0x83917a=parseInt(_0x83917a);}_0x112800=_0x216ed9['rx'][_0x9ba2('0x11')]('\x20');if(_0x112800[_0x9ba2('0x12')]==0x3){_0x112800=_0x112800[0x2][_0x9ba2('0x13')](0x1,_0x112800[0x2][_0x9ba2('0x12')]-0x1);}else if(_0x112800[_0x9ba2('0x12')]>0x3){var _0x212aca=/\((.+)\)/;var _0x2c82ca=_0x216ed9['rx'][_0x9ba2('0x14')](_0x212aca);if(_0x2c82ca){_0x112800=_0x2c82ca[0x1];}else{_0x112800=null;}}else{_0x112800=null;}_0x216ed9['cb'](null,{'code':_0x44849b,'result':_0x83917a,'extra':_0x112800});}});_0x5cdbb2['on']('error',function(_0x55b47d){_0x55d157['emit'](_0x9ba2('0x15'),new AGIError(_0x9ba2('0x16'),_0x55b47d[_0x9ba2('0x17')]));});_0x5cdbb2['on'](_0x9ba2('0x18'),function(){_0x55d157[_0x9ba2('0x19')](_0x9ba2('0x18'),new AGIError(_0x9ba2('0x1a')));});_0x5cdbb2['on'](_0x9ba2('0x1b'),function(){_0x55d157['emit']('timeout',new AGIError(_0x9ba2('0x1c')));_0x5cdbb2['destroy']();});_0x5cdbb2[_0x9ba2('0x1d')](_0x4e8cc7);this['command']=function(_0x35c587,_0x145866){var _0x35c587=_0x35c587||'',_0x145866=typeof _0x145866==_0x9ba2('0xf')?_0x145866:new Function();_0x216ed9={'tx':_0x35c587,'rx':'','cb':_0x145866};_0x5cdbb2[_0x9ba2('0x1e')](_0x35c587+'\x0a');},this[_0x9ba2('0x18')]=function(){_0x5cdbb2[_0x9ba2('0x1f')]();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel['prototype'][_0x9ba2('0x20')]=function(_0x470d6f){return this[_0x9ba2('0x21')][_0x9ba2('0x22')](this,_0x470d6f);};AGIChannel[_0x9ba2('0x23')][_0x9ba2('0x24')]=function(){return this[_0x9ba2('0x20')](_0x9ba2('0x25'));};AGIChannel['prototype']['getData']=function(_0x324c59,_0x1158db,_0x1a6fd7){_0x324c59=_0x324c59===undefined?'beep':_0x324c59;_0x1158db=_0x1158db===undefined?'5':_0x1158db;_0x1a6fd7=_0x1a6fd7===undefined?'1':_0x1a6fd7;return this['sendRequest'](util[_0x9ba2('0x26')](_0x9ba2('0x27'),_0x324c59,_0x1158db*0x3e8,_0x1a6fd7));};AGIChannel[_0x9ba2('0x23')][_0x9ba2('0x28')]=function(_0x1b3869){_0x1b3869=_0x1b3869||'NO\x20MESSAGE';return this[_0x9ba2('0x20')](util[_0x9ba2('0x26')](_0x9ba2('0x29'),_0x1b3869));};AGIChannel['prototype']['exec']=function(_0x7a51bd,_0x35f7c9){if(_[_0x9ba2('0x2a')](_0x35f7c9)){return this[_0x9ba2('0x20')](util[_0x9ba2('0x26')](_0x9ba2('0x2b'),_0x7a51bd,_0x35f7c9[_0x9ba2('0x2c')](',')));}return this[_0x9ba2('0x20')](util[_0x9ba2('0x26')](_0x9ba2('0x2b'),_0x7a51bd,_0x35f7c9));};AGIChannel[_0x9ba2('0x23')][_0x9ba2('0x2d')]=function(_0x2e4018){return this['sendRequest'](util[_0x9ba2('0x26')]('SET\x20CONTEXT\x20%s',_0x2e4018));};AGIChannel[_0x9ba2('0x23')]['setExtension']=function(_0x244732){return this[_0x9ba2('0x20')](util['format'](_0x9ba2('0x2e'),_0x244732));};AGIChannel['prototype'][_0x9ba2('0x2f')]=function(_0x35f7c5){return this[_0x9ba2('0x20')](util[_0x9ba2('0x26')]('SET\x20PRIORITY\x20%s',_0x35f7c5));};AGIChannel[_0x9ba2('0x23')][_0x9ba2('0xd')]=function(){return this['sendRequest'](_0x9ba2('0x30'));};AGIChannel[_0x9ba2('0x23')][_0x9ba2('0x31')]=function(_0xcf4768,_0x122c44){var _0x21b992=_['isBoolean'](_0x122c44)||_[_0x9ba2('0x32')](_0x122c44)?_0x122c44[_0x9ba2('0x33')]():_0x122c44;return this[_0x9ba2('0x20')](util['format'](_0x9ba2('0x34'),_0xcf4768,_0x21b992?_0x21b992['toString']()[_0x9ba2('0x10')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel['prototype'][_0x9ba2('0x35')]=function(_0x5c79a4,_0x1e7b84){return this['sendRequest'](util[_0x9ba2('0x26')](_0x9ba2('0x36'),_0x5c79a4,_0x1e7b84));};AGIChannel[_0x9ba2('0x23')]['sayDigits']=function(_0x2a4e3d,_0x307685){return this['sendRequest'](util[_0x9ba2('0x26')](_0x9ba2('0x37'),_0x2a4e3d,_0x307685));};AGIChannel[_0x9ba2('0x23')][_0x9ba2('0x38')]=function(_0x30a766,_0x3abee5){return this['sendRequest'](util['format'](_0x9ba2('0x39'),_0x30a766,_0x3abee5));};AGIChannel[_0x9ba2('0x23')][_0x9ba2('0x3a')]=function(_0x66c892,_0x249136,_0x367c8a){_0x249136=_0x249136||this[_0x9ba2('0x3b')];_0x367c8a=_0x367c8a||0x1;this[_0x9ba2('0x2d')](_0x66c892);this[_0x9ba2('0x3c')](_0x249136);this[_0x9ba2('0x2f')](_0x367c8a);return this[_0x9ba2('0x28')](util[_0x9ba2('0x26')](_0x9ba2('0x3d'),_0x66c892,_0x249136,_0x367c8a));};AGIChannel['prototype']['getVariable']=function(_0x157f46){return this[_0x9ba2('0x20')](util[_0x9ba2('0x26')](_0x9ba2('0x3e'),_0x157f46));};AGIChannel['prototype'][_0x9ba2('0x3f')]=function(_0x3715e2,_0x1e7ed5,_0x466156,_0x1f6f63,_0x4a8623,_0x4890a7){_0x1e7ed5=_0x1e7ed5||_0x9ba2('0x40');_0x466156=_0x466156||'';_0x1f6f63=_0x1f6f63===undefined?-0x1:_0x1f6f63==='-1'?-0x1:_0x1f6f63*0x3e8;_0x4a8623=_0x4a8623===undefined?'':'s='+_0x4a8623;_0x4890a7=_0x4890a7?_0x9ba2('0x41'):'';return this['sendRequest'](util[_0x9ba2('0x26')](_0x9ba2('0x42'),_0x3715e2,_0x1e7ed5,_0x466156,_0x1f6f63,_0x4890a7,_0x4a8623));};AGIChannel['prototype'][_0x9ba2('0x43')]=function(_0x2bc253,_0x1e8a51){_0x1e8a51=_0x1e8a51||'';return this[_0x9ba2('0x20')](util[_0x9ba2('0x26')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x2bc253,_0x1e8a51));};AGIChannel['prototype'][_0x9ba2('0x44')]=function(_0xedfb82){return this[_0x9ba2('0x45')](_0x9ba2('0x46'),_0xedfb82);};AGIChannel[_0x9ba2('0x23')][_0x9ba2('0x47')]=function(_0x5dc61b){return this['exec'](_0x9ba2('0x48'),_0x5dc61b);};AGIChannel[_0x9ba2('0x23')][_0x9ba2('0x15')]=function(_0x485367,_0x28610c){this['noop'](util[_0x9ba2('0x26')](_0x9ba2('0x49'),_0x485367['id'],_0x485367[_0x9ba2('0x4a')],_0x28610c));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x9ba2('0x4b')]=AGIChannel;