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