Built motion from commit (unavailable).|2.3.1
[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 _0x91f2=['function','prototype','sync','answer','sendRequest','ANSWER','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','VERBOSE\x20\x22%s\x22','isArray','join','EXEC\x20%s\x20%s','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','HANGUP','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','setContext','GOTO\x20%s\x20%s\x20%s','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','exec','AGI','wait','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','exports','util','lodash','events','./reply','./error','call','setEncoding','utf8','headers','emit','line','toLowerCase','hangup','substring','520-Invalid','search','replace','result=','startsWith','length','match','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','command'];(function(_0x23840e,_0x2fb0cb){var _0x277300=function(_0x246e5a){while(--_0x246e5a){_0x23840e['push'](_0x23840e['shift']());}};_0x277300(++_0x2fb0cb);}(_0x91f2,0x73));var _0x291f=function(_0x31ae70,_0x50ab0f){_0x31ae70=_0x31ae70-0x0;var _0x5760dc=_0x91f2[_0x31ae70];return _0x5760dc;};'use strict';var util=require(_0x291f('0x0'));var _=require(_0x291f('0x1'));var EventEmitter=require(_0x291f('0x2'))['EventEmitter'];var AGIReply=require(_0x291f('0x3'));var AGIError=require(_0x291f('0x4'));function AGIChannel(_0x44ba97){var _0x299b0e=this,_0x47eb15=new AGIReply(),_0x3a06fa=![],_0x27fd6e={};EventEmitter[_0x291f('0x5')](_0x299b0e);_0x44ba97[_0x291f('0x6')](_0x291f('0x7'));_0x44ba97['setTimeout'](0x8*0x3c*0x3c*0x3e8);_0x47eb15[_0x291f('0x6')](_0x291f('0x7'));_0x47eb15['on'](_0x291f('0x8'),function(_0x2211a3){for(var _0x4f9896 in _0x2211a3){_0x299b0e[_0x4f9896]=_0x2211a3[_0x4f9896];}_0x299b0e[_0x291f('0x9')]('ready');});_0x47eb15['on'](_0x291f('0xa'),function(_0x254df2){if(_0x254df2[_0x291f('0xb')]()==_0x291f('0xc')){_0x299b0e[_0x291f('0x9')]('hangup');return;}if(_0x254df2[_0x291f('0xd')](0x0,0xb)==_0x291f('0xe')){_0x3a06fa=!![];}if(_0x3a06fa){_0x27fd6e['rx']+=_0x254df2+'\x0a';if(_0x254df2[_0x291f('0xf')]('520\x20End\x20of\x20proper')!=-0x1){_0x3a06fa=![];}}else{_0x27fd6e['rx']=_0x254df2;}if(_0x3a06fa){return;}if(typeof _0x27fd6e['cb']=='function'){var _0x2f7438=_0x27fd6e['rx'][_0x291f('0xd')](0x0,0x3),_0x166d29=null,_0x2f0564=null;_0x2f7438=parseInt(_0x2f7438);if(isNaN(_0x2f7438)){_0x27fd6e['cb'](null,{'code':0x1f4,'result':-0x1,'extra':'no\x20code'});return;}if(_0x2f7438!=0xc8){_0x27fd6e['cb'](null,{'code':_0x2f7438,'result':-0x1,'extra':'KO'});return;}_0x166d29=_0x27fd6e['rx']['substring'](0x4)[_0x291f('0x10')](_0x291f('0x11'),'');if(_0x166d29['indexOf']('\x20')!=-0x1){_0x166d29=_0x166d29['substr'](0x0,_0x166d29['indexOf']('\x20'));}if(_[_0x291f('0x12')](_0x166d29,'-1')){_0x166d29=parseInt(_0x166d29);}_0x2f0564=_0x27fd6e['rx']['split']('\x20');if(_0x2f0564[_0x291f('0x13')]==0x3){_0x2f0564=_0x2f0564[0x2][_0x291f('0xd')](0x1,_0x2f0564[0x2][_0x291f('0x13')]-0x1);}else if(_0x2f0564[_0x291f('0x13')]>0x3){var _0x2785bf=/\((.+)\)/;var _0x167356=_0x27fd6e['rx'][_0x291f('0x14')](_0x2785bf);if(_0x167356){_0x2f0564=_0x167356[0x1];}else{_0x2f0564=null;}}else{_0x2f0564=null;}_0x27fd6e['cb'](null,{'code':_0x2f7438,'result':_0x166d29,'extra':_0x2f0564});}});_0x44ba97['on']('error',function(_0x51dfcf){_0x299b0e[_0x291f('0x9')](_0x291f('0x15'),new AGIError(_0x291f('0x16'),_0x51dfcf[_0x291f('0x17')]));});_0x44ba97['on']('close',function(){_0x299b0e[_0x291f('0x9')](_0x291f('0x18'),new AGIError(_0x291f('0x19')));});_0x44ba97['on'](_0x291f('0x1a'),function(){_0x299b0e[_0x291f('0x9')](_0x291f('0x1a'),new AGIError(_0x291f('0x1b')));_0x44ba97[_0x291f('0x1c')]();});_0x44ba97[_0x291f('0x1d')](_0x47eb15);this[_0x291f('0x1e')]=function(_0x407c34,_0x4a5fea){var _0x407c34=_0x407c34||'',_0x4a5fea=typeof _0x4a5fea==_0x291f('0x1f')?_0x4a5fea:new Function();_0x27fd6e={'tx':_0x407c34,'rx':'','cb':_0x4a5fea};_0x44ba97['write'](_0x407c34+'\x0a');},this['close']=function(){_0x44ba97[_0x291f('0x1c')]();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel[_0x291f('0x20')]['sendRequest']=function(_0x2d1f41){return this['command'][_0x291f('0x21')](this,_0x2d1f41);};AGIChannel[_0x291f('0x20')][_0x291f('0x22')]=function(){return this[_0x291f('0x23')](_0x291f('0x24'));};AGIChannel['prototype']['getData']=function(_0x26d793,_0x81d6dd,_0x4a9bf3){_0x26d793=_0x26d793===undefined?'beep':_0x26d793;_0x81d6dd=_0x81d6dd===undefined?'5':_0x81d6dd;_0x4a9bf3=_0x4a9bf3===undefined?'1':_0x4a9bf3;return this[_0x291f('0x23')](util[_0x291f('0x25')](_0x291f('0x26'),_0x26d793,_0x81d6dd*0x3e8,_0x4a9bf3));};AGIChannel[_0x291f('0x20')][_0x291f('0x27')]=function(_0x2064df){_0x2064df=_0x2064df||'NO\x20MESSAGE';return this[_0x291f('0x23')](util[_0x291f('0x25')](_0x291f('0x28'),_0x2064df));};AGIChannel['prototype']['exec']=function(_0x539512,_0x42f00e){if(_[_0x291f('0x29')](_0x42f00e)){return this[_0x291f('0x23')](util['format']('EXEC\x20%s\x20%s',_0x539512,_0x42f00e[_0x291f('0x2a')](',')));}return this[_0x291f('0x23')](util[_0x291f('0x25')](_0x291f('0x2b'),_0x539512,_0x42f00e));};AGIChannel[_0x291f('0x20')]['setContext']=function(_0x395345){return this[_0x291f('0x23')](util[_0x291f('0x25')](_0x291f('0x2c'),_0x395345));};AGIChannel['prototype'][_0x291f('0x2d')]=function(_0x2853f3){return this['sendRequest'](util[_0x291f('0x25')](_0x291f('0x2e'),_0x2853f3));};AGIChannel[_0x291f('0x20')][_0x291f('0x2f')]=function(_0x4bf398){return this['sendRequest'](util[_0x291f('0x25')](_0x291f('0x30'),_0x4bf398));};AGIChannel[_0x291f('0x20')][_0x291f('0xc')]=function(){return this['sendRequest'](_0x291f('0x31'));};AGIChannel[_0x291f('0x20')]['setVariable']=function(_0x1b72f7,_0x299255){return this[_0x291f('0x23')](util[_0x291f('0x25')](_0x291f('0x32'),_0x1b72f7,_0x299255?_0x299255[_0x291f('0x33')]()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel['prototype'][_0x291f('0x34')]=function(_0x57ea4d,_0x4d376c){return this[_0x291f('0x23')](util[_0x291f('0x25')](_0x291f('0x35'),_0x57ea4d,_0x4d376c));};AGIChannel[_0x291f('0x20')][_0x291f('0x36')]=function(_0x3a4f87,_0x161333){return this[_0x291f('0x23')](util[_0x291f('0x25')](_0x291f('0x37'),_0x3a4f87,_0x161333));};AGIChannel[_0x291f('0x20')][_0x291f('0x38')]=function(_0x19c5c4,_0x16f9ed){return this[_0x291f('0x23')](util[_0x291f('0x25')](_0x291f('0x39'),_0x19c5c4,_0x16f9ed));};AGIChannel[_0x291f('0x20')][_0x291f('0x3a')]=function(_0x2a50aa,_0x493424,_0x52e97e){_0x493424=_0x493424||this[_0x291f('0x3b')];_0x52e97e=_0x52e97e||0x1;this[_0x291f('0x3c')](_0x2a50aa);this[_0x291f('0x2d')](_0x493424);this[_0x291f('0x2f')](_0x52e97e);return this[_0x291f('0x27')](util[_0x291f('0x25')](_0x291f('0x3d'),_0x2a50aa,_0x493424,_0x52e97e));};AGIChannel[_0x291f('0x20')]['getVariable']=function(_0x52c525){return this['sendRequest'](util[_0x291f('0x25')]('GET\x20VARIABLE\x20\x22%s\x22',_0x52c525));};AGIChannel[_0x291f('0x20')]['recordFile']=function(_0x242ad4,_0x16b711,_0x4d372c,_0x22fc17,_0x1a61ea,_0x4a7b08){_0x16b711=_0x16b711||'wav';_0x4d372c=_0x4d372c||'';_0x22fc17=_0x22fc17===undefined?-0x1:_0x22fc17==='-1'?-0x1:_0x22fc17*0x3e8;_0x1a61ea=_0x1a61ea===undefined?'':'s='+_0x1a61ea;_0x4a7b08=_0x4a7b08?_0x291f('0x3e'):'';return this['sendRequest'](util[_0x291f('0x25')](_0x291f('0x3f'),_0x242ad4,_0x16b711,_0x4d372c,_0x22fc17,_0x4a7b08,_0x1a61ea));};AGIChannel['prototype'][_0x291f('0x40')]=function(_0x1bf8f1,_0xbd0010){_0xbd0010=_0xbd0010||'';return this[_0x291f('0x23')](util[_0x291f('0x25')](_0x291f('0x41'),_0x1bf8f1,_0xbd0010));};AGIChannel[_0x291f('0x20')][_0x291f('0x42')]=function(_0x1c061f){return this[_0x291f('0x43')](_0x291f('0x44'),_0x1c061f);};AGIChannel[_0x291f('0x20')][_0x291f('0x45')]=function(_0x4da85d){return this['exec'](_0x291f('0x46'),_0x4da85d);};AGIChannel[_0x291f('0x20')][_0x291f('0x15')]=function(_0xa91fe0,_0x2f9f01){this[_0x291f('0x27')](util[_0x291f('0x25')](_0x291f('0x47'),_0xa91fe0['id'],_0xa91fe0['label'],_0x2f9f01));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x291f('0x48')]=AGIChannel;