cff6342dba5bc18bc64c64ca0c72168ff1da4534
[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 _0x8991=['prototype','sendRequest','answer','ANSWER','getData','beep','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','format','EXEC\x20%s\x20%s','join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','HANGUP','setVariable','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','sayNumber','SAY\x20DIGITS\x20%s\x20%s','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','noop','GOTO\x20%s\x20%s\x20%s','getVariable','GET\x20VARIABLE\x20\x22%s\x22','recordFile','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','label','exports','util','lodash','./reply','./error','call','setEncoding','utf8','setTimeout','headers','emit','line','toLowerCase','hangup','substring','520-Invalid','function','no\x20code','replace','result=','substr','indexOf','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','pipe','command','write','inherits'];(function(_0x137981,_0x5caa53){var _0x4ebc80=function(_0x34660f){while(--_0x34660f){_0x137981['push'](_0x137981['shift']());}};_0x4ebc80(++_0x5caa53);}(_0x8991,0x1b0));var _0x1899=function(_0x3fa04a,_0x1b5d83){_0x3fa04a=_0x3fa04a-0x0;var _0x3008bc=_0x8991[_0x3fa04a];return _0x3008bc;};'use strict';var util=require(_0x1899('0x0'));var _=require(_0x1899('0x1'));var EventEmitter=require('events')['EventEmitter'];var AGIReply=require(_0x1899('0x2'));var AGIError=require(_0x1899('0x3'));function AGIChannel(_0xd45726){var _0x1183f1=this,_0xdf3e4d=new AGIReply(),_0x32df91=![],_0x2d3712={};EventEmitter[_0x1899('0x4')](_0x1183f1);_0xd45726[_0x1899('0x5')](_0x1899('0x6'));_0xd45726[_0x1899('0x7')](0x8*0x3c*0x3c*0x3e8);_0xdf3e4d[_0x1899('0x5')](_0x1899('0x6'));_0xdf3e4d['on'](_0x1899('0x8'),function(_0x5ae1ca){for(var _0x1259f4 in _0x5ae1ca){_0x1183f1[_0x1259f4]=_0x5ae1ca[_0x1259f4];}_0x1183f1[_0x1899('0x9')]('ready');});_0xdf3e4d['on'](_0x1899('0xa'),function(_0x17b8b){if(_0x17b8b[_0x1899('0xb')]()=='hangup'){_0x1183f1[_0x1899('0x9')](_0x1899('0xc'));return;}if(_0x17b8b[_0x1899('0xd')](0x0,0xb)==_0x1899('0xe')){_0x32df91=!![];}if(_0x32df91){_0x2d3712['rx']+=_0x17b8b+'\x0a';if(_0x17b8b['search']('520\x20End\x20of\x20proper')!=-0x1){_0x32df91=![];}}else{_0x2d3712['rx']=_0x17b8b;}if(_0x32df91){return;}if(typeof _0x2d3712['cb']==_0x1899('0xf')){var _0x5e1353=_0x2d3712['rx']['substring'](0x0,0x3),_0x22ca67=null,_0x308c2b=null;_0x5e1353=parseInt(_0x5e1353);if(isNaN(_0x5e1353)){_0x2d3712['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x1899('0x10')});return;}if(_0x5e1353!=0xc8){_0x2d3712['cb'](null,{'code':_0x5e1353,'result':-0x1,'extra':'KO'});return;}_0x22ca67=_0x2d3712['rx'][_0x1899('0xd')](0x4)[_0x1899('0x11')](_0x1899('0x12'),'');if(_0x22ca67['indexOf']('\x20')!=-0x1){_0x22ca67=_0x22ca67[_0x1899('0x13')](0x0,_0x22ca67[_0x1899('0x14')]('\x20'));}if(_[_0x1899('0x15')](_0x22ca67,'-1')){_0x22ca67=parseInt(_0x22ca67);}_0x308c2b=_0x2d3712['rx'][_0x1899('0x16')]('\x20');if(_0x308c2b[_0x1899('0x17')]==0x3){_0x308c2b=_0x308c2b[0x2][_0x1899('0xd')](0x1,_0x308c2b[0x2][_0x1899('0x17')]-0x1);}else if(_0x308c2b['length']>0x3){var _0x5ba31b=/\((.+)\)/;var _0x56e781=_0x2d3712['rx'][_0x1899('0x18')](_0x5ba31b);if(_0x56e781){_0x308c2b=_0x56e781[0x1];}else{_0x308c2b=null;}}else{_0x308c2b=null;}_0x2d3712['cb'](null,{'code':_0x5e1353,'result':_0x22ca67,'extra':_0x308c2b});}});_0xd45726['on']('error',function(_0x2dfca0){_0x1183f1['emit'](_0x1899('0x19'),new AGIError(_0x1899('0x1a'),_0x2dfca0[_0x1899('0x1b')]));});_0xd45726['on'](_0x1899('0x1c'),function(){_0x1183f1[_0x1899('0x9')](_0x1899('0x1c'),new AGIError(_0x1899('0x1d')));});_0xd45726['on'](_0x1899('0x1e'),function(){_0x1183f1[_0x1899('0x9')](_0x1899('0x1e'),new AGIError(_0x1899('0x1f')));_0xd45726['destroy']();});_0xd45726[_0x1899('0x20')](_0xdf3e4d);this[_0x1899('0x21')]=function(_0x4f346c,_0x4a3aad){var _0x4f346c=_0x4f346c||'',_0x4a3aad=typeof _0x4a3aad==_0x1899('0xf')?_0x4a3aad:new Function();_0x2d3712={'tx':_0x4f346c,'rx':'','cb':_0x4a3aad};_0xd45726[_0x1899('0x22')](_0x4f346c+'\x0a');},this[_0x1899('0x1c')]=function(){_0xd45726['destroy']();};}util[_0x1899('0x23')](AGIChannel,EventEmitter);AGIChannel[_0x1899('0x24')][_0x1899('0x25')]=function(_0x11291a){return this[_0x1899('0x21')]['sync'](this,_0x11291a);};AGIChannel['prototype'][_0x1899('0x26')]=function(){return this[_0x1899('0x25')](_0x1899('0x27'));};AGIChannel[_0x1899('0x24')][_0x1899('0x28')]=function(_0xeb41f6,_0x2ba3b2,_0x53b59e){_0xeb41f6=_0xeb41f6===undefined?_0x1899('0x29'):_0xeb41f6;_0x2ba3b2=_0x2ba3b2===undefined?'5':_0x2ba3b2;_0x53b59e=_0x53b59e===undefined?'1':_0x53b59e;return this[_0x1899('0x25')](util['format'](_0x1899('0x2a'),_0xeb41f6,_0x2ba3b2*0x3e8,_0x53b59e));};AGIChannel[_0x1899('0x24')]['noop']=function(_0x55d2f9){_0x55d2f9=_0x55d2f9||_0x1899('0x2b');return this[_0x1899('0x25')](util['format'](_0x1899('0x2c'),_0x55d2f9));};AGIChannel[_0x1899('0x24')][_0x1899('0x2d')]=function(_0x2dddae,_0x17d39d){if(_['isArray'](_0x17d39d)){return this[_0x1899('0x25')](util[_0x1899('0x2e')](_0x1899('0x2f'),_0x2dddae,_0x17d39d[_0x1899('0x30')](',')));}return this['sendRequest'](util[_0x1899('0x2e')]('EXEC\x20%s\x20%s',_0x2dddae,_0x17d39d));};AGIChannel[_0x1899('0x24')][_0x1899('0x31')]=function(_0x11f930){return this[_0x1899('0x25')](util[_0x1899('0x2e')](_0x1899('0x32'),_0x11f930));};AGIChannel[_0x1899('0x24')][_0x1899('0x33')]=function(_0x416de7){return this[_0x1899('0x25')](util[_0x1899('0x2e')](_0x1899('0x34'),_0x416de7));};AGIChannel[_0x1899('0x24')][_0x1899('0x35')]=function(_0x82bf77){return this['sendRequest'](util[_0x1899('0x2e')]('SET\x20PRIORITY\x20%s',_0x82bf77));};AGIChannel[_0x1899('0x24')]['hangup']=function(){return this['sendRequest'](_0x1899('0x36'));};AGIChannel[_0x1899('0x24')][_0x1899('0x37')]=function(_0x56fa5a,_0x504b28){var _0x4bea56=_['isBoolean'](_0x504b28)||_[_0x1899('0x38')](_0x504b28)?_0x504b28[_0x1899('0x39')]():_0x504b28;return this[_0x1899('0x25')](util[_0x1899('0x2e')](_0x1899('0x3a'),_0x56fa5a,_0x4bea56?_0x4bea56['toString']()[_0x1899('0x11')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x1899('0x24')][_0x1899('0x3b')]=function(_0x3fa881,_0x39045c){return this[_0x1899('0x25')](util['format']('SAY\x20NUMBER\x20%s\x20%s',_0x3fa881,_0x39045c));};AGIChannel[_0x1899('0x24')]['sayDigits']=function(_0x599c7a,_0x81c10c){return this['sendRequest'](util[_0x1899('0x2e')](_0x1899('0x3c'),_0x599c7a,_0x81c10c));};AGIChannel[_0x1899('0x24')]['sayPhonetic']=function(_0x578f52,_0x1225a1){return this['sendRequest'](util['format'](_0x1899('0x3d'),_0x578f52,_0x1225a1));};AGIChannel[_0x1899('0x24')]['continueAt']=function(_0x425f64,_0x7b1ea7,_0x8da3ce){_0x7b1ea7=_0x7b1ea7||this['extension'];_0x8da3ce=_0x8da3ce||0x1;this[_0x1899('0x31')](_0x425f64);this['setExtension'](_0x7b1ea7);this[_0x1899('0x35')](_0x8da3ce);return this[_0x1899('0x3e')](util[_0x1899('0x2e')](_0x1899('0x3f'),_0x425f64,_0x7b1ea7,_0x8da3ce));};AGIChannel[_0x1899('0x24')][_0x1899('0x40')]=function(_0x3ef404){return this[_0x1899('0x25')](util[_0x1899('0x2e')](_0x1899('0x41'),_0x3ef404));};AGIChannel[_0x1899('0x24')][_0x1899('0x42')]=function(_0x5eeed2,_0x4db4f4,_0x201d6d,_0x3d8ff9,_0x2e1121,_0x5e3e61){_0x4db4f4=_0x4db4f4||_0x1899('0x43');_0x201d6d=_0x201d6d||'';_0x3d8ff9=_0x3d8ff9===undefined?-0x1:_0x3d8ff9==='-1'?-0x1:_0x3d8ff9*0x3e8;_0x2e1121=_0x2e1121===undefined?'':'s='+_0x2e1121;_0x5e3e61=_0x5e3e61?_0x1899('0x44'):'';return this[_0x1899('0x25')](util[_0x1899('0x2e')](_0x1899('0x45'),_0x5eeed2,_0x4db4f4,_0x201d6d,_0x3d8ff9,_0x5e3e61,_0x2e1121));};AGIChannel['prototype'][_0x1899('0x46')]=function(_0x209eb0,_0x482ac6){_0x482ac6=_0x482ac6||'';return this[_0x1899('0x25')](util[_0x1899('0x2e')](_0x1899('0x47'),_0x209eb0,_0x482ac6));};AGIChannel[_0x1899('0x24')][_0x1899('0x48')]=function(_0x1121fe){return this['exec'](_0x1899('0x49'),_0x1121fe);};AGIChannel[_0x1899('0x24')][_0x1899('0x4a')]=function(_0x5cfc50){return this[_0x1899('0x2d')](_0x1899('0x4b'),_0x5cfc50);};AGIChannel[_0x1899('0x24')][_0x1899('0x19')]=function(_0x55324c,_0xa733fb){this[_0x1899('0x3e')](util[_0x1899('0x2e')]('ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s',_0x55324c['id'],_0x55324c[_0x1899('0x4c')],_0xa733fb));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x1899('0x4d')]=AGIChannel;