24230bf98733b63d6c1679a1e3296a1286c95ded
[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 _0x919f=['sayNumber','sayDigits','sayPhonetic','extension','setExtension','GOTO\x20%s\x20%s\x20%s','getVariable','recordFile','wav','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','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','lodash','events','EventEmitter','./error','call','setEncoding','utf8','setTimeout','headers','emit','ready','line','hangup','substring','520-Invalid','search','520\x20End\x20of\x20proper','function','no\x20code','replace','result=','substr','indexOf','startsWith','length','match','error','E_AGI_SOCKET_ERROR','code','close','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','command','write','inherits','prototype','sendRequest','sync','answer','ANSWER','getData','noop','NO\x20MESSAGE','format','VERBOSE\x20\x22%s\x22','exec','join','EXEC\x20%s\x20%s','setContext','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isBoolean','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22'];(function(_0xe616be,_0x1ca4c1){var _0x5d5e81=function(_0x3ecd3d){while(--_0x3ecd3d){_0xe616be['push'](_0xe616be['shift']());}};_0x5d5e81(++_0x1ca4c1);}(_0x919f,0x192));var _0xf919=function(_0x45dc5b,_0x1c532b){_0x45dc5b=_0x45dc5b-0x0;var _0x2b67a6=_0x919f[_0x45dc5b];return _0x2b67a6;};'use strict';var util=require('util');var _=require(_0xf919('0x0'));var EventEmitter=require(_0xf919('0x1'))[_0xf919('0x2')];var AGIReply=require('./reply');var AGIError=require(_0xf919('0x3'));function AGIChannel(_0x3f561a){var _0x54e13d=this,_0x8e786b=new AGIReply(),_0x82e271=![],_0x57a6dc={};EventEmitter[_0xf919('0x4')](_0x54e13d);_0x3f561a[_0xf919('0x5')](_0xf919('0x6'));_0x3f561a[_0xf919('0x7')](0x8*0x3c*0x3c*0x3e8);_0x8e786b[_0xf919('0x5')](_0xf919('0x6'));_0x8e786b['on'](_0xf919('0x8'),function(_0x995941){for(var _0x5855a6 in _0x995941){_0x54e13d[_0x5855a6]=_0x995941[_0x5855a6];}_0x54e13d[_0xf919('0x9')](_0xf919('0xa'));});_0x8e786b['on'](_0xf919('0xb'),function(_0x47eb4c){if(_0x47eb4c['toLowerCase']()==_0xf919('0xc')){_0x54e13d[_0xf919('0x9')](_0xf919('0xc'));return;}if(_0x47eb4c[_0xf919('0xd')](0x0,0xb)==_0xf919('0xe')){_0x82e271=!![];}if(_0x82e271){_0x57a6dc['rx']+=_0x47eb4c+'\x0a';if(_0x47eb4c[_0xf919('0xf')](_0xf919('0x10'))!=-0x1){_0x82e271=![];}}else{_0x57a6dc['rx']=_0x47eb4c;}if(_0x82e271){return;}if(typeof _0x57a6dc['cb']==_0xf919('0x11')){var _0x2ce0ab=_0x57a6dc['rx']['substring'](0x0,0x3),_0x53cb23=null,_0x34f120=null;_0x2ce0ab=parseInt(_0x2ce0ab);if(isNaN(_0x2ce0ab)){_0x57a6dc['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xf919('0x12')});return;}if(_0x2ce0ab!=0xc8){_0x57a6dc['cb'](null,{'code':_0x2ce0ab,'result':-0x1,'extra':'KO'});return;}_0x53cb23=_0x57a6dc['rx'][_0xf919('0xd')](0x4)[_0xf919('0x13')](_0xf919('0x14'),'');if(_0x53cb23['indexOf']('\x20')!=-0x1){_0x53cb23=_0x53cb23[_0xf919('0x15')](0x0,_0x53cb23[_0xf919('0x16')]('\x20'));}if(_[_0xf919('0x17')](_0x53cb23,'-1')){_0x53cb23=parseInt(_0x53cb23);}_0x34f120=_0x57a6dc['rx']['split']('\x20');if(_0x34f120[_0xf919('0x18')]==0x3){_0x34f120=_0x34f120[0x2][_0xf919('0xd')](0x1,_0x34f120[0x2][_0xf919('0x18')]-0x1);}else if(_0x34f120['length']>0x3){var _0xc2751e=/\((.+)\)/;var _0x2fa00b=_0x57a6dc['rx'][_0xf919('0x19')](_0xc2751e);if(_0x2fa00b){_0x34f120=_0x2fa00b[0x1];}else{_0x34f120=null;}}else{_0x34f120=null;}_0x57a6dc['cb'](null,{'code':_0x2ce0ab,'result':_0x53cb23,'extra':_0x34f120});}});_0x3f561a['on'](_0xf919('0x1a'),function(_0x484eec){_0x54e13d[_0xf919('0x9')](_0xf919('0x1a'),new AGIError(_0xf919('0x1b'),_0x484eec[_0xf919('0x1c')]));});_0x3f561a['on'](_0xf919('0x1d'),function(){_0x54e13d[_0xf919('0x9')](_0xf919('0x1d'),new AGIError('E_AGI_SOCKET_CLOSE'));});_0x3f561a['on'](_0xf919('0x1e'),function(){_0x54e13d[_0xf919('0x9')](_0xf919('0x1e'),new AGIError(_0xf919('0x1f')));_0x3f561a[_0xf919('0x20')]();});_0x3f561a[_0xf919('0x21')](_0x8e786b);this[_0xf919('0x22')]=function(_0x5192c8,_0xe50023){var _0x5192c8=_0x5192c8||'',_0xe50023=typeof _0xe50023=='function'?_0xe50023:new Function();_0x57a6dc={'tx':_0x5192c8,'rx':'','cb':_0xe50023};_0x3f561a[_0xf919('0x23')](_0x5192c8+'\x0a');},this['close']=function(){_0x3f561a[_0xf919('0x20')]();};}util[_0xf919('0x24')](AGIChannel,EventEmitter);AGIChannel[_0xf919('0x25')][_0xf919('0x26')]=function(_0x10debf){return this['command'][_0xf919('0x27')](this,_0x10debf);};AGIChannel[_0xf919('0x25')][_0xf919('0x28')]=function(){return this[_0xf919('0x26')](_0xf919('0x29'));};AGIChannel['prototype'][_0xf919('0x2a')]=function(_0x5713ef,_0x1961fb,_0x41bee0){_0x5713ef=_0x5713ef===undefined?'beep':_0x5713ef;_0x1961fb=_0x1961fb===undefined?'5':_0x1961fb;_0x41bee0=_0x41bee0===undefined?'1':_0x41bee0;return this[_0xf919('0x26')](util['format']('GET\x20DATA\x20\x22%s\x22\x20%s\x20%s',_0x5713ef,_0x1961fb*0x3e8,_0x41bee0));};AGIChannel[_0xf919('0x25')][_0xf919('0x2b')]=function(_0x369537){_0x369537=_0x369537||_0xf919('0x2c');return this['sendRequest'](util[_0xf919('0x2d')](_0xf919('0x2e'),_0x369537));};AGIChannel[_0xf919('0x25')][_0xf919('0x2f')]=function(_0x39651,_0x3bacbb){if(_['isArray'](_0x3bacbb)){return this['sendRequest'](util['format']('EXEC\x20%s\x20%s',_0x39651,_0x3bacbb[_0xf919('0x30')](',')));}return this[_0xf919('0x26')](util[_0xf919('0x2d')](_0xf919('0x31'),_0x39651,_0x3bacbb));};AGIChannel[_0xf919('0x25')][_0xf919('0x32')]=function(_0x149276){return this[_0xf919('0x26')](util[_0xf919('0x2d')]('SET\x20CONTEXT\x20%s',_0x149276));};AGIChannel['prototype']['setExtension']=function(_0x11cb20){return this[_0xf919('0x26')](util[_0xf919('0x2d')](_0xf919('0x33'),_0x11cb20));};AGIChannel[_0xf919('0x25')][_0xf919('0x34')]=function(_0x5c209c){return this[_0xf919('0x26')](util[_0xf919('0x2d')](_0xf919('0x35'),_0x5c209c));};AGIChannel[_0xf919('0x25')][_0xf919('0xc')]=function(){return this[_0xf919('0x26')](_0xf919('0x36'));};AGIChannel[_0xf919('0x25')][_0xf919('0x37')]=function(_0x5caf45,_0x596256){var _0x3c49b7=_[_0xf919('0x38')](_0x596256)||_[_0xf919('0x39')](_0x596256)?_0x596256[_0xf919('0x3a')]():_0x596256;return this[_0xf919('0x26')](util[_0xf919('0x2d')](_0xf919('0x3b'),_0x5caf45,_0x3c49b7?_0x3c49b7['toString']()[_0xf919('0x13')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xf919('0x25')][_0xf919('0x3c')]=function(_0x46c307,_0x9deedd){return this[_0xf919('0x26')](util[_0xf919('0x2d')]('SAY\x20NUMBER\x20%s\x20%s',_0x46c307,_0x9deedd));};AGIChannel['prototype'][_0xf919('0x3d')]=function(_0x40daf4,_0x283ae0){return this[_0xf919('0x26')](util['format']('SAY\x20DIGITS\x20%s\x20%s',_0x40daf4,_0x283ae0));};AGIChannel[_0xf919('0x25')][_0xf919('0x3e')]=function(_0x4f1cb5,_0x40213f){return this[_0xf919('0x26')](util['format']('SAY\x20PHONETIC\x20\x22%s\x22\x20%s',_0x4f1cb5,_0x40213f));};AGIChannel[_0xf919('0x25')]['continueAt']=function(_0x3a97b8,_0x40c649,_0x2c9775){_0x40c649=_0x40c649||this[_0xf919('0x3f')];_0x2c9775=_0x2c9775||0x1;this[_0xf919('0x32')](_0x3a97b8);this[_0xf919('0x40')](_0x40c649);this[_0xf919('0x34')](_0x2c9775);return this[_0xf919('0x2b')](util[_0xf919('0x2d')](_0xf919('0x41'),_0x3a97b8,_0x40c649,_0x2c9775));};AGIChannel[_0xf919('0x25')][_0xf919('0x42')]=function(_0x2e22b5){return this[_0xf919('0x26')](util[_0xf919('0x2d')]('GET\x20VARIABLE\x20\x22%s\x22',_0x2e22b5));};AGIChannel[_0xf919('0x25')][_0xf919('0x43')]=function(_0x1f67b3,_0x30f58f,_0x5e2f73,_0x58f54b,_0x5cc29c,_0x29a858){_0x30f58f=_0x30f58f||_0xf919('0x44');_0x5e2f73=_0x5e2f73||'';_0x58f54b=_0x58f54b===undefined?-0x1:_0x58f54b==='-1'?-0x1:_0x58f54b*0x3e8;_0x5cc29c=_0x5cc29c===undefined?'':'s='+_0x5cc29c;_0x29a858=_0x29a858?'BEEP':'';return this[_0xf919('0x26')](util[_0xf919('0x2d')](_0xf919('0x45'),_0x1f67b3,_0x30f58f,_0x5e2f73,_0x58f54b,_0x29a858,_0x5cc29c));};AGIChannel[_0xf919('0x25')][_0xf919('0x46')]=function(_0x1140b5,_0x1ff539){_0x1ff539=_0x1ff539||'';return this[_0xf919('0x26')](util[_0xf919('0x2d')](_0xf919('0x47'),_0x1140b5,_0x1ff539));};AGIChannel[_0xf919('0x25')][_0xf919('0x48')]=function(_0x11983d){return this['exec']('AGI',_0x11983d);};AGIChannel[_0xf919('0x25')]['wait']=function(_0x195d33){return this[_0xf919('0x2f')](_0xf919('0x49'),_0x195d33);};AGIChannel[_0xf919('0x25')][_0xf919('0x1a')]=function(_0x1a5859,_0x40e81a){this[_0xf919('0x2b')](util[_0xf919('0x2d')](_0xf919('0x4a'),_0x1a5859['id'],_0x1a5859[_0xf919('0x4b')],_0x40e81a));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xf919('0x4c')]=AGIChannel;