950ecae4162b1142f2f9169a57d4413df69381a6
[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 _0xf114=['AGI','WAIT','noop','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','util','lodash','events','EventEmitter','./reply','./error','call','setEncoding','utf8','setTimeout','headers','emit','ready','line','hangup','substring','520-Invalid','function','no\x20code','replace','indexOf','substr','startsWith','length','match','error','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','write','inherits','prototype','sendRequest','command','answer','ANSWER','getData','beep','NO\x20MESSAGE','format','VERBOSE\x20\x22%s\x22','exec','isArray','EXEC\x20%s\x20%s','join','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','SET\x20PRIORITY\x20%s','HANGUP','setVariable','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','setContext','setPriority','GOTO\x20%s\x20%s\x20%s','getVariable','recordFile','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','streamFile','agi'];(function(_0x4cb272,_0x52c0e9){var _0x57b4aa=function(_0x1efefb){while(--_0x1efefb){_0x4cb272['push'](_0x4cb272['shift']());}};_0x57b4aa(++_0x52c0e9);}(_0xf114,0xe9));var _0x4f11=function(_0x433acc,_0x172c9d){_0x433acc=_0x433acc-0x0;var _0x1841dc=_0xf114[_0x433acc];return _0x1841dc;};'use strict';var util=require(_0x4f11('0x0'));var _=require(_0x4f11('0x1'));var EventEmitter=require(_0x4f11('0x2'))[_0x4f11('0x3')];var AGIReply=require(_0x4f11('0x4'));var AGIError=require(_0x4f11('0x5'));function AGIChannel(_0x2f69d5){var _0x42923c=this,_0x33ab6a=new AGIReply(),_0x4f0f4e=![],_0xb75cc9={};EventEmitter[_0x4f11('0x6')](_0x42923c);_0x2f69d5[_0x4f11('0x7')](_0x4f11('0x8'));_0x2f69d5[_0x4f11('0x9')](0x8*0x3c*0x3c*0x3e8);_0x33ab6a[_0x4f11('0x7')](_0x4f11('0x8'));_0x33ab6a['on'](_0x4f11('0xa'),function(_0x16377b){for(var _0x2185a6 in _0x16377b){_0x42923c[_0x2185a6]=_0x16377b[_0x2185a6];}_0x42923c[_0x4f11('0xb')](_0x4f11('0xc'));});_0x33ab6a['on'](_0x4f11('0xd'),function(_0x4eb562){if(_0x4eb562['toLowerCase']()==_0x4f11('0xe')){_0x42923c[_0x4f11('0xb')]('hangup');return;}if(_0x4eb562[_0x4f11('0xf')](0x0,0xb)==_0x4f11('0x10')){_0x4f0f4e=!![];}if(_0x4f0f4e){_0xb75cc9['rx']+=_0x4eb562+'\x0a';if(_0x4eb562['search']('520\x20End\x20of\x20proper')!=-0x1){_0x4f0f4e=![];}}else{_0xb75cc9['rx']=_0x4eb562;}if(_0x4f0f4e){return;}if(typeof _0xb75cc9['cb']==_0x4f11('0x11')){var _0x529140=_0xb75cc9['rx'][_0x4f11('0xf')](0x0,0x3),_0x4c1fb2=null,_0x27db57=null;_0x529140=parseInt(_0x529140);if(isNaN(_0x529140)){_0xb75cc9['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x4f11('0x12')});return;}if(_0x529140!=0xc8){_0xb75cc9['cb'](null,{'code':_0x529140,'result':-0x1,'extra':'KO'});return;}_0x4c1fb2=_0xb75cc9['rx']['substring'](0x4)[_0x4f11('0x13')]('result=','');if(_0x4c1fb2[_0x4f11('0x14')]('\x20')!=-0x1){_0x4c1fb2=_0x4c1fb2[_0x4f11('0x15')](0x0,_0x4c1fb2[_0x4f11('0x14')]('\x20'));}if(_[_0x4f11('0x16')](_0x4c1fb2,'-1')){_0x4c1fb2=parseInt(_0x4c1fb2);}_0x27db57=_0xb75cc9['rx']['split']('\x20');if(_0x27db57[_0x4f11('0x17')]==0x3){_0x27db57=_0x27db57[0x2][_0x4f11('0xf')](0x1,_0x27db57[0x2][_0x4f11('0x17')]-0x1);}else if(_0x27db57[_0x4f11('0x17')]>0x3){var _0x4d0d6b=/\((.+)\)/;var _0x538d4a=_0xb75cc9['rx'][_0x4f11('0x18')](_0x4d0d6b);if(_0x538d4a){_0x27db57=_0x538d4a[0x1];}else{_0x27db57=null;}}else{_0x27db57=null;}_0xb75cc9['cb'](null,{'code':_0x529140,'result':_0x4c1fb2,'extra':_0x27db57});}});_0x2f69d5['on'](_0x4f11('0x19'),function(_0x18816b){_0x42923c['emit'](_0x4f11('0x19'),new AGIError('E_AGI_SOCKET_ERROR',_0x18816b['code']));});_0x2f69d5['on'](_0x4f11('0x1a'),function(){_0x42923c[_0x4f11('0xb')]('close',new AGIError(_0x4f11('0x1b')));});_0x2f69d5['on'](_0x4f11('0x1c'),function(){_0x42923c[_0x4f11('0xb')](_0x4f11('0x1c'),new AGIError(_0x4f11('0x1d')));_0x2f69d5[_0x4f11('0x1e')]();});_0x2f69d5[_0x4f11('0x1f')](_0x33ab6a);this['command']=function(_0x38afb,_0x1ef83b){var _0x38afb=_0x38afb||'',_0x1ef83b=typeof _0x1ef83b==_0x4f11('0x11')?_0x1ef83b:new Function();_0xb75cc9={'tx':_0x38afb,'rx':'','cb':_0x1ef83b};_0x2f69d5[_0x4f11('0x20')](_0x38afb+'\x0a');},this[_0x4f11('0x1a')]=function(){_0x2f69d5['destroy']();};}util[_0x4f11('0x21')](AGIChannel,EventEmitter);AGIChannel[_0x4f11('0x22')][_0x4f11('0x23')]=function(_0x2fb7d6){return this[_0x4f11('0x24')]['sync'](this,_0x2fb7d6);};AGIChannel[_0x4f11('0x22')][_0x4f11('0x25')]=function(){return this['sendRequest'](_0x4f11('0x26'));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x27')]=function(_0x2f2dfc,_0x679549,_0x226ecb){_0x2f2dfc=_0x2f2dfc===undefined?_0x4f11('0x28'):_0x2f2dfc;_0x679549=_0x679549===undefined?'5':_0x679549;_0x226ecb=_0x226ecb===undefined?'1':_0x226ecb;return this[_0x4f11('0x23')](util['format']('GET\x20DATA\x20\x22%s\x22\x20%s\x20%s',_0x2f2dfc,_0x679549*0x3e8,_0x226ecb));};AGIChannel['prototype']['noop']=function(_0x493451){_0x493451=_0x493451||_0x4f11('0x29');return this[_0x4f11('0x23')](util[_0x4f11('0x2a')](_0x4f11('0x2b'),_0x493451));};AGIChannel['prototype'][_0x4f11('0x2c')]=function(_0xa4174a,_0x248d51){if(_[_0x4f11('0x2d')](_0x248d51)){return this['sendRequest'](util[_0x4f11('0x2a')](_0x4f11('0x2e'),_0xa4174a,_0x248d51[_0x4f11('0x2f')](',')));}return this[_0x4f11('0x23')](util[_0x4f11('0x2a')](_0x4f11('0x2e'),_0xa4174a,_0x248d51));};AGIChannel[_0x4f11('0x22')]['setContext']=function(_0x356557){return this[_0x4f11('0x23')](util[_0x4f11('0x2a')](_0x4f11('0x30'),_0x356557));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x31')]=function(_0x49846a){return this[_0x4f11('0x23')](util['format'](_0x4f11('0x32'),_0x49846a));};AGIChannel[_0x4f11('0x22')]['setPriority']=function(_0x2d0d98){return this[_0x4f11('0x23')](util['format'](_0x4f11('0x33'),_0x2d0d98));};AGIChannel['prototype']['hangup']=function(){return this[_0x4f11('0x23')](_0x4f11('0x34'));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x35')]=function(_0x23c5b5,_0x27de87){return this[_0x4f11('0x23')](util[_0x4f11('0x2a')](_0x4f11('0x36'),_0x23c5b5,_0x27de87?_0x27de87[_0x4f11('0x37')]()[_0x4f11('0x13')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x38')]=function(_0x39888,_0xa5e0c9){return this[_0x4f11('0x23')](util[_0x4f11('0x2a')](_0x4f11('0x39'),_0x39888,_0xa5e0c9));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x3a')]=function(_0x224d61,_0x48c204){return this[_0x4f11('0x23')](util['format']('SAY\x20DIGITS\x20%s\x20%s',_0x224d61,_0x48c204));};AGIChannel[_0x4f11('0x22')]['sayPhonetic']=function(_0x58c086,_0x414f84){return this['sendRequest'](util[_0x4f11('0x2a')](_0x4f11('0x3b'),_0x58c086,_0x414f84));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x3c')]=function(_0x8d0dd6,_0x13d4a2,_0x300479){_0x13d4a2=_0x13d4a2||this[_0x4f11('0x3d')];_0x300479=_0x300479||0x1;this[_0x4f11('0x3e')](_0x8d0dd6);this[_0x4f11('0x31')](_0x13d4a2);this[_0x4f11('0x3f')](_0x300479);return this['noop'](util['format'](_0x4f11('0x40'),_0x8d0dd6,_0x13d4a2,_0x300479));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x41')]=function(_0x571f29){return this[_0x4f11('0x23')](util[_0x4f11('0x2a')]('GET\x20VARIABLE\x20\x22%s\x22',_0x571f29));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x42')]=function(_0x542f72,_0x4b3b1b,_0x116ed8,_0x1115eb,_0x13f1e5,_0x3d0a11){_0x4b3b1b=_0x4b3b1b||'wav';_0x116ed8=_0x116ed8||'';_0x1115eb=_0x1115eb===undefined?-0x1:_0x1115eb==='-1'?-0x1:_0x1115eb*0x3e8;_0x13f1e5=_0x13f1e5===undefined?'':'s='+_0x13f1e5;_0x3d0a11=_0x3d0a11?_0x4f11('0x43'):'';return this[_0x4f11('0x23')](util[_0x4f11('0x2a')](_0x4f11('0x44'),_0x542f72,_0x4b3b1b,_0x116ed8,_0x1115eb,_0x3d0a11,_0x13f1e5));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x45')]=function(_0x59fa62,_0x236a53){_0x236a53=_0x236a53||'';return this[_0x4f11('0x23')](util[_0x4f11('0x2a')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x59fa62,_0x236a53));};AGIChannel[_0x4f11('0x22')][_0x4f11('0x46')]=function(_0x218394){return this[_0x4f11('0x2c')](_0x4f11('0x47'),_0x218394);};AGIChannel[_0x4f11('0x22')]['wait']=function(_0xa91ea2){return this[_0x4f11('0x2c')](_0x4f11('0x48'),_0xa91ea2);};AGIChannel['prototype']['error']=function(_0x5b0b8a,_0x10ecc2){this[_0x4f11('0x49')](util['format'](_0x4f11('0x4a'),_0x5b0b8a['id'],_0x5b0b8a[_0x4f11('0x4b')],_0x10ecc2));return{'code':0x1f4,'result':'-1','extra':''};};module['exports']=AGIChannel;