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