0fe457c5781940f2416e12a040e4930e83b15b1b
[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 _0xb796=['E_AGI_SOCKET_TIMEOUT','destroy','function','write','inherits','prototype','command','sync','answer','getData','beep','sendRequest','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','isArray','EXEC\x20%s\x20%s','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isBoolean','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','sayNumber','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','noop','GOTO\x20%s\x20%s\x20%s','getVariable','GET\x20VARIABLE\x20\x22%s\x22','recordFile','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','agi','AGI','wait','label','exports','util','lodash','events','./error','call','setTimeout','setEncoding','utf8','headers','emit','ready','line','toLowerCase','hangup','substring','520-Invalid','search','520\x20End\x20of\x20proper','no\x20code','replace','result=','indexOf','substr','length','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout'];(function(_0x14bf63,_0xdbd373){var _0x410d22=function(_0x2e5e3a){while(--_0x2e5e3a){_0x14bf63['push'](_0x14bf63['shift']());}};_0x410d22(++_0xdbd373);}(_0xb796,0xd2));var _0x6b79=function(_0x5636a5,_0x2c6a23){_0x5636a5=_0x5636a5-0x0;var _0x2c774b=_0xb796[_0x5636a5];return _0x2c774b;};'use strict';var util=require(_0x6b79('0x0'));var _=require(_0x6b79('0x1'));var EventEmitter=require(_0x6b79('0x2'))['EventEmitter'];var AGIReply=require('./reply');var AGIError=require(_0x6b79('0x3'));function AGIChannel(_0x229129){var _0x17af53=this,_0x3ff52c=new AGIReply(),_0x3b4114=![],_0x16c2f4={};EventEmitter[_0x6b79('0x4')](_0x17af53);_0x229129['setEncoding']('utf8');_0x229129[_0x6b79('0x5')](0x8*0x3c*0x3c*0x3e8);_0x3ff52c[_0x6b79('0x6')](_0x6b79('0x7'));_0x3ff52c['on'](_0x6b79('0x8'),function(_0x246171){for(var _0x45d1bc in _0x246171){_0x17af53[_0x45d1bc]=_0x246171[_0x45d1bc];}_0x17af53[_0x6b79('0x9')](_0x6b79('0xa'));});_0x3ff52c['on'](_0x6b79('0xb'),function(_0x3263ce){if(_0x3263ce[_0x6b79('0xc')]()==_0x6b79('0xd')){_0x17af53[_0x6b79('0x9')]('hangup');return;}if(_0x3263ce[_0x6b79('0xe')](0x0,0xb)==_0x6b79('0xf')){_0x3b4114=!![];}if(_0x3b4114){_0x16c2f4['rx']+=_0x3263ce+'\x0a';if(_0x3263ce[_0x6b79('0x10')](_0x6b79('0x11'))!=-0x1){_0x3b4114=![];}}else{_0x16c2f4['rx']=_0x3263ce;}if(_0x3b4114){return;}if(typeof _0x16c2f4['cb']=='function'){var _0x3795b4=_0x16c2f4['rx'][_0x6b79('0xe')](0x0,0x3),_0x4863f8=null,_0x2d4526=null;_0x3795b4=parseInt(_0x3795b4);if(isNaN(_0x3795b4)){_0x16c2f4['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x6b79('0x12')});return;}if(_0x3795b4!=0xc8){_0x16c2f4['cb'](null,{'code':_0x3795b4,'result':-0x1,'extra':'KO'});return;}_0x4863f8=_0x16c2f4['rx'][_0x6b79('0xe')](0x4)[_0x6b79('0x13')](_0x6b79('0x14'),'');if(_0x4863f8[_0x6b79('0x15')]('\x20')!=-0x1){_0x4863f8=_0x4863f8[_0x6b79('0x16')](0x0,_0x4863f8['indexOf']('\x20'));}if(_['startsWith'](_0x4863f8,'-1')){_0x4863f8=parseInt(_0x4863f8);}_0x2d4526=_0x16c2f4['rx']['split']('\x20');if(_0x2d4526[_0x6b79('0x17')]==0x3){_0x2d4526=_0x2d4526[0x2]['substring'](0x1,_0x2d4526[0x2][_0x6b79('0x17')]-0x1);}else if(_0x2d4526[_0x6b79('0x17')]>0x3){var _0x406141=/\((.+)\)/;var _0x515404=_0x16c2f4['rx']['match'](_0x406141);if(_0x515404){_0x2d4526=_0x515404[0x1];}else{_0x2d4526=null;}}else{_0x2d4526=null;}_0x16c2f4['cb'](null,{'code':_0x3795b4,'result':_0x4863f8,'extra':_0x2d4526});}});_0x229129['on'](_0x6b79('0x18'),function(_0x404466){_0x17af53[_0x6b79('0x9')](_0x6b79('0x18'),new AGIError(_0x6b79('0x19'),_0x404466[_0x6b79('0x1a')]));});_0x229129['on'](_0x6b79('0x1b'),function(){_0x17af53[_0x6b79('0x9')](_0x6b79('0x1b'),new AGIError(_0x6b79('0x1c')));});_0x229129['on'](_0x6b79('0x1d'),function(){_0x17af53[_0x6b79('0x9')](_0x6b79('0x1d'),new AGIError(_0x6b79('0x1e')));_0x229129[_0x6b79('0x1f')]();});_0x229129['pipe'](_0x3ff52c);this['command']=function(_0x381456,_0xaa11ec){var _0x381456=_0x381456||'',_0xaa11ec=typeof _0xaa11ec==_0x6b79('0x20')?_0xaa11ec:new Function();_0x16c2f4={'tx':_0x381456,'rx':'','cb':_0xaa11ec};_0x229129[_0x6b79('0x21')](_0x381456+'\x0a');},this[_0x6b79('0x1b')]=function(){_0x229129[_0x6b79('0x1f')]();};}util[_0x6b79('0x22')](AGIChannel,EventEmitter);AGIChannel[_0x6b79('0x23')]['sendRequest']=function(_0x54e135){return this[_0x6b79('0x24')][_0x6b79('0x25')](this,_0x54e135);};AGIChannel['prototype'][_0x6b79('0x26')]=function(){return this['sendRequest']('ANSWER');};AGIChannel[_0x6b79('0x23')][_0x6b79('0x27')]=function(_0x18d0fd,_0x308368,_0x36d5d4){_0x18d0fd=_0x18d0fd===undefined?_0x6b79('0x28'):_0x18d0fd;_0x308368=_0x308368===undefined?'5':_0x308368;_0x36d5d4=_0x36d5d4===undefined?'1':_0x36d5d4;return this[_0x6b79('0x29')](util[_0x6b79('0x2a')](_0x6b79('0x2b'),_0x18d0fd,_0x308368*0x3e8,_0x36d5d4));};AGIChannel[_0x6b79('0x23')]['noop']=function(_0x3be081){_0x3be081=_0x3be081||_0x6b79('0x2c');return this['sendRequest'](util[_0x6b79('0x2a')](_0x6b79('0x2d'),_0x3be081));};AGIChannel['prototype'][_0x6b79('0x2e')]=function(_0xf24c6,_0x3c9eb6){if(_[_0x6b79('0x2f')](_0x3c9eb6)){return this[_0x6b79('0x29')](util[_0x6b79('0x2a')](_0x6b79('0x30'),_0xf24c6,_0x3c9eb6['join'](',')));}return this[_0x6b79('0x29')](util[_0x6b79('0x2a')]('EXEC\x20%s\x20%s',_0xf24c6,_0x3c9eb6));};AGIChannel[_0x6b79('0x23')][_0x6b79('0x31')]=function(_0xdad1c3){return this['sendRequest'](util[_0x6b79('0x2a')](_0x6b79('0x32'),_0xdad1c3));};AGIChannel[_0x6b79('0x23')][_0x6b79('0x33')]=function(_0x250955){return this[_0x6b79('0x29')](util[_0x6b79('0x2a')](_0x6b79('0x34'),_0x250955));};AGIChannel[_0x6b79('0x23')][_0x6b79('0x35')]=function(_0x4f06b6){return this[_0x6b79('0x29')](util['format'](_0x6b79('0x36'),_0x4f06b6));};AGIChannel[_0x6b79('0x23')][_0x6b79('0xd')]=function(){return this[_0x6b79('0x29')](_0x6b79('0x37'));};AGIChannel[_0x6b79('0x23')][_0x6b79('0x38')]=function(_0x1b22a4,_0x2104c6){var _0x26f4e8=_[_0x6b79('0x39')](_0x2104c6)||_[_0x6b79('0x3a')](_0x2104c6)?_0x2104c6[_0x6b79('0x3b')]():_0x2104c6;return this[_0x6b79('0x29')](util[_0x6b79('0x2a')](_0x6b79('0x3c'),_0x1b22a4,_0x26f4e8?_0x26f4e8[_0x6b79('0x3b')]()[_0x6b79('0x13')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x6b79('0x23')][_0x6b79('0x3d')]=function(_0x1eb115,_0x5cde30){return this[_0x6b79('0x29')](util[_0x6b79('0x2a')]('SAY\x20NUMBER\x20%s\x20%s',_0x1eb115,_0x5cde30));};AGIChannel[_0x6b79('0x23')]['sayDigits']=function(_0x68577d,_0x48b51f){return this[_0x6b79('0x29')](util[_0x6b79('0x2a')](_0x6b79('0x3e'),_0x68577d,_0x48b51f));};AGIChannel[_0x6b79('0x23')][_0x6b79('0x3f')]=function(_0x115812,_0x4fee78){return this['sendRequest'](util[_0x6b79('0x2a')](_0x6b79('0x40'),_0x115812,_0x4fee78));};AGIChannel[_0x6b79('0x23')][_0x6b79('0x41')]=function(_0xeea26a,_0x353c86,_0xabae45){_0x353c86=_0x353c86||this[_0x6b79('0x42')];_0xabae45=_0xabae45||0x1;this[_0x6b79('0x31')](_0xeea26a);this['setExtension'](_0x353c86);this[_0x6b79('0x35')](_0xabae45);return this[_0x6b79('0x43')](util[_0x6b79('0x2a')](_0x6b79('0x44'),_0xeea26a,_0x353c86,_0xabae45));};AGIChannel['prototype'][_0x6b79('0x45')]=function(_0x55aeb2){return this[_0x6b79('0x29')](util[_0x6b79('0x2a')](_0x6b79('0x46'),_0x55aeb2));};AGIChannel[_0x6b79('0x23')][_0x6b79('0x47')]=function(_0xa5d8f5,_0x564bb2,_0x271bf1,_0x156855,_0x458e9d,_0x434a51){_0x564bb2=_0x564bb2||'wav';_0x271bf1=_0x271bf1||'';_0x156855=_0x156855===undefined?-0x1:_0x156855==='-1'?-0x1:_0x156855*0x3e8;_0x458e9d=_0x458e9d===undefined?'':'s='+_0x458e9d;_0x434a51=_0x434a51?_0x6b79('0x48'):'';return this[_0x6b79('0x29')](util[_0x6b79('0x2a')](_0x6b79('0x49'),_0xa5d8f5,_0x564bb2,_0x271bf1,_0x156855,_0x434a51,_0x458e9d));};AGIChannel[_0x6b79('0x23')]['streamFile']=function(_0x228857,_0x37f5c3){_0x37f5c3=_0x37f5c3||'';return this[_0x6b79('0x29')](util[_0x6b79('0x2a')](_0x6b79('0x4a'),_0x228857,_0x37f5c3));};AGIChannel[_0x6b79('0x23')][_0x6b79('0x4b')]=function(_0x1b5873){return this[_0x6b79('0x2e')](_0x6b79('0x4c'),_0x1b5873);};AGIChannel[_0x6b79('0x23')][_0x6b79('0x4d')]=function(_0x2d49e0){return this[_0x6b79('0x2e')]('WAIT',_0x2d49e0);};AGIChannel[_0x6b79('0x23')][_0x6b79('0x18')]=function(_0x4bc29f,_0x531f36){this[_0x6b79('0x43')](util[_0x6b79('0x2a')]('ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s',_0x4bc29f['id'],_0x4bc29f[_0x6b79('0x4e')],_0x531f36));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x6b79('0x4f')]=AGIChannel;