Built motion from commit (unavailable).|2.5.4
[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 _0x216b=['noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','isArray','EXEC\x20%s\x20%s','join','setContext','setExtension','SET\x20EXTENSION\x20%s','HANGUP','setVariable','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','continueAt','extension','setPriority','GOTO\x20%s\x20%s\x20%s','getVariable','getvariable','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','agi','AGI','wait','WAIT','label','util','lodash','events','./reply','./error','setEncoding','utf8','setTimeout','headers','ready','line','toLowerCase','substring','520-Invalid','search','520\x20End\x20of\x20proper','function','no\x20code','replace','indexOf','substr','startsWith','split','length','match','error','emit','E_AGI_SOCKET_ERROR','code','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','log','command=','close','inherits','prototype','sendRequest','command','sync','answer','ANSWER','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s'];(function(_0x1ceb6e,_0x4d6d50){var _0x1987d3=function(_0x113b78){while(--_0x113b78){_0x1ceb6e['push'](_0x1ceb6e['shift']());}};_0x1987d3(++_0x4d6d50);}(_0x216b,0x174));var _0xb216=function(_0x59c207,_0x8ff66e){_0x59c207=_0x59c207-0x0;var _0x82d8db=_0x216b[_0x59c207];return _0x82d8db;};'use strict';var util=require(_0xb216('0x0'));var _=require(_0xb216('0x1'));var EventEmitter=require(_0xb216('0x2'))['EventEmitter'];var AGIReply=require(_0xb216('0x3'));var AGIError=require(_0xb216('0x4'));function AGIChannel(_0x29b8ef){var _0x257d84=this,_0x155a40=new AGIReply(),_0xbc069=![],_0x4c9687={};EventEmitter['call'](_0x257d84);_0x29b8ef[_0xb216('0x5')](_0xb216('0x6'));_0x29b8ef[_0xb216('0x7')](0x8*0x3c*0x3c*0x3e8);_0x155a40[_0xb216('0x5')](_0xb216('0x6'));_0x155a40['on'](_0xb216('0x8'),function(_0x54baec){for(var _0x383e09 in _0x54baec){_0x257d84[_0x383e09]=_0x54baec[_0x383e09];}_0x257d84['emit'](_0xb216('0x9'));});_0x155a40['on'](_0xb216('0xa'),function(_0x391d75){if(_0x391d75[_0xb216('0xb')]()=='hangup'){_0x257d84['emit']('hangup');return;}if(_0x391d75[_0xb216('0xc')](0x0,0xb)==_0xb216('0xd')){_0xbc069=!![];}if(_0xbc069){_0x4c9687['rx']+=_0x391d75+'\x0a';if(_0x391d75[_0xb216('0xe')](_0xb216('0xf'))!=-0x1){_0xbc069=![];}}else{_0x4c9687['rx']=_0x391d75;}if(_0xbc069){return;}if(typeof _0x4c9687['cb']==_0xb216('0x10')){var _0x3ae0fd=_0x4c9687['rx']['substring'](0x0,0x3),_0x26695f=null,_0xbdabbe=null;_0x3ae0fd=parseInt(_0x3ae0fd);if(isNaN(_0x3ae0fd)){_0x4c9687['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xb216('0x11')});return;}if(_0x3ae0fd!=0xc8){_0x4c9687['cb'](null,{'code':_0x3ae0fd,'result':-0x1,'extra':'KO'});return;}_0x26695f=_0x4c9687['rx']['substring'](0x4)[_0xb216('0x12')]('result=','');if(_0x26695f[_0xb216('0x13')]('\x20')!=-0x1){_0x26695f=_0x26695f[_0xb216('0x14')](0x0,_0x26695f['indexOf']('\x20'));}if(_[_0xb216('0x15')](_0x26695f,'-1')){_0x26695f=parseInt(_0x26695f);}_0xbdabbe=_0x4c9687['rx'][_0xb216('0x16')]('\x20');if(_0xbdabbe[_0xb216('0x17')]==0x3){_0xbdabbe=_0xbdabbe[0x2][_0xb216('0xc')](0x1,_0xbdabbe[0x2][_0xb216('0x17')]-0x1);}else if(_0xbdabbe[_0xb216('0x17')]>0x3){var _0x4ad104=/\((.+)\)/;var _0x400fe3=_0x4c9687['rx'][_0xb216('0x18')](_0x4ad104);if(_0x400fe3){_0xbdabbe=_0x400fe3[0x1];}else{_0xbdabbe=null;}}else{_0xbdabbe=null;}_0x4c9687['cb'](null,{'code':_0x3ae0fd,'result':_0x26695f,'extra':_0xbdabbe});}});_0x29b8ef['on'](_0xb216('0x19'),function(_0x824601){_0x257d84[_0xb216('0x1a')](_0xb216('0x19'),new AGIError(_0xb216('0x1b'),_0x824601[_0xb216('0x1c')]));});_0x29b8ef['on']('close',function(){_0x257d84['emit']('close',new AGIError(_0xb216('0x1d')));});_0x29b8ef['on'](_0xb216('0x1e'),function(){_0x257d84[_0xb216('0x1a')](_0xb216('0x1e'),new AGIError(_0xb216('0x1f')));_0x29b8ef[_0xb216('0x20')]();});_0x29b8ef[_0xb216('0x21')](_0x155a40);this['command']=function(_0x3c7307,_0x3edd80){console[_0xb216('0x22')](_0xb216('0x23'),_0x3c7307);var _0x3c7307=_0x3c7307||'',_0x3edd80=typeof _0x3edd80=='function'?_0x3edd80:new Function();_0x4c9687={'tx':_0x3c7307,'rx':'','cb':_0x3edd80};_0x29b8ef['write'](_0x3c7307+'\x0a');},this[_0xb216('0x24')]=function(){_0x29b8ef[_0xb216('0x20')]();};}util[_0xb216('0x25')](AGIChannel,EventEmitter);AGIChannel[_0xb216('0x26')][_0xb216('0x27')]=function(_0x1a7af8){return this[_0xb216('0x28')][_0xb216('0x29')](this,_0x1a7af8);};AGIChannel[_0xb216('0x26')][_0xb216('0x2a')]=function(){return this[_0xb216('0x27')](_0xb216('0x2b'));};AGIChannel[_0xb216('0x26')][_0xb216('0x2c')]=function(_0xc5b550,_0x152a63,_0x5ee769){_0xc5b550=_0xc5b550===undefined?_0xb216('0x2d'):_0xc5b550;_0x152a63=_0x152a63===undefined?'5':_0x152a63;_0x5ee769=_0x5ee769===undefined?'1':_0x5ee769;return this[_0xb216('0x27')](util[_0xb216('0x2e')](_0xb216('0x2f'),_0xc5b550,_0x152a63*0x3e8,_0x5ee769));};AGIChannel[_0xb216('0x26')][_0xb216('0x30')]=function(_0xadf9a9){_0xadf9a9=_0xadf9a9||_0xb216('0x31');return this[_0xb216('0x27')](util['format'](_0xb216('0x32'),_0xadf9a9));};AGIChannel[_0xb216('0x26')][_0xb216('0x33')]=function(_0x22e109,_0x23fda2){if(_[_0xb216('0x34')](_0x23fda2)){return this['sendRequest'](util['format'](_0xb216('0x35'),_0x22e109,_0x23fda2[_0xb216('0x36')](',')));}return this['sendRequest'](util[_0xb216('0x2e')](_0xb216('0x35'),_0x22e109,_0x23fda2));};AGIChannel[_0xb216('0x26')][_0xb216('0x37')]=function(_0x4933ab){return this['sendRequest'](util[_0xb216('0x2e')]('SET\x20CONTEXT\x20%s',_0x4933ab));};AGIChannel['prototype'][_0xb216('0x38')]=function(_0x3a8c19){return this['sendRequest'](util['format'](_0xb216('0x39'),_0x3a8c19));};AGIChannel[_0xb216('0x26')]['setPriority']=function(_0x139832){return this[_0xb216('0x27')](util[_0xb216('0x2e')]('SET\x20PRIORITY\x20%s',_0x139832));};AGIChannel[_0xb216('0x26')]['hangup']=function(){return this[_0xb216('0x27')](_0xb216('0x3a'));};AGIChannel[_0xb216('0x26')][_0xb216('0x3b')]=function(_0x3747ef,_0x1c88c2){var _0x19b298=_['isBoolean'](_0x1c88c2)||_[_0xb216('0x3c')](_0x1c88c2)?_0x1c88c2[_0xb216('0x3d')]():_0x1c88c2;return this[_0xb216('0x27')](util[_0xb216('0x2e')](_0xb216('0x3e'),_0x3747ef,_0x19b298?_0x19b298[_0xb216('0x3d')]()[_0xb216('0x12')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xb216('0x26')][_0xb216('0x3f')]=function(_0x88a489,_0x550de9){return this[_0xb216('0x27')](util[_0xb216('0x2e')](_0xb216('0x40'),_0x88a489,_0x550de9));};AGIChannel[_0xb216('0x26')][_0xb216('0x41')]=function(_0x2db804,_0x5d0b2b){return this['sendRequest'](util['format'](_0xb216('0x42'),_0x2db804,_0x5d0b2b));};AGIChannel[_0xb216('0x26')][_0xb216('0x43')]=function(_0x377000,_0x342af6){return this['sendRequest'](util['format']('SAY\x20PHONETIC\x20\x22%s\x22\x20%s',_0x377000,_0x342af6));};AGIChannel[_0xb216('0x26')][_0xb216('0x44')]=function(_0x4d3b90,_0x5a4826,_0x266760){_0x5a4826=_0x5a4826||this[_0xb216('0x45')];_0x266760=_0x266760||0x1;this['setContext'](_0x4d3b90);this[_0xb216('0x38')](_0x5a4826);this[_0xb216('0x46')](_0x266760);return this[_0xb216('0x30')](util[_0xb216('0x2e')](_0xb216('0x47'),_0x4d3b90,_0x5a4826,_0x266760));};AGIChannel[_0xb216('0x26')][_0xb216('0x48')]=function(_0x5eb418){console[_0xb216('0x22')](_0xb216('0x49'),_0x5eb418);return this[_0xb216('0x27')](util[_0xb216('0x2e')](_0xb216('0x4a'),_0x5eb418));};AGIChannel['prototype']['recordFile']=function(_0x5a3b45,_0x517ec1,_0x40127e,_0xd6d3da,_0x260b40,_0x4ff5e8){_0x517ec1=_0x517ec1||_0xb216('0x4b');_0x40127e=_0x40127e||'';_0xd6d3da=_0xd6d3da===undefined?-0x1:_0xd6d3da==='-1'?-0x1:_0xd6d3da*0x3e8;_0x260b40=_0x260b40===undefined?'':'s='+_0x260b40;_0x4ff5e8=_0x4ff5e8?_0xb216('0x4c'):'';return this[_0xb216('0x27')](util['format'](_0xb216('0x4d'),_0x5a3b45,_0x517ec1,_0x40127e,_0xd6d3da,_0x4ff5e8,_0x260b40));};AGIChannel[_0xb216('0x26')][_0xb216('0x4e')]=function(_0x5a0a41,_0x52cc7f){_0x52cc7f=_0x52cc7f||'';return this['sendRequest'](util[_0xb216('0x2e')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x5a0a41,_0x52cc7f));};AGIChannel[_0xb216('0x26')][_0xb216('0x4f')]=function(_0x3cb3af){return this[_0xb216('0x33')](_0xb216('0x50'),_0x3cb3af);};AGIChannel['prototype'][_0xb216('0x51')]=function(_0x50d5e0){return this[_0xb216('0x33')](_0xb216('0x52'),_0x50d5e0);};AGIChannel['prototype'][_0xb216('0x19')]=function(_0x3be047,_0x13bda5){this[_0xb216('0x30')](util['format']('ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s',_0x3be047['id'],_0x3be047[_0xb216('0x53')],_0x13bda5));return{'code':0x1f4,'result':'-1','extra':''};};module['exports']=AGIChannel;