Built motion from commit 97f2f211.|2.6.31
[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 _0x29b1=['code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','command','destroy','prototype','sync','answer','ANSWER','sendRequest','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','isArray','EXEC\x20%s\x20%s','join','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','hangup','HANGUP','isBoolean','SET\x20VARIABLE\x20%s\x20\x22%s\x22','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','extension','setContext','GOTO\x20%s\x20%s\x20%s','GET\x20VARIABLE\x20\x22%s\x22','BEEP','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','lodash','./error','call','setEncoding','setTimeout','utf8','headers','ready','line','toLowerCase','emit','substring','520\x20End\x20of\x20proper','replace','result=','indexOf','substr','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR'];(function(_0x1467d7,_0x33654c){var _0x5280e4=function(_0x3771d1){while(--_0x3771d1){_0x1467d7['push'](_0x1467d7['shift']());}};_0x5280e4(++_0x33654c);}(_0x29b1,0xbb));var _0x129b=function(_0x341e0f,_0x4a09d0){_0x341e0f=_0x341e0f-0x0;var _0x59555a=_0x29b1[_0x341e0f];return _0x59555a;};'use strict';var util=require('util');var _=require(_0x129b('0x0'));var EventEmitter=require('events')['EventEmitter'];var AGIReply=require('./reply');var AGIError=require(_0x129b('0x1'));function AGIChannel(_0x3a13a5){var _0x340c01=this,_0x54a38b=new AGIReply(),_0x1e6cd4=![],_0xb4ee0e={};EventEmitter[_0x129b('0x2')](_0x340c01);_0x3a13a5[_0x129b('0x3')]('utf8');_0x3a13a5[_0x129b('0x4')](0x8*0x3c*0x3c*0x3e8);_0x54a38b[_0x129b('0x3')](_0x129b('0x5'));_0x54a38b['on'](_0x129b('0x6'),function(_0x5e066f){for(var _0x481318 in _0x5e066f){_0x340c01[_0x481318]=_0x5e066f[_0x481318];}_0x340c01['emit'](_0x129b('0x7'));});_0x54a38b['on'](_0x129b('0x8'),function(_0x5675e9){if(_0x5675e9[_0x129b('0x9')]()=='hangup'){_0x340c01[_0x129b('0xa')]('hangup');return;}if(_0x5675e9[_0x129b('0xb')](0x0,0xb)=='520-Invalid'){_0x1e6cd4=!![];}if(_0x1e6cd4){_0xb4ee0e['rx']+=_0x5675e9+'\x0a';if(_0x5675e9['search'](_0x129b('0xc'))!=-0x1){_0x1e6cd4=![];}}else{_0xb4ee0e['rx']=_0x5675e9;}if(_0x1e6cd4){return;}if(typeof _0xb4ee0e['cb']=='function'){var _0x14bb9e=_0xb4ee0e['rx'][_0x129b('0xb')](0x0,0x3),_0x2d91ae=null,_0x9c34e9=null;_0x14bb9e=parseInt(_0x14bb9e);if(isNaN(_0x14bb9e)){_0xb4ee0e['cb'](null,{'code':0x1f4,'result':-0x1,'extra':'no\x20code'});return;}if(_0x14bb9e!=0xc8){_0xb4ee0e['cb'](null,{'code':_0x14bb9e,'result':-0x1,'extra':'KO'});return;}_0x2d91ae=_0xb4ee0e['rx'][_0x129b('0xb')](0x4)[_0x129b('0xd')](_0x129b('0xe'),'');if(_0x2d91ae[_0x129b('0xf')]('\x20')!=-0x1){_0x2d91ae=_0x2d91ae[_0x129b('0x10')](0x0,_0x2d91ae[_0x129b('0xf')]('\x20'));}if(_[_0x129b('0x11')](_0x2d91ae,'-1')){_0x2d91ae=parseInt(_0x2d91ae);}_0x9c34e9=_0xb4ee0e['rx'][_0x129b('0x12')]('\x20');if(_0x9c34e9[_0x129b('0x13')]==0x3){_0x9c34e9=_0x9c34e9[0x2][_0x129b('0xb')](0x1,_0x9c34e9[0x2][_0x129b('0x13')]-0x1);}else if(_0x9c34e9[_0x129b('0x13')]>0x3){var _0xb34c52=/\((.+)\)/;var _0x10939e=_0xb4ee0e['rx'][_0x129b('0x14')](_0xb34c52);if(_0x10939e){_0x9c34e9=_0x10939e[0x1];}else{_0x9c34e9=null;}}else{_0x9c34e9=null;}_0xb4ee0e['cb'](null,{'code':_0x14bb9e,'result':_0x2d91ae,'extra':_0x9c34e9});}});_0x3a13a5['on'](_0x129b('0x15'),function(_0xdaa9d7){_0x340c01[_0x129b('0xa')](_0x129b('0x15'),new AGIError(_0x129b('0x16'),_0xdaa9d7[_0x129b('0x17')]));});_0x3a13a5['on'](_0x129b('0x18'),function(){_0x340c01[_0x129b('0xa')]('close',new AGIError(_0x129b('0x19')));});_0x3a13a5['on'](_0x129b('0x1a'),function(){_0x340c01[_0x129b('0xa')]('timeout',new AGIError(_0x129b('0x1b')));_0x3a13a5['destroy']();});_0x3a13a5['pipe'](_0x54a38b);this[_0x129b('0x1c')]=function(_0x246511,_0x5ca376){var _0x246511=_0x246511||'',_0x5ca376=typeof _0x5ca376=='function'?_0x5ca376:new Function();_0xb4ee0e={'tx':_0x246511,'rx':'','cb':_0x5ca376};_0x3a13a5['write'](_0x246511+'\x0a');},this['close']=function(){_0x3a13a5[_0x129b('0x1d')]();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel[_0x129b('0x1e')]['sendRequest']=function(_0x475092){return this['command'][_0x129b('0x1f')](this,_0x475092);};AGIChannel[_0x129b('0x1e')][_0x129b('0x20')]=function(){return this['sendRequest'](_0x129b('0x21'));};AGIChannel[_0x129b('0x1e')]['getData']=function(_0xab26ee,_0x59bc83,_0x1fa141){_0xab26ee=_0xab26ee===undefined?'beep':_0xab26ee;_0x59bc83=_0x59bc83===undefined?'5':_0x59bc83;_0x1fa141=_0x1fa141===undefined?'1':_0x1fa141;return this[_0x129b('0x22')](util[_0x129b('0x23')](_0x129b('0x24'),_0xab26ee,_0x59bc83*0x3e8,_0x1fa141));};AGIChannel[_0x129b('0x1e')][_0x129b('0x25')]=function(_0xc8b344){_0xc8b344=_0xc8b344||_0x129b('0x26');return this[_0x129b('0x22')](util['format'](_0x129b('0x27'),_0xc8b344));};AGIChannel[_0x129b('0x1e')][_0x129b('0x28')]=function(_0x43719b,_0x26f1e2){if(_[_0x129b('0x29')](_0x26f1e2)){return this[_0x129b('0x22')](util['format'](_0x129b('0x2a'),_0x43719b,_0x26f1e2[_0x129b('0x2b')](',')));}return this[_0x129b('0x22')](util[_0x129b('0x23')]('EXEC\x20%s\x20%s',_0x43719b,_0x26f1e2));};AGIChannel[_0x129b('0x1e')]['setContext']=function(_0x24d709){return this[_0x129b('0x22')](util['format'](_0x129b('0x2c'),_0x24d709));};AGIChannel[_0x129b('0x1e')][_0x129b('0x2d')]=function(_0x4b33ae){return this[_0x129b('0x22')](util['format'](_0x129b('0x2e'),_0x4b33ae));};AGIChannel[_0x129b('0x1e')][_0x129b('0x2f')]=function(_0x1ae6ee){return this[_0x129b('0x22')](util['format'](_0x129b('0x30'),_0x1ae6ee));};AGIChannel['prototype'][_0x129b('0x31')]=function(){return this[_0x129b('0x22')](_0x129b('0x32'));};AGIChannel['prototype']['setVariable']=function(_0x34bb1f,_0x3f26e3){var _0x55b1e5=_[_0x129b('0x33')](_0x3f26e3)||_['isNumber'](_0x3f26e3)?_0x3f26e3['toString']():_0x3f26e3;return this[_0x129b('0x22')](util[_0x129b('0x23')](_0x129b('0x34'),_0x34bb1f,_0x55b1e5?_0x55b1e5['toString']()[_0x129b('0xd')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel['prototype']['sayNumber']=function(_0x23f8c8,_0xb37b0a){return this[_0x129b('0x22')](util[_0x129b('0x23')](_0x129b('0x35'),_0x23f8c8,_0xb37b0a));};AGIChannel[_0x129b('0x1e')][_0x129b('0x36')]=function(_0x37215c,_0x1fb955){return this[_0x129b('0x22')](util[_0x129b('0x23')](_0x129b('0x37'),_0x37215c,_0x1fb955));};AGIChannel['prototype'][_0x129b('0x38')]=function(_0x964798,_0xa10258){return this[_0x129b('0x22')](util[_0x129b('0x23')](_0x129b('0x39'),_0x964798,_0xa10258));};AGIChannel[_0x129b('0x1e')]['continueAt']=function(_0x26c14a,_0x4eeaaa,_0x59199d){_0x4eeaaa=_0x4eeaaa||this[_0x129b('0x3a')];_0x59199d=_0x59199d||0x1;this[_0x129b('0x3b')](_0x26c14a);this[_0x129b('0x2d')](_0x4eeaaa);this[_0x129b('0x2f')](_0x59199d);return this[_0x129b('0x25')](util[_0x129b('0x23')](_0x129b('0x3c'),_0x26c14a,_0x4eeaaa,_0x59199d));};AGIChannel['prototype']['getVariable']=function(_0x36c22a){return this[_0x129b('0x22')](util['format'](_0x129b('0x3d'),_0x36c22a));};AGIChannel['prototype']['recordFile']=function(_0x3c48b1,_0x34ef65,_0x1b5b07,_0x2a96cb,_0x576616,_0x1e97ad){_0x34ef65=_0x34ef65||'wav';_0x1b5b07=_0x1b5b07||'';_0x2a96cb=_0x2a96cb===undefined?-0x1:_0x2a96cb==='-1'?-0x1:_0x2a96cb*0x3e8;_0x576616=_0x576616===undefined?'':'s='+_0x576616;_0x1e97ad=_0x1e97ad?_0x129b('0x3e'):'';return this['sendRequest'](util[_0x129b('0x23')]('RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s',_0x3c48b1,_0x34ef65,_0x1b5b07,_0x2a96cb,_0x1e97ad,_0x576616));};AGIChannel[_0x129b('0x1e')]['streamFile']=function(_0x43010e,_0x6dcf57){_0x6dcf57=_0x6dcf57||'';return this['sendRequest'](util[_0x129b('0x23')](_0x129b('0x3f'),_0x43010e,_0x6dcf57));};AGIChannel['prototype'][_0x129b('0x40')]=function(_0x536b6b){return this[_0x129b('0x28')]('AGI',_0x536b6b);};AGIChannel[_0x129b('0x1e')][_0x129b('0x41')]=function(_0x2fb885){return this['exec'](_0x129b('0x42'),_0x2fb885);};AGIChannel[_0x129b('0x1e')]['error']=function(_0x156bc9,_0x562960){this[_0x129b('0x25')](util[_0x129b('0x23')](_0x129b('0x43'),_0x156bc9['id'],_0x156bc9[_0x129b('0x44')],_0x562960));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x129b('0x45')]=AGIChannel;