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