Built motion from commit f1f5024.|1.0.16
[motion.git] / server / config / ami / db / fax.js
1 var _0x59f5=["\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"];_0x59f5[0];var BPromise=require(_0x59f5[1]);var moment=require(_0x59f5[2]);var util=require(_0x59f5[3]);var _=require(_0x59f5[4]);var path=require(_0x59f5[5]);var config=require(_0x59f5[6]);var exec=require(_0x59f5[8])[_0x59f5[7]];var FaxMessage=require(_0x59f5[10])[_0x59f5[9]];var FaxRoom=require(_0x59f5[10])[_0x59f5[11]];var FaxAccount=require(_0x59f5[10])[_0x59f5[12]];var FaxAttachment=require(_0x59f5[10])[_0x59f5[13]];var Contact=require(_0x59f5[10])[_0x59f5[14]];module[_0x59f5[15]]= function(){return {receivefax:function(_0x6765xd){return function(_0x6765xe){console[_0x59f5[19]](util[_0x59f5[18]](_0x59f5[16],_0x6765xd[_0x59f5[17]]));var _0x6765xf=_[_0x59f5[20]](_0x6765xd);var _0x6765x10;var _0x6765x11,_0x6765x12;return FaxAccount[_0x59f5[79]]({where:{localstationid:_0x6765xd[_0x59f5[59]]}})[_0x59f5[32]](function(_0x6765x1b){if(!_0x6765x1b){throw  new Error(_0x59f5[75])};console[_0x59f5[19]](_0x59f5[76],_0x6765xd[_0x59f5[59]]);_0x6765x10= _0x6765x1b;if(_0x6765x10[_0x59f5[77]]){return Contact[_0x59f5[78]]({where:{ListId:_0x6765x10[_0x59f5[77]],$or:[{phone:_0x6765xd[_0x59f5[17]]},{fax:_0x6765xd[_0x59f5[17]]}]},defaults:{phone:_0x6765xd[_0x59f5[17]],fax:_0x6765xd[_0x59f5[17]],firstName:_0x6765xd[_0x59f5[17]],ListId:_0x6765x10[_0x59f5[77]]}})}else {return []}})[_0x59f5[74]](function(_0x6765x19,_0x6765x1a){if(_0x6765x1a!== undefined&&  !_0x6765x1a){return _0x6765x19[_0x59f5[68]]({fax:_0x6765xd[_0x59f5[17]]})};return})[_0x59f5[32]](function(){return FaxRoom[_0x59f5[73]]({limit:1,where:{contact:_0x6765xf[_0x59f5[17]],FaxAccountId:_0x6765x10[_0x59f5[35]],status:{$ne:_0x59f5[70]}},order:[[_0x59f5[71],_0x59f5[72]]]})})[_0x59f5[32]](function(_0x6765x18){if(_0x6765x18[_0x59f5[62]]){_0x6765x18= _[_0x59f5[63]](_0x6765x18);return _0x6765x18[_0x59f5[68]]({lastEvent:_0x59f5[56],lastEventAt:moment()[_0x59f5[18]](_0x59f5[64]),status:_0x59f5[65],openReason:_0x59f5[66],faxIn:++_0x6765x18[_0x59f5[67]]})}else {return FaxRoom[_0x59f5[50]]({contact:_0x6765xf[_0x59f5[17]],account:_0x6765x10[_0x59f5[40]],status:_0x59f5[69],lastEvent:_0x59f5[56],lastEventAt:moment()[_0x59f5[18]](_0x59f5[64]),FaxAccountId:_0x6765x10[_0x59f5[35]],faxIn:1})}})[_0x59f5[32]](function(_0x6765x18){if(!_0x6765x18){throw  new Error(_0x59f5[52])};console[_0x59f5[19]](_0x59f5[53],_0x6765x18[_0x59f5[35]]);_0x6765x12= _0x6765x18;_0x6765xf[_0x59f5[54]]= _0x6765x18[_0x59f5[35]];_0x6765xf[_0x59f5[55]]= _0x59f5[56];_0x6765xf[_0x59f5[57]]= _0x6765xf[_0x59f5[17]];_0x6765xf[_0x59f5[58]]= _0x6765xf[_0x59f5[59]];_0x6765xf[_0x59f5[22]]= parseInt(_0x6765xf[_0x59f5[28]])> 0?_0x59f5[60]:_0x59f5[61];return FaxMessage[_0x59f5[50]](_0x6765xf)})[_0x59f5[32]](function(_0x6765x15){if(!_0x6765x15){throw  new Error(_0x59f5[39])};_0x6765x11= _0x6765x15;console[_0x59f5[19]](_0x59f5[23],_0x6765x15[_0x59f5[35]]);if(parseInt(_0x6765xd[_0x59f5[28]])> 0){var _0x6765x16=path[_0x59f5[41]](_0x6765xd[_0x59f5[38]])[_0x59f5[40]];var _0x6765x17=_0x6765x16+ _0x59f5[42];return FaxAttachment[_0x59f5[50]]({path:path[_0x59f5[49]](config[_0x59f5[43]],_0x59f5[44],_0x59f5[45],_0x59f5[46],_0x59f5[47],_0x59f5[48],_0x6765x17),basename:_0x6765x17,name:_0x6765x16,FaxMessageId:_0x6765x15[_0x59f5[35]]})};console[_0x59f5[19]](util[_0x59f5[18]](_0x59f5[51],_0x6765xd[_0x59f5[28]]));return})[_0x59f5[32]](function(_0x6765x14){if(!_0x6765x14){console[_0x59f5[19]](_0x59f5[33]);return};console[_0x59f5[19]](_0x59f5[34],_0x6765x14[_0x59f5[35]]);return exec(_0x59f5[36]+ _0x6765x14[_0x59f5[5]]+ _0x59f5[37]+ _0x6765xd[_0x59f5[38]])})[_0x59f5[32]](function(){if(parseInt(_0x6765xd[_0x59f5[28]])> 0){console[_0x59f5[19]](_0x59f5[29]);process[_0x59f5[31]]({message:_0x59f5[30],doc:{message:_0x6765x11,account:_0x6765x10}})}})[_0x59f5[27]](function(_0x6765x13){console[_0x59f5[22]](_0x59f5[21],_0x6765x13);console[_0x59f5[22]](_0x59f5[23],_0x6765x13[_0x59f5[24]]);console[_0x59f5[22]](_0x59f5[25],_0x6765x13[_0x59f5[26]])})}},sendfax:function(_0x6765xd){return function(_0x6765xe){var _0x6765x11;return FaxMessage[_0x59f5[79]]({where:{filename:_0x6765xd[_0x59f5[38]],localstationid:_0x6765xd[_0x59f5[59]]}})[_0x59f5[32]](function(_0x6765x1d){if(!_0x6765x1d){throw  new Error(_0x59f5[86])};_0x6765x11= _0x6765x1d;var _0x6765x1e=_0x59f5[83];if(_0x6765xd[_0x59f5[28]]=== _0x59f5[87]){_0x6765x1e= _0x59f5[88]};return _0x6765x11[_0x59f5[68]]({remotestationid:_0x6765xd[_0x59f5[89]],pagestransferred:_0x6765xd[_0x59f5[28]],resolution:_0x6765xd[_0x59f5[90]],transferrate:_0x6765xd[_0x59f5[91]],status:_0x6765x1e})})[_0x59f5[32]](function(_0x6765x15){console[_0x59f5[19]](_0x59f5[84],_0x6765x15[_0x59f5[35]]);return _0x6765x11[_0x59f5[85]]()})[_0x59f5[32]](function(_0x6765x1c){if(!_0x6765x1c){throw  new Error(_0x59f5[82])};return _0x6765x1c[_0x59f5[68]]({lastEvent:_0x59f5[83]},{individualHooks:true})})[_0x59f5[32]](function(_0x6765x18){console[_0x59f5[19]](_0x59f5[81],_0x6765x18[_0x59f5[35]])})[_0x59f5[27]](function(_0x6765x13){console[_0x59f5[22]](_0x59f5[80],_0x6765x13);console[_0x59f5[22]](_0x59f5[23],_0x6765x13[_0x59f5[24]]);console[_0x59f5[22]](_0x59f5[25],_0x6765x13[_0x59f5[26]])})}},faxstatus:function(_0x6765xd){return function(_0x6765xe){if(_0x6765xd[_0x59f5[92]]!== _0x59f5[31]){return BPromise[_0x59f5[93]]()};return FaxMessage[_0x59f5[79]]({where:{filename:_0x6765xd[_0x59f5[38]],localstationid:_0x6765xd[_0x59f5[59]]}})[_0x59f5[32]](function(_0x6765x1d){if(!_0x6765x1d){throw  new Error(_0x59f5[86])};return _0x6765x1d[_0x59f5[68]]({channel:_0x6765xd[_0x59f5[95]],channelstate:_0x6765xd[_0x59f5[96]],channelstatedesc:_0x6765xd[_0x59f5[97]],calleridnum:_0x6765xd[_0x59f5[17]],calleridname:_0x6765xd[_0x59f5[98]],connectedlinenum:_0x6765xd[_0x59f5[99]],connectedlinename:_0x6765xd[_0x59f5[100]],accountcode:_0x6765xd[_0x59f5[101]],context:_0x6765xd[_0x59f5[102]],exten:_0x6765xd[_0x59f5[103]],priority:_0x6765xd[_0x59f5[104]],uniqueid:_0x6765xd[_0x59f5[105]],linkedid:_0x6765xd[_0x59f5[106]],lastStatus:_0x6765xd[_0x59f5[55]]})})[_0x59f5[27]](function(_0x6765x13){console[_0x59f5[22]](_0x59f5[94],_0x6765x13);console[_0x59f5[22]](_0x59f5[23],_0x6765x13[_0x59f5[24]]);console[_0x59f5[22]](_0x59f5[25],_0x6765x13[_0x59f5[26]])})}},faxerror:function(_0x6765xd){return function(_0x6765xe){if(!_0x6765xd[_0x59f5[92]][_0x59f5[108]](_0x59f5[107])||  !_0x6765xd[_0x59f5[109]]){return BPromise[_0x59f5[93]]()};return FaxMessage[_0x59f5[79]]({where:{channel:_0x6765xd[_0x59f5[95]]}})[_0x59f5[32]](function(_0x6765x1d){if(_0x6765x1d){return _0x6765x1d[_0x59f5[68]]({error:_0x6765xd[_0x59f5[109]]})};return})[_0x59f5[27]](function(_0x6765x13){console[_0x59f5[22]](_0x59f5[110],_0x6765x13)})}}}}