Built motion from commit 8c034dcd.|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 _0x302e=['setContext','SET\x20EXTENSION\x20%s','setPriority','HANGUP','isBoolean','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','replace','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','extension','setExtension','noop','GOTO\x20%s\x20%s\x20%s','GET\x20VARIABLE\x20\x22%s\x22','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','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','exports','util','lodash','events','EventEmitter','./error','setEncoding','utf8','setTimeout','headers','emit','ready','line','toLowerCase','hangup','520-Invalid','520\x20End\x20of\x20proper','function','no\x20code','substring','result=','substr','indexOf','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','close','timeout','E_AGI_SOCKET_TIMEOUT','pipe','command','write','destroy','inherits','sendRequest','sync','prototype','answer','ANSWER','beep','format','VERBOSE\x20\x22%s\x22','exec','isArray','EXEC\x20%s\x20%s','join'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x302e,0x1eb));var _0xe302=function(_0x480a5d,_0x873e21){_0x480a5d=_0x480a5d-0x0;var _0x286487=_0x302e[_0x480a5d];return _0x286487;};'use strict';var util=require(_0xe302('0x0'));var _=require(_0xe302('0x1'));var EventEmitter=require(_0xe302('0x2'))[_0xe302('0x3')];var AGIReply=require('./reply');var AGIError=require(_0xe302('0x4'));function AGIChannel(_0x371048){var _0x3e965=this,_0x5151d8=new AGIReply(),_0x321c8a=![],_0x1647a7={};EventEmitter['call'](_0x3e965);_0x371048[_0xe302('0x5')](_0xe302('0x6'));_0x371048[_0xe302('0x7')](0x8*0x3c*0x3c*0x3e8);_0x5151d8[_0xe302('0x5')](_0xe302('0x6'));_0x5151d8['on'](_0xe302('0x8'),function(_0xe14329){for(var _0x1155a5 in _0xe14329){_0x3e965[_0x1155a5]=_0xe14329[_0x1155a5];}_0x3e965[_0xe302('0x9')](_0xe302('0xa'));});_0x5151d8['on'](_0xe302('0xb'),function(_0x319a5b){if(_0x319a5b[_0xe302('0xc')]()==_0xe302('0xd')){_0x3e965[_0xe302('0x9')](_0xe302('0xd'));return;}if(_0x319a5b['substring'](0x0,0xb)==_0xe302('0xe')){_0x321c8a=!![];}if(_0x321c8a){_0x1647a7['rx']+=_0x319a5b+'\x0a';if(_0x319a5b['search'](_0xe302('0xf'))!=-0x1){_0x321c8a=![];}}else{_0x1647a7['rx']=_0x319a5b;}if(_0x321c8a){return;}if(typeof _0x1647a7['cb']==_0xe302('0x10')){var _0x56a8bf=_0x1647a7['rx']['substring'](0x0,0x3),_0xd9a2fd=null,_0x37ad2e=null;_0x56a8bf=parseInt(_0x56a8bf);if(isNaN(_0x56a8bf)){_0x1647a7['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xe302('0x11')});return;}if(_0x56a8bf!=0xc8){_0x1647a7['cb'](null,{'code':_0x56a8bf,'result':-0x1,'extra':'KO'});return;}_0xd9a2fd=_0x1647a7['rx'][_0xe302('0x12')](0x4)['replace'](_0xe302('0x13'),'');if(_0xd9a2fd['indexOf']('\x20')!=-0x1){_0xd9a2fd=_0xd9a2fd[_0xe302('0x14')](0x0,_0xd9a2fd[_0xe302('0x15')]('\x20'));}if(_[_0xe302('0x16')](_0xd9a2fd,'-1')){_0xd9a2fd=parseInt(_0xd9a2fd);}_0x37ad2e=_0x1647a7['rx'][_0xe302('0x17')]('\x20');if(_0x37ad2e['length']==0x3){_0x37ad2e=_0x37ad2e[0x2]['substring'](0x1,_0x37ad2e[0x2][_0xe302('0x18')]-0x1);}else if(_0x37ad2e[_0xe302('0x18')]>0x3){var _0x3eba1b=/\((.+)\)/;var _0x5a80fd=_0x1647a7['rx'][_0xe302('0x19')](_0x3eba1b);if(_0x5a80fd){_0x37ad2e=_0x5a80fd[0x1];}else{_0x37ad2e=null;}}else{_0x37ad2e=null;}_0x1647a7['cb'](null,{'code':_0x56a8bf,'result':_0xd9a2fd,'extra':_0x37ad2e});}});_0x371048['on'](_0xe302('0x1a'),function(_0x3015f6){_0x3e965['emit'](_0xe302('0x1a'),new AGIError(_0xe302('0x1b'),_0x3015f6['code']));});_0x371048['on']('close',function(){_0x3e965[_0xe302('0x9')](_0xe302('0x1c'),new AGIError('E_AGI_SOCKET_CLOSE'));});_0x371048['on'](_0xe302('0x1d'),function(){_0x3e965['emit']('timeout',new AGIError(_0xe302('0x1e')));_0x371048['destroy']();});_0x371048[_0xe302('0x1f')](_0x5151d8);this[_0xe302('0x20')]=function(_0x924111,_0x390678){var _0x924111=_0x924111||'',_0x390678=typeof _0x390678=='function'?_0x390678:new Function();_0x1647a7={'tx':_0x924111,'rx':'','cb':_0x390678};_0x371048[_0xe302('0x21')](_0x924111+'\x0a');},this[_0xe302('0x1c')]=function(){_0x371048[_0xe302('0x22')]();};}util[_0xe302('0x23')](AGIChannel,EventEmitter);AGIChannel['prototype'][_0xe302('0x24')]=function(_0x532e94){return this[_0xe302('0x20')][_0xe302('0x25')](this,_0x532e94);};AGIChannel[_0xe302('0x26')][_0xe302('0x27')]=function(){return this[_0xe302('0x24')](_0xe302('0x28'));};AGIChannel['prototype']['getData']=function(_0x23e33c,_0x377097,_0x4ab7b9){_0x23e33c=_0x23e33c===undefined?_0xe302('0x29'):_0x23e33c;_0x377097=_0x377097===undefined?'5':_0x377097;_0x4ab7b9=_0x4ab7b9===undefined?'1':_0x4ab7b9;return this['sendRequest'](util[_0xe302('0x2a')]('GET\x20DATA\x20\x22%s\x22\x20%s\x20%s',_0x23e33c,_0x377097*0x3e8,_0x4ab7b9));};AGIChannel['prototype']['noop']=function(_0x38fcf6){_0x38fcf6=_0x38fcf6||'NO\x20MESSAGE';return this[_0xe302('0x24')](util['format'](_0xe302('0x2b'),_0x38fcf6));};AGIChannel[_0xe302('0x26')][_0xe302('0x2c')]=function(_0x14defb,_0x292ab3){if(_[_0xe302('0x2d')](_0x292ab3)){return this[_0xe302('0x24')](util[_0xe302('0x2a')](_0xe302('0x2e'),_0x14defb,_0x292ab3[_0xe302('0x2f')](',')));}return this[_0xe302('0x24')](util[_0xe302('0x2a')]('EXEC\x20%s\x20%s',_0x14defb,_0x292ab3));};AGIChannel[_0xe302('0x26')][_0xe302('0x30')]=function(_0xe3ca4c){return this[_0xe302('0x24')](util['format']('SET\x20CONTEXT\x20%s',_0xe3ca4c));};AGIChannel['prototype']['setExtension']=function(_0xe22fb3){return this['sendRequest'](util[_0xe302('0x2a')](_0xe302('0x31'),_0xe22fb3));};AGIChannel[_0xe302('0x26')][_0xe302('0x32')]=function(_0x1d6f88){return this[_0xe302('0x24')](util[_0xe302('0x2a')]('SET\x20PRIORITY\x20%s',_0x1d6f88));};AGIChannel[_0xe302('0x26')]['hangup']=function(){return this['sendRequest'](_0xe302('0x33'));};AGIChannel[_0xe302('0x26')]['setVariable']=function(_0x4bd072,_0x29b859){var _0x1a2590=_[_0xe302('0x34')](_0x29b859)||_['isNumber'](_0x29b859)?_0x29b859[_0xe302('0x35')]():_0x29b859;return this[_0xe302('0x24')](util['format'](_0xe302('0x36'),_0x4bd072,_0x1a2590?_0x1a2590[_0xe302('0x35')]()[_0xe302('0x37')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xe302('0x26')]['sayNumber']=function(_0x383610,_0x134be7){return this[_0xe302('0x24')](util[_0xe302('0x2a')](_0xe302('0x38'),_0x383610,_0x134be7));};AGIChannel[_0xe302('0x26')][_0xe302('0x39')]=function(_0x138457,_0x2f9494){return this[_0xe302('0x24')](util[_0xe302('0x2a')](_0xe302('0x3a'),_0x138457,_0x2f9494));};AGIChannel[_0xe302('0x26')][_0xe302('0x3b')]=function(_0x1e89b0,_0x15a642){return this[_0xe302('0x24')](util['format'](_0xe302('0x3c'),_0x1e89b0,_0x15a642));};AGIChannel[_0xe302('0x26')]['continueAt']=function(_0x46976a,_0xec1d61,_0x3732f4){_0xec1d61=_0xec1d61||this[_0xe302('0x3d')];_0x3732f4=_0x3732f4||0x1;this[_0xe302('0x30')](_0x46976a);this[_0xe302('0x3e')](_0xec1d61);this[_0xe302('0x32')](_0x3732f4);return this[_0xe302('0x3f')](util[_0xe302('0x2a')](_0xe302('0x40'),_0x46976a,_0xec1d61,_0x3732f4));};AGIChannel[_0xe302('0x26')]['getVariable']=function(_0x2a7049){return this[_0xe302('0x24')](util['format'](_0xe302('0x41'),_0x2a7049));};AGIChannel['prototype']['recordFile']=function(_0x5e937f,_0x44382a,_0x8a80c8,_0x5eaf97,_0x5aa1bf,_0x2aceb1){_0x44382a=_0x44382a||_0xe302('0x42');_0x8a80c8=_0x8a80c8||'';_0x5eaf97=_0x5eaf97===undefined?-0x1:_0x5eaf97==='-1'?-0x1:_0x5eaf97*0x3e8;_0x5aa1bf=_0x5aa1bf===undefined?'':'s='+_0x5aa1bf;_0x2aceb1=_0x2aceb1?_0xe302('0x43'):'';return this[_0xe302('0x24')](util['format'](_0xe302('0x44'),_0x5e937f,_0x44382a,_0x8a80c8,_0x5eaf97,_0x2aceb1,_0x5aa1bf));};AGIChannel[_0xe302('0x26')][_0xe302('0x45')]=function(_0x4d84b6,_0x121b51){_0x121b51=_0x121b51||'';return this[_0xe302('0x24')](util[_0xe302('0x2a')](_0xe302('0x46'),_0x4d84b6,_0x121b51));};AGIChannel[_0xe302('0x26')][_0xe302('0x47')]=function(_0x49eda0){return this[_0xe302('0x2c')](_0xe302('0x48'),_0x49eda0);};AGIChannel[_0xe302('0x26')][_0xe302('0x49')]=function(_0x4ed8ed){return this[_0xe302('0x2c')](_0xe302('0x4a'),_0x4ed8ed);};AGIChannel[_0xe302('0x26')]['error']=function(_0x2cacbf,_0x1f09bc){this[_0xe302('0x3f')](util[_0xe302('0x2a')](_0xe302('0x4b'),_0x2cacbf['id'],_0x2cacbf['label'],_0x1f09bc));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xe302('0x4c')]=AGIChannel;