b993eaeaf3759cc30ba8dae619ff186f821c883f
[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 _0x2bc6=['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','sync','prototype','answer','sendRequest','ANSWER','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','join','EXEC\x20%s\x20%s','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','SET\x20PRIORITY\x20%s','setVariable','isBoolean','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','sayNumber','SAY\x20NUMBER\x20%s\x20%s','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','setContext','setPriority','recordFile','wav','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','streamFile','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','agi','AGI','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','util','lodash','events','./reply','./error','setEncoding','utf8','headers','emit','line','toLowerCase','hangup','substring','520-Invalid','search','520\x20End\x20of\x20proper','function','no\x20code','replace'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x2bc6,0x8b));var _0x62bc=function(_0x12baa2,_0x27a8c9){_0x12baa2=_0x12baa2-0x0;var _0x4f78f2=_0x2bc6[_0x12baa2];return _0x4f78f2;};'use strict';var util=require(_0x62bc('0x0'));var _=require(_0x62bc('0x1'));var EventEmitter=require(_0x62bc('0x2'))['EventEmitter'];var AGIReply=require(_0x62bc('0x3'));var AGIError=require(_0x62bc('0x4'));function AGIChannel(_0x10715f){var _0x3c6fd4=this,_0x174df3=new AGIReply(),_0x3c06ee=![],_0x5114c5={};EventEmitter['call'](_0x3c6fd4);_0x10715f[_0x62bc('0x5')](_0x62bc('0x6'));_0x10715f['setTimeout'](0x8*0x3c*0x3c*0x3e8);_0x174df3[_0x62bc('0x5')](_0x62bc('0x6'));_0x174df3['on'](_0x62bc('0x7'),function(_0x5ea60f){for(var _0x32b903 in _0x5ea60f){_0x3c6fd4[_0x32b903]=_0x5ea60f[_0x32b903];}_0x3c6fd4[_0x62bc('0x8')]('ready');});_0x174df3['on'](_0x62bc('0x9'),function(_0x2d2ac3){if(_0x2d2ac3[_0x62bc('0xa')]()==_0x62bc('0xb')){_0x3c6fd4[_0x62bc('0x8')]('hangup');return;}if(_0x2d2ac3[_0x62bc('0xc')](0x0,0xb)==_0x62bc('0xd')){_0x3c06ee=!![];}if(_0x3c06ee){_0x5114c5['rx']+=_0x2d2ac3+'\x0a';if(_0x2d2ac3[_0x62bc('0xe')](_0x62bc('0xf'))!=-0x1){_0x3c06ee=![];}}else{_0x5114c5['rx']=_0x2d2ac3;}if(_0x3c06ee){return;}if(typeof _0x5114c5['cb']==_0x62bc('0x10')){var _0x562b5d=_0x5114c5['rx']['substring'](0x0,0x3),_0x36a80d=null,_0x287c06=null;_0x562b5d=parseInt(_0x562b5d);if(isNaN(_0x562b5d)){_0x5114c5['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x62bc('0x11')});return;}if(_0x562b5d!=0xc8){_0x5114c5['cb'](null,{'code':_0x562b5d,'result':-0x1,'extra':'KO'});return;}_0x36a80d=_0x5114c5['rx'][_0x62bc('0xc')](0x4)[_0x62bc('0x12')](_0x62bc('0x13'),'');if(_0x36a80d[_0x62bc('0x14')]('\x20')!=-0x1){_0x36a80d=_0x36a80d[_0x62bc('0x15')](0x0,_0x36a80d[_0x62bc('0x14')]('\x20'));}if(_[_0x62bc('0x16')](_0x36a80d,'-1')){_0x36a80d=parseInt(_0x36a80d);}_0x287c06=_0x5114c5['rx'][_0x62bc('0x17')]('\x20');if(_0x287c06[_0x62bc('0x18')]==0x3){_0x287c06=_0x287c06[0x2][_0x62bc('0xc')](0x1,_0x287c06[0x2][_0x62bc('0x18')]-0x1);}else if(_0x287c06[_0x62bc('0x18')]>0x3){var _0x1f4689=/\((.+)\)/;var _0x3ac0dc=_0x5114c5['rx'][_0x62bc('0x19')](_0x1f4689);if(_0x3ac0dc){_0x287c06=_0x3ac0dc[0x1];}else{_0x287c06=null;}}else{_0x287c06=null;}_0x5114c5['cb'](null,{'code':_0x562b5d,'result':_0x36a80d,'extra':_0x287c06});}});_0x10715f['on'](_0x62bc('0x1a'),function(_0x414197){_0x3c6fd4[_0x62bc('0x8')](_0x62bc('0x1a'),new AGIError(_0x62bc('0x1b'),_0x414197[_0x62bc('0x1c')]));});_0x10715f['on']('close',function(){_0x3c6fd4['emit'](_0x62bc('0x1d'),new AGIError(_0x62bc('0x1e')));});_0x10715f['on'](_0x62bc('0x1f'),function(){_0x3c6fd4[_0x62bc('0x8')](_0x62bc('0x1f'),new AGIError(_0x62bc('0x20')));_0x10715f[_0x62bc('0x21')]();});_0x10715f[_0x62bc('0x22')](_0x174df3);this[_0x62bc('0x23')]=function(_0x4f1d12,_0x4907fa){var _0x4f1d12=_0x4f1d12||'',_0x4907fa=typeof _0x4907fa=='function'?_0x4907fa:new Function();_0x5114c5={'tx':_0x4f1d12,'rx':'','cb':_0x4907fa};_0x10715f[_0x62bc('0x24')](_0x4f1d12+'\x0a');},this['close']=function(){_0x10715f[_0x62bc('0x21')]();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel['prototype']['sendRequest']=function(_0x37943c){return this[_0x62bc('0x23')][_0x62bc('0x25')](this,_0x37943c);};AGIChannel[_0x62bc('0x26')][_0x62bc('0x27')]=function(){return this[_0x62bc('0x28')](_0x62bc('0x29'));};AGIChannel[_0x62bc('0x26')][_0x62bc('0x2a')]=function(_0x11f3c0,_0x5c15a4,_0x318d16){_0x11f3c0=_0x11f3c0===undefined?_0x62bc('0x2b'):_0x11f3c0;_0x5c15a4=_0x5c15a4===undefined?'5':_0x5c15a4;_0x318d16=_0x318d16===undefined?'1':_0x318d16;return this['sendRequest'](util[_0x62bc('0x2c')](_0x62bc('0x2d'),_0x11f3c0,_0x5c15a4*0x3e8,_0x318d16));};AGIChannel['prototype'][_0x62bc('0x2e')]=function(_0x5866a2){_0x5866a2=_0x5866a2||_0x62bc('0x2f');return this[_0x62bc('0x28')](util[_0x62bc('0x2c')](_0x62bc('0x30'),_0x5866a2));};AGIChannel[_0x62bc('0x26')][_0x62bc('0x31')]=function(_0xd1b976,_0x10f9c6){if(_['isArray'](_0x10f9c6)){return this[_0x62bc('0x28')](util['format']('EXEC\x20%s\x20%s',_0xd1b976,_0x10f9c6[_0x62bc('0x32')](',')));}return this[_0x62bc('0x28')](util[_0x62bc('0x2c')](_0x62bc('0x33'),_0xd1b976,_0x10f9c6));};AGIChannel[_0x62bc('0x26')]['setContext']=function(_0x2a7eca){return this[_0x62bc('0x28')](util[_0x62bc('0x2c')](_0x62bc('0x34'),_0x2a7eca));};AGIChannel['prototype'][_0x62bc('0x35')]=function(_0x54efe8){return this['sendRequest'](util[_0x62bc('0x2c')](_0x62bc('0x36'),_0x54efe8));};AGIChannel[_0x62bc('0x26')]['setPriority']=function(_0xab5b57){return this[_0x62bc('0x28')](util[_0x62bc('0x2c')](_0x62bc('0x37'),_0xab5b57));};AGIChannel[_0x62bc('0x26')][_0x62bc('0xb')]=function(){return this['sendRequest']('HANGUP');};AGIChannel[_0x62bc('0x26')][_0x62bc('0x38')]=function(_0x416ed3,_0x5e7fef){var _0x238e4b=_[_0x62bc('0x39')](_0x5e7fef)||_[_0x62bc('0x3a')](_0x5e7fef)?_0x5e7fef[_0x62bc('0x3b')]():_0x5e7fef;return this[_0x62bc('0x28')](util[_0x62bc('0x2c')](_0x62bc('0x3c'),_0x416ed3,_0x238e4b?_0x238e4b[_0x62bc('0x3b')]()[_0x62bc('0x12')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x62bc('0x26')][_0x62bc('0x3d')]=function(_0x5dcb89,_0x363bad){return this[_0x62bc('0x28')](util[_0x62bc('0x2c')](_0x62bc('0x3e'),_0x5dcb89,_0x363bad));};AGIChannel[_0x62bc('0x26')]['sayDigits']=function(_0x1e49f0,_0x4bcab0){return this[_0x62bc('0x28')](util['format'](_0x62bc('0x3f'),_0x1e49f0,_0x4bcab0));};AGIChannel[_0x62bc('0x26')][_0x62bc('0x40')]=function(_0x6d6c7c,_0x519989){return this[_0x62bc('0x28')](util['format']('SAY\x20PHONETIC\x20\x22%s\x22\x20%s',_0x6d6c7c,_0x519989));};AGIChannel[_0x62bc('0x26')]['continueAt']=function(_0xd09ba2,_0x562adc,_0xca354a){_0x562adc=_0x562adc||this['extension'];_0xca354a=_0xca354a||0x1;this[_0x62bc('0x41')](_0xd09ba2);this[_0x62bc('0x35')](_0x562adc);this[_0x62bc('0x42')](_0xca354a);return this[_0x62bc('0x2e')](util[_0x62bc('0x2c')]('GOTO\x20%s\x20%s\x20%s',_0xd09ba2,_0x562adc,_0xca354a));};AGIChannel['prototype']['getVariable']=function(_0x4bea02){return this[_0x62bc('0x28')](util[_0x62bc('0x2c')]('GET\x20VARIABLE\x20\x22%s\x22',_0x4bea02));};AGIChannel[_0x62bc('0x26')][_0x62bc('0x43')]=function(_0x4324cf,_0x3ef8a2,_0x14bfda,_0x5b65f4,_0x3ba18f,_0x186839){_0x3ef8a2=_0x3ef8a2||_0x62bc('0x44');_0x14bfda=_0x14bfda||'';_0x5b65f4=_0x5b65f4===undefined?-0x1:_0x5b65f4==='-1'?-0x1:_0x5b65f4*0x3e8;_0x3ba18f=_0x3ba18f===undefined?'':'s='+_0x3ba18f;_0x186839=_0x186839?_0x62bc('0x45'):'';return this[_0x62bc('0x28')](util[_0x62bc('0x2c')](_0x62bc('0x46'),_0x4324cf,_0x3ef8a2,_0x14bfda,_0x5b65f4,_0x186839,_0x3ba18f));};AGIChannel[_0x62bc('0x26')][_0x62bc('0x47')]=function(_0xe02f06,_0x2fb75c){_0x2fb75c=_0x2fb75c||'';return this['sendRequest'](util[_0x62bc('0x2c')](_0x62bc('0x48'),_0xe02f06,_0x2fb75c));};AGIChannel[_0x62bc('0x26')][_0x62bc('0x49')]=function(_0x20adb8){return this['exec'](_0x62bc('0x4a'),_0x20adb8);};AGIChannel['prototype']['wait']=function(_0x290367){return this[_0x62bc('0x31')](_0x62bc('0x4b'),_0x290367);};AGIChannel[_0x62bc('0x26')][_0x62bc('0x1a')]=function(_0x2515d5,_0x5dc283){this[_0x62bc('0x2e')](util[_0x62bc('0x2c')](_0x62bc('0x4c'),_0x2515d5['id'],_0x2515d5[_0x62bc('0x4d')],_0x5dc283));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x62bc('0x4e')]=AGIChannel;