1b9e2a1bf24ce3da301c2a09a134cb8f3b013991
[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 _0x1c3a=['exports','util','lodash','events','./reply','./error','call','utf8','setTimeout','setEncoding','headers','ready','line','toLowerCase','hangup','emit','substring','520\x20End\x20of\x20proper','function','no\x20code','replace','result=','indexOf','substr','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','pipe','write','destroy','inherits','prototype','sendRequest','command','sync','ANSWER','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','EXEC\x20%s\x20%s','join','setContext','setExtension','setPriority','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isBoolean','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','GOTO\x20%s\x20%s\x20%s','getVariable','recordFile','wav','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','streamFile','AGI','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label'];(function(_0x1233d9,_0x3ca200){var _0x44b5d3=function(_0x35f3bd){while(--_0x35f3bd){_0x1233d9['push'](_0x1233d9['shift']());}};_0x44b5d3(++_0x3ca200);}(_0x1c3a,0x9d));var _0xa1c3=function(_0xe4ee1e,_0xea8b9b){_0xe4ee1e=_0xe4ee1e-0x0;var _0x22f903=_0x1c3a[_0xe4ee1e];return _0x22f903;};'use strict';var util=require(_0xa1c3('0x0'));var _=require(_0xa1c3('0x1'));var EventEmitter=require(_0xa1c3('0x2'))['EventEmitter'];var AGIReply=require(_0xa1c3('0x3'));var AGIError=require(_0xa1c3('0x4'));function AGIChannel(_0x20b8b5){var _0xf9a98b=this,_0x5ee23f=new AGIReply(),_0xfca3d=![],_0x5d08c7={};EventEmitter[_0xa1c3('0x5')](_0xf9a98b);_0x20b8b5['setEncoding'](_0xa1c3('0x6'));_0x20b8b5[_0xa1c3('0x7')](0x8*0x3c*0x3c*0x3e8);_0x5ee23f[_0xa1c3('0x8')](_0xa1c3('0x6'));_0x5ee23f['on'](_0xa1c3('0x9'),function(_0x23a8dc){for(var _0x208c73 in _0x23a8dc){_0xf9a98b[_0x208c73]=_0x23a8dc[_0x208c73];}_0xf9a98b['emit'](_0xa1c3('0xa'));});_0x5ee23f['on'](_0xa1c3('0xb'),function(_0xfb31b6){if(_0xfb31b6[_0xa1c3('0xc')]()==_0xa1c3('0xd')){_0xf9a98b[_0xa1c3('0xe')](_0xa1c3('0xd'));return;}if(_0xfb31b6[_0xa1c3('0xf')](0x0,0xb)=='520-Invalid'){_0xfca3d=!![];}if(_0xfca3d){_0x5d08c7['rx']+=_0xfb31b6+'\x0a';if(_0xfb31b6['search'](_0xa1c3('0x10'))!=-0x1){_0xfca3d=![];}}else{_0x5d08c7['rx']=_0xfb31b6;}if(_0xfca3d){return;}if(typeof _0x5d08c7['cb']==_0xa1c3('0x11')){var _0x545854=_0x5d08c7['rx']['substring'](0x0,0x3),_0x869c36=null,_0x4f1aa0=null;_0x545854=parseInt(_0x545854);if(isNaN(_0x545854)){_0x5d08c7['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xa1c3('0x12')});return;}if(_0x545854!=0xc8){_0x5d08c7['cb'](null,{'code':_0x545854,'result':-0x1,'extra':'KO'});return;}_0x869c36=_0x5d08c7['rx'][_0xa1c3('0xf')](0x4)[_0xa1c3('0x13')](_0xa1c3('0x14'),'');if(_0x869c36[_0xa1c3('0x15')]('\x20')!=-0x1){_0x869c36=_0x869c36[_0xa1c3('0x16')](0x0,_0x869c36[_0xa1c3('0x15')]('\x20'));}if(_[_0xa1c3('0x17')](_0x869c36,'-1')){_0x869c36=parseInt(_0x869c36);}_0x4f1aa0=_0x5d08c7['rx'][_0xa1c3('0x18')]('\x20');if(_0x4f1aa0[_0xa1c3('0x19')]==0x3){_0x4f1aa0=_0x4f1aa0[0x2][_0xa1c3('0xf')](0x1,_0x4f1aa0[0x2]['length']-0x1);}else if(_0x4f1aa0[_0xa1c3('0x19')]>0x3){var _0x51acce=/\((.+)\)/;var _0x3500f8=_0x5d08c7['rx'][_0xa1c3('0x1a')](_0x51acce);if(_0x3500f8){_0x4f1aa0=_0x3500f8[0x1];}else{_0x4f1aa0=null;}}else{_0x4f1aa0=null;}_0x5d08c7['cb'](null,{'code':_0x545854,'result':_0x869c36,'extra':_0x4f1aa0});}});_0x20b8b5['on']('error',function(_0x282d52){_0xf9a98b[_0xa1c3('0xe')](_0xa1c3('0x1b'),new AGIError(_0xa1c3('0x1c'),_0x282d52[_0xa1c3('0x1d')]));});_0x20b8b5['on'](_0xa1c3('0x1e'),function(){_0xf9a98b[_0xa1c3('0xe')](_0xa1c3('0x1e'),new AGIError(_0xa1c3('0x1f')));});_0x20b8b5['on']('timeout',function(){_0xf9a98b[_0xa1c3('0xe')]('timeout',new AGIError('E_AGI_SOCKET_TIMEOUT'));_0x20b8b5['destroy']();});_0x20b8b5[_0xa1c3('0x20')](_0x5ee23f);this['command']=function(_0x11aa29,_0x3246df){var _0x11aa29=_0x11aa29||'',_0x3246df=typeof _0x3246df==_0xa1c3('0x11')?_0x3246df:new Function();_0x5d08c7={'tx':_0x11aa29,'rx':'','cb':_0x3246df};_0x20b8b5[_0xa1c3('0x21')](_0x11aa29+'\x0a');},this[_0xa1c3('0x1e')]=function(){_0x20b8b5[_0xa1c3('0x22')]();};}util[_0xa1c3('0x23')](AGIChannel,EventEmitter);AGIChannel[_0xa1c3('0x24')][_0xa1c3('0x25')]=function(_0x3451fb){return this[_0xa1c3('0x26')][_0xa1c3('0x27')](this,_0x3451fb);};AGIChannel[_0xa1c3('0x24')]['answer']=function(){return this[_0xa1c3('0x25')](_0xa1c3('0x28'));};AGIChannel[_0xa1c3('0x24')][_0xa1c3('0x29')]=function(_0x2e731c,_0x46308e,_0x4568d6){_0x2e731c=_0x2e731c===undefined?_0xa1c3('0x2a'):_0x2e731c;_0x46308e=_0x46308e===undefined?'5':_0x46308e;_0x4568d6=_0x4568d6===undefined?'1':_0x4568d6;return this[_0xa1c3('0x25')](util[_0xa1c3('0x2b')](_0xa1c3('0x2c'),_0x2e731c,_0x46308e*0x3e8,_0x4568d6));};AGIChannel['prototype'][_0xa1c3('0x2d')]=function(_0x266771){_0x266771=_0x266771||_0xa1c3('0x2e');return this[_0xa1c3('0x25')](util[_0xa1c3('0x2b')](_0xa1c3('0x2f'),_0x266771));};AGIChannel[_0xa1c3('0x24')][_0xa1c3('0x30')]=function(_0x18f981,_0x4903be){if(_['isArray'](_0x4903be)){return this[_0xa1c3('0x25')](util[_0xa1c3('0x2b')](_0xa1c3('0x31'),_0x18f981,_0x4903be[_0xa1c3('0x32')](',')));}return this[_0xa1c3('0x25')](util['format'](_0xa1c3('0x31'),_0x18f981,_0x4903be));};AGIChannel[_0xa1c3('0x24')][_0xa1c3('0x33')]=function(_0x4472c6){return this[_0xa1c3('0x25')](util[_0xa1c3('0x2b')]('SET\x20CONTEXT\x20%s',_0x4472c6));};AGIChannel['prototype'][_0xa1c3('0x34')]=function(_0x49b589){return this[_0xa1c3('0x25')](util[_0xa1c3('0x2b')]('SET\x20EXTENSION\x20%s',_0x49b589));};AGIChannel['prototype'][_0xa1c3('0x35')]=function(_0x6fd33e){return this['sendRequest'](util[_0xa1c3('0x2b')](_0xa1c3('0x36'),_0x6fd33e));};AGIChannel['prototype'][_0xa1c3('0xd')]=function(){return this[_0xa1c3('0x25')](_0xa1c3('0x37'));};AGIChannel[_0xa1c3('0x24')][_0xa1c3('0x38')]=function(_0x3af2cf,_0x540363){var _0x20c968=_[_0xa1c3('0x39')](_0x540363)||_[_0xa1c3('0x3a')](_0x540363)?_0x540363[_0xa1c3('0x3b')]():_0x540363;return this[_0xa1c3('0x25')](util['format'](_0xa1c3('0x3c'),_0x3af2cf,_0x20c968?_0x20c968[_0xa1c3('0x3b')]()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xa1c3('0x24')][_0xa1c3('0x3d')]=function(_0x4cf884,_0x4970a6){return this[_0xa1c3('0x25')](util[_0xa1c3('0x2b')](_0xa1c3('0x3e'),_0x4cf884,_0x4970a6));};AGIChannel['prototype'][_0xa1c3('0x3f')]=function(_0x1fb2ad,_0x3925a9){return this[_0xa1c3('0x25')](util['format']('SAY\x20DIGITS\x20%s\x20%s',_0x1fb2ad,_0x3925a9));};AGIChannel[_0xa1c3('0x24')]['sayPhonetic']=function(_0x1312b5,_0x2fa2c8){return this['sendRequest'](util['format'](_0xa1c3('0x40'),_0x1312b5,_0x2fa2c8));};AGIChannel[_0xa1c3('0x24')][_0xa1c3('0x41')]=function(_0x1b9c27,_0x20d828,_0x468837){_0x20d828=_0x20d828||this[_0xa1c3('0x42')];_0x468837=_0x468837||0x1;this[_0xa1c3('0x33')](_0x1b9c27);this[_0xa1c3('0x34')](_0x20d828);this[_0xa1c3('0x35')](_0x468837);return this[_0xa1c3('0x2d')](util[_0xa1c3('0x2b')](_0xa1c3('0x43'),_0x1b9c27,_0x20d828,_0x468837));};AGIChannel['prototype'][_0xa1c3('0x44')]=function(_0x2a0565){return this[_0xa1c3('0x25')](util[_0xa1c3('0x2b')]('GET\x20VARIABLE\x20\x22%s\x22',_0x2a0565));};AGIChannel['prototype'][_0xa1c3('0x45')]=function(_0x5bbaa9,_0x436307,_0x110fe1,_0x95e9c8,_0x2e7422,_0x1789b9){_0x436307=_0x436307||_0xa1c3('0x46');_0x110fe1=_0x110fe1||'';_0x95e9c8=_0x95e9c8===undefined?-0x1:_0x95e9c8==='-1'?-0x1:_0x95e9c8*0x3e8;_0x2e7422=_0x2e7422===undefined?'':'s='+_0x2e7422;_0x1789b9=_0x1789b9?_0xa1c3('0x47'):'';return this[_0xa1c3('0x25')](util[_0xa1c3('0x2b')](_0xa1c3('0x48'),_0x5bbaa9,_0x436307,_0x110fe1,_0x95e9c8,_0x1789b9,_0x2e7422));};AGIChannel[_0xa1c3('0x24')][_0xa1c3('0x49')]=function(_0x4087e8,_0x2db568){_0x2db568=_0x2db568||'';return this[_0xa1c3('0x25')](util[_0xa1c3('0x2b')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x4087e8,_0x2db568));};AGIChannel[_0xa1c3('0x24')]['agi']=function(_0x684aaf){return this[_0xa1c3('0x30')](_0xa1c3('0x4a'),_0x684aaf);};AGIChannel[_0xa1c3('0x24')]['wait']=function(_0xf6facf){return this['exec']('WAIT',_0xf6facf);};AGIChannel[_0xa1c3('0x24')]['error']=function(_0x3cfbb7,_0x3a3b80){this[_0xa1c3('0x2d')](util[_0xa1c3('0x2b')](_0xa1c3('0x4b'),_0x3cfbb7['id'],_0x3cfbb7[_0xa1c3('0x4c')],_0x3a3b80));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xa1c3('0x4d')]=AGIChannel;