df134fd10e484ba7dde2943829db3bcbc9c1d0a7
[motion.git] / server / config / ami / db / fax.js
1 var _0x111c=["\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","\x66\x61\x78","\x2E\x2E\x2F\x2E\x2E\x2F\x6C\x6F\x67\x67\x65\x72\x2E\x6A\x73","\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","\x69\x6E\x66\x6F","\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","\x64\x65\x62\x75\x67","\x5B\x46\x61\x78\x5D\x20\x4D\x65\x73\x73\x61\x67\x65\x20\x63\x6F\x72\x72\x65\x63\x74\x6C\x79\x20\x72\x65\x63\x65\x69\x76\x65\x64\x2C\x20\x69\x6E\x69\x74\x69\x61\x74\x69\x6E\x67\x20\x72\x6F\x75\x74\x69\x6E\x67\x2E\x2E\x2E","\x69\x6E\x69\x74\x46\x61\x78\x52\x6F\x75\x74\x69\x6E\x67","\x73\x65\x6E\x64","\x67\x65\x74","\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","\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"];_0x111c[0];var BPromise=require(_0x111c[1]);var moment=require(_0x111c[2]);var util=require(_0x111c[3]);var _=require(_0x111c[4]);var path=require(_0x111c[5]);var config=require(_0x111c[6]);var exec=require(_0x111c[8])[_0x111c[7]];var logger=require(_0x111c[10])(_0x111c[9]);var FaxMessage=require(_0x111c[12])[_0x111c[11]];var FaxRoom=require(_0x111c[12])[_0x111c[13]];var FaxAccount=require(_0x111c[12])[_0x111c[14]];var FaxAttachment=require(_0x111c[12])[_0x111c[15]];var Contact=require(_0x111c[12])[_0x111c[16]];module[_0x111c[17]]= function(){return {receivefax:function(_0x1096xe){return function(_0x1096xf){logger[_0x111c[21]](util[_0x111c[20]](_0x111c[18],_0x1096xe[_0x111c[19]]));var _0x1096x10=_[_0x111c[22]](_0x1096xe);var _0x1096x11;var _0x1096x12,_0x1096x13;return FaxAccount[_0x111c[83]]({where:{localstationid:_0x1096xe[_0x111c[63]]}})[_0x111c[37]](function(_0x1096x1c){if(!_0x1096x1c){throw  new Error(_0x111c[79])};logger[_0x111c[32]](_0x111c[80],_0x1096xe[_0x111c[63]]);_0x1096x11= _0x1096x1c;if(_0x1096x11[_0x111c[81]]){return Contact[_0x111c[82]]({where:{ListId:_0x1096x11[_0x111c[81]],$or:[{phone:_0x1096xe[_0x111c[19]]},{fax:_0x1096xe[_0x111c[19]]}]},defaults:{phone:_0x1096xe[_0x111c[19]],fax:_0x1096xe[_0x111c[19]],firstName:_0x1096xe[_0x111c[19]],ListId:_0x1096x11[_0x111c[81]]}})}else {return []}})[_0x111c[78]](function(_0x1096x1a,_0x1096x1b){if(_0x1096x1b!== undefined&&  !_0x1096x1b){return _0x1096x1a[_0x111c[72]]({fax:_0x1096xe[_0x111c[19]]})};return})[_0x111c[37]](function(){return FaxRoom[_0x111c[77]]({limit:1,where:{contact:_0x1096x10[_0x111c[19]],FaxAccountId:_0x1096x11[_0x111c[40]],status:{$ne:_0x111c[74]}},order:[[_0x111c[75],_0x111c[76]]]})})[_0x111c[37]](function(_0x1096x19){if(_0x1096x19[_0x111c[66]]){_0x1096x19= _[_0x111c[67]](_0x1096x19);return _0x1096x19[_0x111c[72]]({lastEvent:_0x111c[60],lastEventAt:moment()[_0x111c[20]](_0x111c[68]),status:_0x111c[69],openReason:_0x111c[70],faxIn:++_0x1096x19[_0x111c[71]]})}else {return FaxRoom[_0x111c[54]]({contact:_0x1096x10[_0x111c[19]],account:_0x1096x11[_0x111c[45]],status:_0x111c[73],lastEvent:_0x111c[60],lastEventAt:moment()[_0x111c[20]](_0x111c[68]),FaxAccountId:_0x1096x11[_0x111c[40]],faxIn:1})}})[_0x111c[37]](function(_0x1096x19){if(!_0x1096x19){throw  new Error(_0x111c[56])};logger[_0x111c[32]](_0x111c[57],_0x1096x19[_0x111c[40]]);_0x1096x13= _0x1096x19;_0x1096x10[_0x111c[58]]= _0x1096x19[_0x111c[40]];_0x1096x10[_0x111c[59]]= _0x111c[60];_0x1096x10[_0x111c[61]]= _0x1096x10[_0x111c[19]];_0x1096x10[_0x111c[62]]= _0x1096x10[_0x111c[63]];_0x1096x10[_0x111c[24]]= parseInt(_0x1096x10[_0x111c[30]])> 0?_0x111c[64]:_0x111c[65];return FaxMessage[_0x111c[54]](_0x1096x10)})[_0x111c[37]](function(_0x1096x16){if(!_0x1096x16){throw  new Error(_0x111c[44])};_0x1096x12= _0x1096x16;logger[_0x111c[32]](_0x111c[25],_0x1096x16[_0x111c[40]]);if(parseInt(_0x1096xe[_0x111c[30]])> 0){var _0x1096x17=path[_0x111c[46]](_0x1096xe[_0x111c[43]])[_0x111c[45]];var _0x1096x18=_0x1096x17+ _0x111c[47];return FaxAttachment[_0x111c[54]]({path:path[_0x111c[53]](config[_0x111c[48]],_0x111c[49],_0x111c[50],_0x111c[9],_0x111c[51],_0x111c[52],_0x1096x18),basename:_0x1096x18,name:_0x1096x17,FaxMessageId:_0x1096x16[_0x111c[40]]})};logger[_0x111c[24]](util[_0x111c[20]](_0x111c[55],_0x1096xe[_0x111c[30]]));return})[_0x111c[37]](function(_0x1096x15){if(!_0x1096x15){logger[_0x111c[24]](_0x111c[38]);return};logger[_0x111c[32]](_0x111c[39],_0x1096x15[_0x111c[40]]);return exec(_0x111c[41]+ _0x1096x15[_0x111c[5]]+ _0x111c[42]+ _0x1096xe[_0x111c[43]])})[_0x111c[37]](function(){if(parseInt(_0x1096xe[_0x111c[30]])> 0){logger[_0x111c[32]](_0x111c[31]);logger[_0x111c[21]](_0x111c[33]);process[_0x111c[35]]({message:_0x111c[34],doc:{message:_0x1096x12,account:_0x1096x11}});return _0x1096x12[_0x111c[36]]({plain:true})}})[_0x111c[29]](function(_0x1096x14){logger[_0x111c[24]](_0x111c[23],_0x1096x14);logger[_0x111c[24]](_0x111c[25],_0x1096x14[_0x111c[26]]);logger[_0x111c[24]](_0x111c[27],_0x1096x14[_0x111c[28]])})}},sendfax:function(_0x1096xe){return function(_0x1096xf){var _0x1096x12;return FaxMessage[_0x111c[83]]({where:{filename:_0x1096xe[_0x111c[43]],localstationid:_0x1096xe[_0x111c[63]]}})[_0x111c[37]](function(_0x1096x1e){if(!_0x1096x1e){throw  new Error(_0x111c[90])};_0x1096x12= _0x1096x1e;var _0x1096x1f=_0x111c[87];if(_0x1096xe[_0x111c[30]]=== _0x111c[91]){_0x1096x1f= _0x111c[92]};return _0x1096x12[_0x111c[72]]({remotestationid:_0x1096xe[_0x111c[93]],pagestransferred:_0x1096xe[_0x111c[30]],resolution:_0x1096xe[_0x111c[94]],transferrate:_0x1096xe[_0x111c[95]],status:_0x1096x1f})})[_0x111c[37]](function(_0x1096x16){logger[_0x111c[32]](_0x111c[88],_0x1096x16[_0x111c[40]]);return _0x1096x12[_0x111c[89]]()})[_0x111c[37]](function(_0x1096x1d){if(!_0x1096x1d){throw  new Error(_0x111c[86])};return _0x1096x1d[_0x111c[72]]({lastEvent:_0x111c[87]},{individualHooks:true})})[_0x111c[37]](function(_0x1096x19){logger[_0x111c[32]](_0x111c[85],_0x1096x19[_0x111c[40]])})[_0x111c[29]](function(_0x1096x14){logger[_0x111c[24]](_0x111c[84],_0x1096x14);logger[_0x111c[24]](_0x111c[25],_0x1096x14[_0x111c[26]]);logger[_0x111c[24]](_0x111c[27],_0x1096x14[_0x111c[28]])})}},faxstatus:function(_0x1096xe){return function(_0x1096xf){if(_0x1096xe[_0x111c[96]]!== _0x111c[35]){return BPromise[_0x111c[97]]()};return FaxMessage[_0x111c[83]]({where:{filename:_0x1096xe[_0x111c[43]],localstationid:_0x1096xe[_0x111c[63]]}})[_0x111c[37]](function(_0x1096x1e){if(!_0x1096x1e){throw  new Error(_0x111c[90])};return _0x1096x1e[_0x111c[72]]({channel:_0x1096xe[_0x111c[99]],channelstate:_0x1096xe[_0x111c[100]],channelstatedesc:_0x1096xe[_0x111c[101]],calleridnum:_0x1096xe[_0x111c[19]],calleridname:_0x1096xe[_0x111c[102]],connectedlinenum:_0x1096xe[_0x111c[103]],connectedlinename:_0x1096xe[_0x111c[104]],accountcode:_0x1096xe[_0x111c[105]],context:_0x1096xe[_0x111c[106]],exten:_0x1096xe[_0x111c[107]],priority:_0x1096xe[_0x111c[108]],uniqueid:_0x1096xe[_0x111c[109]],linkedid:_0x1096xe[_0x111c[110]],lastStatus:_0x1096xe[_0x111c[59]]})})[_0x111c[29]](function(_0x1096x14){logger[_0x111c[24]](_0x111c[98],_0x1096x14);logger[_0x111c[24]](_0x111c[25],_0x1096x14[_0x111c[26]]);logger[_0x111c[24]](_0x111c[27],_0x1096x14[_0x111c[28]])})}},faxerror:function(_0x1096xe){return function(_0x1096xf){if(!_0x1096xe[_0x111c[96]][_0x111c[112]](_0x111c[111])||  !_0x1096xe[_0x111c[113]]){return BPromise[_0x111c[97]]()};return FaxMessage[_0x111c[83]]({where:{channel:_0x1096xe[_0x111c[99]]}})[_0x111c[37]](function(_0x1096x1e){if(_0x1096x1e){return _0x1096x1e[_0x111c[72]]({error:_0x1096xe[_0x111c[113]]})};return})[_0x111c[29]](function(_0x1096x14){logger[_0x111c[24]](_0x111c[114],_0x1096x14)})}}}}