f4a590a10af49059af5f2abc71bc92d9c723d8ba
[motion.git] / server / config / ami / db / fax.js
1 var _0x787e=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x62\x6C\x75\x65\x62\x69\x72\x64","\x6D\x6F\x6D\x65\x6E\x74","\x75\x74\x69\x6C","\x6C\x6F\x64\x61\x73\x68","\x70\x61\x74\x68","\x2E\x2E\x2F\x2E\x2E\x2F\x65\x6E\x76\x69\x72\x6F\x6E\x6D\x65\x6E\x74","\x65\x78\x65\x63","\x63\x68\x69\x6C\x64\x2D\x70\x72\x6F\x63\x65\x73\x73\x2D\x70\x72\x6F\x6D\x69\x73\x65","\x46\x61\x78\x4D\x65\x73\x73\x61\x67\x65","\x2E\x2E\x2F\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x46\x61\x78\x52\x6F\x6F\x6D","\x46\x61\x78\x41\x63\x63\x6F\x75\x6E\x74","\x46\x61\x78\x41\x74\x74\x61\x63\x68\x6D\x65\x6E\x74","\x43\x6F\x6E\x74\x61\x63\x74","\x65\x78\x70\x6F\x72\x74\x73","\x5B\x46\x61\x78\x5D\x20\x4E\x65\x77\x20\x6D\x65\x73\x73\x61\x67\x65\x20\x66\x72\x6F\x6D\x20\x25\x73","\x63\x61\x6C\x6C\x65\x72\x69\x64\x6E\x75\x6D","\x66\x6F\x72\x6D\x61\x74","\x6C\x6F\x67","\x63\x6C\x6F\x6E\x65","\x5B\x46\x61\x78\x5D\x20\x45\x72\x72\x6F\x72\x20\x72\x65\x63\x65\x69\x76\x69\x6E\x67\x20\x6D\x65\x73\x73\x61\x67\x65\x3A","\x65\x72\x72\x6F\x72","\x5B\x46\x61\x78\x5D\x20\x4D\x65\x73\x73\x61\x67\x65\x3A","\x6D\x65\x73\x73\x61\x67\x65","\x5B\x46\x61\x78\x5D\x20\x53\x74\x61\x63\x6B\x3A","\x73\x74\x61\x63\x6B","\x63\x61\x74\x63\x68","\x70\x61\x67\x65\x73\x74\x72\x61\x6E\x73\x66\x65\x72\x72\x65\x64","\x5B\x46\x61\x78\x5D\x20\x46\x69\x6C\x65\x20\x63\x6F\x72\x72\x65\x63\x74\x6C\x79\x20\x63\x6F\x6E\x76\x65\x72\x74\x65\x64","\x69\x6E\x69\x74\x46\x61\x78\x52\x6F\x75\x74\x69\x6E\x67","\x73\x65\x6E\x64","\x74\x68\x65\x6E","\x5B\x46\x61\x78\x5D\x20\x41\x74\x74\x61\x63\x68\x6D\x65\x6E\x74\x20\x6E\x6F\x74\x20\x63\x72\x65\x61\x74\x65\x64","\x5B\x46\x61\x78\x5D\x20\x41\x74\x74\x61\x63\x68\x6D\x65\x6E\x74\x3A","\x69\x64","\x74\x69\x66\x66\x32\x70\x64\x66\x20\x2D\x6F\x20","\x20","\x66\x69\x6C\x65\x6E\x61\x6D\x65","\x5B\x46\x61\x78\x5D\x20\x4D\x65\x73\x73\x61\x67\x65\x20\x6E\x6F\x74\x20\x63\x72\x65\x61\x74\x65\x64","\x6E\x61\x6D\x65","\x70\x61\x72\x73\x65","\x2E\x70\x64\x66","\x72\x6F\x6F\x74","\x73\x65\x72\x76\x65\x72","\x66\x69\x6C\x65\x73","\x66\x61\x78","\x69\x6E\x62\x6F\x75\x6E\x64","\x63\x6F\x6E\x76\x65\x72\x74\x65\x64","\x6A\x6F\x69\x6E","\x63\x72\x65\x61\x74\x65","\x5B\x46\x61\x78\x5D\x20\x54\x72\x61\x6E\x73\x66\x65\x72\x72\x65\x64\x20\x66\x69\x6C\x65\x20\x69\x73\x20\x65\x6D\x70\x74\x79\x20\x28\x70\x61\x67\x65\x73\x74\x72\x61\x6E\x73\x66\x65\x72\x72\x65\x64\x3A\x25\x73\x29","\x5B\x46\x61\x78\x5D\x20\x52\x6F\x6F\x6D\x20\x6E\x6F\x74\x20\x66\x6F\x75\x6E\x64\x2F\x63\x72\x65\x61\x74\x65\x64","\x5B\x46\x61\x78\x5D\x20\x52\x6F\x6F\x6D\x3A","\x46\x61\x78\x52\x6F\x6F\x6D\x49\x64","\x73\x74\x61\x74\x75\x73","\x52\x45\x43\x45\x49\x56\x45\x44","\x66\x72\x6F\x6D","\x74\x6F","\x6C\x6F\x63\x61\x6C\x73\x74\x61\x74\x69\x6F\x6E\x69\x64","","\x54\x72\x61\x6E\x73\x66\x65\x72\x72\x65\x64\x20\x66\x69\x6C\x65\x20\x69\x73\x20\x65\x6D\x70\x74\x79","\x6C\x65\x6E\x67\x74\x68","\x66\x69\x72\x73\x74","\x59\x59\x59\x59\x2D\x4D\x4D\x2D\x44\x44\x20\x48\x48\x3A\x6D\x6D\x3A\x73\x73","\x4F\x50\x45\x4E","\x73\x79\x73\x74\x65\x6D","\x66\x61\x78\x49\x6E","\x75\x70\x64\x61\x74\x65\x41\x74\x74\x72\x69\x62\x75\x74\x65\x73","\x4E\x45\x57","\x43\x4C\x4F\x53\x45\x44","\x63\x72\x65\x61\x74\x65\x64\x41\x74","\x44\x45\x53\x43","\x66\x69\x6E\x64\x41\x6C\x6C","\x73\x70\x72\x65\x61\x64","\x5B\x46\x61\x78\x5D\x20\x41\x63\x63\x6F\x75\x6E\x74\x20\x6E\x6F\x74\x20\x66\x6F\x75\x6E\x64","\x5B\x46\x61\x78\x5D\x20\x41\x63\x63\x6F\x75\x6E\x74\x20\x66\x6F\x75\x6E\x64\x3A","\x4C\x69\x73\x74\x49\x64","\x66\x69\x6E\x64\x4F\x72\x43\x72\x65\x61\x74\x65","\x66\x69\x6E\x64\x4F\x6E\x65","\x5B\x46\x61\x78\x5D\x20\x45\x72\x72\x6F\x72\x20\x75\x70\x64\x61\x74\x69\x6E\x67\x20\x73\x65\x6E\x64\x69\x6E\x67\x20\x6D\x65\x73\x73\x61\x67\x65\x3A","\x5B\x46\x61\x78\x5D\x20\x52\x6F\x6F\x6D\x20\x75\x70\x64\x61\x74\x65\x20\x66\x6F\x72\x20\x53\x65\x6E\x64\x46\x61\x78\x20\x65\x76\x65\x6E\x74","\x5B\x46\x61\x78\x5D\x20\x52\x6F\x6F\x6D\x20\x6E\x6F\x74\x20\x66\x6F\x75\x6E\x64","\x53\x45\x4E\x54","\x5B\x46\x61\x78\x5D\x20\x4D\x65\x73\x73\x61\x67\x65\x20\x75\x70\x64\x61\x74\x65\x20\x66\x6F\x72\x20\x53\x65\x6E\x64\x46\x61\x78\x20\x65\x76\x65\x6E\x74","\x67\x65\x74\x46\x61\x78\x52\x6F\x6F\x6D","\x5B\x46\x61\x78\x5D\x20\x4D\x65\x73\x73\x61\x67\x65\x20\x6E\x6F\x74\x20\x66\x6F\x75\x6E\x64","\x30","\x46\x41\x49\x4C\x45\x44","\x72\x65\x6D\x6F\x74\x65\x73\x74\x61\x74\x69\x6F\x6E\x69\x64","\x72\x65\x73\x6F\x6C\x75\x74\x69\x6F\x6E","\x74\x72\x61\x6E\x73\x66\x65\x72\x72\x61\x74\x65","\x76\x61\x72\x69\x61\x62\x6C\x65","\x72\x65\x73\x6F\x6C\x76\x65","\x5B\x46\x61\x78\x5D\x20\x45\x72\x72\x6F\x72\x20\x75\x70\x64\x61\x74\x69\x6E\x67\x20\x6D\x65\x73\x73\x61\x67\x65\x3A","\x63\x68\x61\x6E\x6E\x65\x6C","\x63\x68\x61\x6E\x6E\x65\x6C\x73\x74\x61\x74\x65","\x63\x68\x61\x6E\x6E\x65\x6C\x73\x74\x61\x74\x65\x64\x65\x73\x63","\x63\x61\x6C\x6C\x65\x72\x69\x64\x6E\x61\x6D\x65","\x63\x6F\x6E\x6E\x65\x63\x74\x65\x64\x6C\x69\x6E\x65\x6E\x75\x6D","\x63\x6F\x6E\x6E\x65\x63\x74\x65\x64\x6C\x69\x6E\x65\x6E\x61\x6D\x65","\x61\x63\x63\x6F\x75\x6E\x74\x63\x6F\x64\x65","\x63\x6F\x6E\x74\x65\x78\x74","\x65\x78\x74\x65\x6E","\x70\x72\x69\x6F\x72\x69\x74\x79","\x75\x6E\x69\x71\x75\x65\x69\x64","\x6C\x69\x6E\x6B\x65\x64\x69\x64","\x66\x61\x78\x65\x72\x72\x6F\x72","\x68\x61\x73\x4F\x77\x6E\x50\x72\x6F\x70\x65\x72\x74\x79","\x76\x61\x6C\x75\x65","\x5B\x46\x61\x78\x5D\x20\x45\x72\x72\x6F\x72\x20\x75\x70\x64\x61\x74\x69\x6E\x67\x20\x65\x72\x72\x6F\x72\x3A"];_0x787e[0];var BPromise=require(_0x787e[1]);var moment=require(_0x787e[2]);var util=require(_0x787e[3]);var _=require(_0x787e[4]);var path=require(_0x787e[5]);var config=require(_0x787e[6]);var exec=require(_0x787e[8])[_0x787e[7]];var FaxMessage=require(_0x787e[10])[_0x787e[9]];var FaxRoom=require(_0x787e[10])[_0x787e[11]];var FaxAccount=require(_0x787e[10])[_0x787e[12]];var FaxAttachment=require(_0x787e[10])[_0x787e[13]];var Contact=require(_0x787e[10])[_0x787e[14]];module[_0x787e[15]]= function(){return {receivefax:function(_0xe98dxd){return function(_0xe98dxe){console[_0x787e[19]](util[_0x787e[18]](_0x787e[16],_0xe98dxd[_0x787e[17]]));var _0xe98dxf=_[_0x787e[20]](_0xe98dxd);var _0xe98dx10;var _0xe98dx11,_0xe98dx12;return FaxAccount[_0x787e[79]]({where:{localstationid:_0xe98dxd[_0x787e[59]]}})[_0x787e[32]](function(_0xe98dx1b){if(!_0xe98dx1b){throw  new Error(_0x787e[75])};console[_0x787e[19]](_0x787e[76],_0xe98dxd[_0x787e[59]]);_0xe98dx10= _0xe98dx1b;if(_0xe98dx10[_0x787e[77]]){return Contact[_0x787e[78]]({where:{ListId:_0xe98dx10[_0x787e[77]],$or:[{phone:_0xe98dxd[_0x787e[17]]},{fax:_0xe98dxd[_0x787e[17]]}]},defaults:{phone:_0xe98dxd[_0x787e[17]],fax:_0xe98dxd[_0x787e[17]],firstName:_0xe98dxd[_0x787e[17]],ListId:_0xe98dx10[_0x787e[77]]}})}else {return []}})[_0x787e[74]](function(_0xe98dx19,_0xe98dx1a){if(_0xe98dx1a!== undefined&&  !_0xe98dx1a){return _0xe98dx19[_0x787e[68]]({fax:_0xe98dxd[_0x787e[17]]})};return})[_0x787e[32]](function(){return FaxRoom[_0x787e[73]]({limit:1,where:{contact:_0xe98dxf[_0x787e[17]],FaxAccountId:_0xe98dx10[_0x787e[35]],status:{$ne:_0x787e[70]}},order:[[_0x787e[71],_0x787e[72]]]})})[_0x787e[32]](function(_0xe98dx18){if(_0xe98dx18[_0x787e[62]]){_0xe98dx18= _[_0x787e[63]](_0xe98dx18);return _0xe98dx18[_0x787e[68]]({lastEvent:_0x787e[56],lastEventAt:moment()[_0x787e[18]](_0x787e[64]),status:_0x787e[65],openReason:_0x787e[66],faxIn:++_0xe98dx18[_0x787e[67]]})}else {return FaxRoom[_0x787e[50]]({contact:_0xe98dxf[_0x787e[17]],account:_0xe98dx10[_0x787e[40]],status:_0x787e[69],lastEvent:_0x787e[56],lastEventAt:moment()[_0x787e[18]](_0x787e[64]),FaxAccountId:_0xe98dx10[_0x787e[35]],faxIn:1})}})[_0x787e[32]](function(_0xe98dx18){if(!_0xe98dx18){throw  new Error(_0x787e[52])};console[_0x787e[19]](_0x787e[53],_0xe98dx18[_0x787e[35]]);_0xe98dx12= _0xe98dx18;_0xe98dxf[_0x787e[54]]= _0xe98dx18[_0x787e[35]];_0xe98dxf[_0x787e[55]]= _0x787e[56];_0xe98dxf[_0x787e[57]]= _0xe98dxf[_0x787e[17]];_0xe98dxf[_0x787e[58]]= _0xe98dxf[_0x787e[59]];_0xe98dxf[_0x787e[22]]= parseInt(_0xe98dxf[_0x787e[28]])> 0?_0x787e[60]:_0x787e[61];return FaxMessage[_0x787e[50]](_0xe98dxf)})[_0x787e[32]](function(_0xe98dx15){if(!_0xe98dx15){throw  new Error(_0x787e[39])};_0xe98dx11= _0xe98dx15;console[_0x787e[19]](_0x787e[23],_0xe98dx15[_0x787e[35]]);if(parseInt(_0xe98dxd[_0x787e[28]])> 0){var _0xe98dx16=path[_0x787e[41]](_0xe98dxd[_0x787e[38]])[_0x787e[40]];var _0xe98dx17=_0xe98dx16+ _0x787e[42];return FaxAttachment[_0x787e[50]]({path:path[_0x787e[49]](config[_0x787e[43]],_0x787e[44],_0x787e[45],_0x787e[46],_0x787e[47],_0x787e[48],_0xe98dx17),basename:_0xe98dx17,name:_0xe98dx16,FaxMessageId:_0xe98dx15[_0x787e[35]]})};console[_0x787e[19]](util[_0x787e[18]](_0x787e[51],_0xe98dxd[_0x787e[28]]));return})[_0x787e[32]](function(_0xe98dx14){if(!_0xe98dx14){console[_0x787e[19]](_0x787e[33]);return};console[_0x787e[19]](_0x787e[34],_0xe98dx14[_0x787e[35]]);return exec(_0x787e[36]+ _0xe98dx14[_0x787e[5]]+ _0x787e[37]+ _0xe98dxd[_0x787e[38]])})[_0x787e[32]](function(){if(parseInt(_0xe98dxd[_0x787e[28]])> 0){console[_0x787e[19]](_0x787e[29]);process[_0x787e[31]]({message:_0x787e[30],doc:{message:_0xe98dx11,account:_0xe98dx10}})}})[_0x787e[27]](function(_0xe98dx13){console[_0x787e[22]](_0x787e[21],_0xe98dx13);console[_0x787e[22]](_0x787e[23],_0xe98dx13[_0x787e[24]]);console[_0x787e[22]](_0x787e[25],_0xe98dx13[_0x787e[26]])})}},sendfax:function(_0xe98dxd){return function(_0xe98dxe){var _0xe98dx11;return FaxMessage[_0x787e[79]]({where:{filename:_0xe98dxd[_0x787e[38]],localstationid:_0xe98dxd[_0x787e[59]]}})[_0x787e[32]](function(_0xe98dx1d){if(!_0xe98dx1d){throw  new Error(_0x787e[86])};_0xe98dx11= _0xe98dx1d;var _0xe98dx1e=_0x787e[83];if(_0xe98dxd[_0x787e[28]]=== _0x787e[87]){_0xe98dx1e= _0x787e[88]};return _0xe98dx11[_0x787e[68]]({remotestationid:_0xe98dxd[_0x787e[89]],pagestransferred:_0xe98dxd[_0x787e[28]],resolution:_0xe98dxd[_0x787e[90]],transferrate:_0xe98dxd[_0x787e[91]],status:_0xe98dx1e})})[_0x787e[32]](function(_0xe98dx15){console[_0x787e[19]](_0x787e[84],_0xe98dx15[_0x787e[35]]);return _0xe98dx11[_0x787e[85]]()})[_0x787e[32]](function(_0xe98dx1c){if(!_0xe98dx1c){throw  new Error(_0x787e[82])};return _0xe98dx1c[_0x787e[68]]({lastEvent:_0x787e[83]},{individualHooks:true})})[_0x787e[32]](function(_0xe98dx18){console[_0x787e[19]](_0x787e[81],_0xe98dx18[_0x787e[35]])})[_0x787e[27]](function(_0xe98dx13){console[_0x787e[22]](_0x787e[80],_0xe98dx13);console[_0x787e[22]](_0x787e[23],_0xe98dx13[_0x787e[24]]);console[_0x787e[22]](_0x787e[25],_0xe98dx13[_0x787e[26]])})}},faxstatus:function(_0xe98dxd){return function(_0xe98dxe){if(_0xe98dxd[_0x787e[92]]!== _0x787e[31]){return BPromise[_0x787e[93]]()};return FaxMessage[_0x787e[79]]({where:{filename:_0xe98dxd[_0x787e[38]],localstationid:_0xe98dxd[_0x787e[59]]}})[_0x787e[32]](function(_0xe98dx1d){if(!_0xe98dx1d){throw  new Error(_0x787e[86])};return _0xe98dx1d[_0x787e[68]]({channel:_0xe98dxd[_0x787e[95]],channelstate:_0xe98dxd[_0x787e[96]],channelstatedesc:_0xe98dxd[_0x787e[97]],calleridnum:_0xe98dxd[_0x787e[17]],calleridname:_0xe98dxd[_0x787e[98]],connectedlinenum:_0xe98dxd[_0x787e[99]],connectedlinename:_0xe98dxd[_0x787e[100]],accountcode:_0xe98dxd[_0x787e[101]],context:_0xe98dxd[_0x787e[102]],exten:_0xe98dxd[_0x787e[103]],priority:_0xe98dxd[_0x787e[104]],uniqueid:_0xe98dxd[_0x787e[105]],linkedid:_0xe98dxd[_0x787e[106]],lastStatus:_0xe98dxd[_0x787e[55]]})})[_0x787e[27]](function(_0xe98dx13){console[_0x787e[22]](_0x787e[94],_0xe98dx13);console[_0x787e[22]](_0x787e[23],_0xe98dx13[_0x787e[24]]);console[_0x787e[22]](_0x787e[25],_0xe98dx13[_0x787e[26]])})}},faxerror:function(_0xe98dxd){return function(_0xe98dxe){if(!_0xe98dxd[_0x787e[92]][_0x787e[108]](_0x787e[107])||  !_0xe98dxd[_0x787e[109]]){return BPromise[_0x787e[93]]()};return FaxMessage[_0x787e[79]]({where:{channel:_0xe98dxd[_0x787e[95]]}})[_0x787e[32]](function(_0xe98dx1d){if(_0xe98dx1d){return _0xe98dx1d[_0x787e[68]]({error:_0xe98dxd[_0x787e[109]]})};return})[_0x787e[27]](function(_0xe98dx13){console[_0x787e[22]](_0x787e[110],_0xe98dx13)})}}}}