Built motion from commit 1fa89557.|2.6.10
[motion2.git] / server / config / schedule / whatsapp.js
index a4d1555..bb773fa 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x968c=['WhatsappInteraction','findAll','lastMsgAt','subtract','length','info','join','update','format','YYYY-MM-DD\x20HH:mm:ss','then','[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:','emit','whatsappInteraction:update','catch','error','start','lodash','moment','../../mysqldb','../logger','schedule','redis','localhost','socket.io-emitter'];(function(_0x690346,_0x40dc57){var _0x5e4dab=function(_0x52ef75){while(--_0x52ef75){_0x690346['push'](_0x690346['shift']());}};_0x5e4dab(++_0x40dc57);}(_0x968c,0xd9));var _0xc968=function(_0x3aca1e,_0x5233f6){_0x3aca1e=_0x3aca1e-0x0;var _0x3f63c9=_0x968c[_0x3aca1e];return _0x3f63c9;};'use strict';var _=require(_0xc968('0x0'));var moment=require(_0xc968('0x1'));var Redis=require('ioredis');var util=require('util');var config=require('../../config/environment');var db=require(_0xc968('0x2'))['db'];var logger=require(_0xc968('0x3'))(_0xc968('0x4'));config['redis']=_['defaults'](config[_0xc968('0x5')],{'host':_0xc968('0x6'),'port':0x18eb});var io=require(_0xc968('0x7'))(new Redis(config[_0xc968('0x5')]));function closeInteractions(){var _0x3648ba=[];return db[_0xc968('0x8')][_0xc968('0x9')]({'raw':!![],'attributes':['id',_0xc968('0xa')],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()[_0xc968('0xb')](0x18,'hours')}}})['then'](function(_0x431b0c){if(_0x431b0c&&_0x431b0c[_0xc968('0xc')]){_0x3648ba=_['map'](_0x431b0c||[],'id');logger[_0xc968('0xd')]('[WHATSAPP]\x20Interactions\x20to\x20close:',_0x3648ba[_0xc968('0xe')]());return db[_0xc968('0x8')][_0xc968('0xf')]({'closeReason':'system','disposition':'timeout','closed':!![],'closedAt':moment()[_0xc968('0x10')](_0xc968('0x11'))},{'where':{'id':_0x3648ba}});}})[_0xc968('0x12')](function(){if(_0x3648ba&&_0x3648ba[_0xc968('0xc')]){logger[_0xc968('0xd')](_0xc968('0x13'),_0x3648ba['join']());for(var _0x1bf905=0x0;_0x1bf905<_0x3648ba[_0xc968('0xc')];_0x1bf905++){io[_0xc968('0x14')](_0xc968('0x15'),{'id':_0x3648ba[_0x1bf905],'closed':!![]});}}})[_0xc968('0x16')](function(_0x4c0161){logger[_0xc968('0x17')]('[WHATSAPP]\x20Error\x20closing\x20interactions',_0x4c0161?util['inspect'](_0x4c0161,{'showHidden':![],'depth':null}):'');});}exports[_0xc968('0x18')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};
\ No newline at end of file
+var _0x3b7f=['[WHATSAPP]\x20Error\x20closing\x20interactions','start','moment','../../config/environment','../../mysqldb','../logger','schedule','redis','defaults','localhost','findAll','lastMsgAt','subtract','hours','then','length','info','[WHATSAPP]\x20Interactions\x20to\x20close:','update','system','format','YYYY-MM-DD\x20HH:mm:ss','join','whatsappInteraction:update'];(function(_0x17406a,_0x1e2320){var _0x1501ff=function(_0x4b075a){while(--_0x4b075a){_0x17406a['push'](_0x17406a['shift']());}};_0x1501ff(++_0x1e2320);}(_0x3b7f,0xf2));var _0xf3b7=function(_0x3f7f97,_0x560695){_0x3f7f97=_0x3f7f97-0x0;var _0x59b575=_0x3b7f[_0x3f7f97];return _0x59b575;};'use strict';var _=require('lodash');var moment=require(_0xf3b7('0x0'));var Redis=require('ioredis');var util=require('util');var config=require(_0xf3b7('0x1'));var db=require(_0xf3b7('0x2'))['db'];var logger=require(_0xf3b7('0x3'))(_0xf3b7('0x4'));config[_0xf3b7('0x5')]=_[_0xf3b7('0x6')](config['redis'],{'host':_0xf3b7('0x7'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xf3b7('0x5')]));function closeInteractions(){var _0x4a1ef3=[];return db['WhatsappInteraction'][_0xf3b7('0x8')]({'raw':!![],'attributes':['id',_0xf3b7('0x9')],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()[_0xf3b7('0xa')](0x18,_0xf3b7('0xb'))}}})[_0xf3b7('0xc')](function(_0x941d4d){if(_0x941d4d&&_0x941d4d[_0xf3b7('0xd')]){_0x4a1ef3=_['map'](_0x941d4d||[],'id');logger[_0xf3b7('0xe')](_0xf3b7('0xf'),_0x4a1ef3['join']());return db['WhatsappInteraction'][_0xf3b7('0x10')]({'closeReason':_0xf3b7('0x11'),'disposition':'timeout','closed':!![],'closedAt':moment()[_0xf3b7('0x12')](_0xf3b7('0x13'))},{'where':{'id':_0x4a1ef3}});}})['then'](function(){if(_0x4a1ef3&&_0x4a1ef3['length']){logger[_0xf3b7('0xe')]('[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:',_0x4a1ef3[_0xf3b7('0x14')]());for(var _0x3aecb9=0x0;_0x3aecb9<_0x4a1ef3[_0xf3b7('0xd')];_0x3aecb9++){io['emit'](_0xf3b7('0x15'),{'id':_0x4a1ef3[_0x3aecb9],'closed':!![]});}}})['catch'](function(_0x143f98){logger['error'](_0xf3b7('0x16'),_0x143f98?util['inspect'](_0x143f98,{'showHidden':![],'depth':null}):'');});}exports[_0xf3b7('0x17')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};
\ No newline at end of file