1 // *************************************************************************
3 // * xCALLY Motion - The Omnichannel Contact Center *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved *
6 // *************************************************************************
8 // * Email: info@xcally.com *
9 // * Website: https://www.xcally.com *
11 // *************************************************************************
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold. *
17 // *************************************************************************
18 var _0x7fcf=['hours','info','join','update','system','timeout','format','YYYY-MM-DD\x20HH:mm:ss','then','length','[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:','emit','whatsappInteraction:update','catch','[WHATSAPP]\x20Error\x20closing\x20interactions','start','util','../../config/environment','../logger','schedule','redis','defaults','localhost','socket.io-emitter','WhatsappInteraction','subtract'];(function(_0x21ecf3,_0x3b4b99){var _0x3cf63a=function(_0x536c67){while(--_0x536c67){_0x21ecf3['push'](_0x21ecf3['shift']());}};_0x3cf63a(++_0x3b4b99);}(_0x7fcf,0xe0));var _0xf7fc=function(_0x47b58b,_0x41a189){_0x47b58b=_0x47b58b-0x0;var _0x46bebe=_0x7fcf[_0x47b58b];return _0x46bebe;};'use strict';var _=require('lodash');var moment=require('moment');var Redis=require('ioredis');var util=require(_0xf7fc('0x0'));var config=require(_0xf7fc('0x1'));var db=require('../../mysqldb')['db'];var logger=require(_0xf7fc('0x2'))(_0xf7fc('0x3'));config[_0xf7fc('0x4')]=_[_0xf7fc('0x5')](config[_0xf7fc('0x4')],{'host':_0xf7fc('0x6'),'port':0x18eb});var io=require(_0xf7fc('0x7'))(new Redis(config[_0xf7fc('0x4')]));function closeInteractions(){var _0x14f10f=[];return db[_0xf7fc('0x8')]['findAll']({'raw':!![],'attributes':['id','lastMsgAt'],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()[_0xf7fc('0x9')](0x18,_0xf7fc('0xa'))}}})['then'](function(_0x1053f4){if(_0x1053f4&&_0x1053f4['length']){_0x14f10f=_['map'](_0x1053f4||[],'id');logger[_0xf7fc('0xb')]('[WHATSAPP]\x20Interactions\x20to\x20close:',_0x14f10f[_0xf7fc('0xc')]());return db[_0xf7fc('0x8')][_0xf7fc('0xd')]({'closeReason':_0xf7fc('0xe'),'disposition':_0xf7fc('0xf'),'closed':!![],'closedAt':moment()[_0xf7fc('0x10')](_0xf7fc('0x11'))},{'where':{'id':_0x14f10f}});}})[_0xf7fc('0x12')](function(){if(_0x14f10f&&_0x14f10f[_0xf7fc('0x13')]){logger[_0xf7fc('0xb')](_0xf7fc('0x14'),_0x14f10f['join']());for(var _0x21e054=0x0;_0x21e054<_0x14f10f['length'];_0x21e054++){io[_0xf7fc('0x15')](_0xf7fc('0x16'),{'id':_0x14f10f[_0x21e054],'closed':!![]});}}})[_0xf7fc('0x17')](function(_0x5a5639){logger['error'](_0xf7fc('0x18'),_0x5a5639?util['inspect'](_0x5a5639,{'showHidden':![],'depth':null}):'');});}exports[_0xf7fc('0x19')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};