db08ba7070531570a05e22f36f85268dd4c9895a
[motion2.git] / server / config / schedule / whatsapp.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
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.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xc894=['localhost','socket.io-emitter','WhatsappInteraction','findAll','subtract','hours','then','length','map','[WHATSAPP]\x20Interactions\x20to\x20close:','update','timeout','format','YYYY-MM-DD\x20HH:mm:ss','info','[WHATSAPP]\x20Sending\x20updates\x20for\x20interactions:','join','emit','catch','inspect','start','lodash','moment','ioredis','util','../logger','schedule','redis','defaults'];(function(_0x17c012,_0x581e0d){var _0x19e62c=function(_0x4fb47e){while(--_0x4fb47e){_0x17c012['push'](_0x17c012['shift']());}};_0x19e62c(++_0x581e0d);}(_0xc894,0xa6));var _0x4c89=function(_0x35ddb8,_0xa6d8e6){_0x35ddb8=_0x35ddb8-0x0;var _0x5dc721=_0xc894[_0x35ddb8];return _0x5dc721;};'use strict';var _=require(_0x4c89('0x0'));var moment=require(_0x4c89('0x1'));var Redis=require(_0x4c89('0x2'));var util=require(_0x4c89('0x3'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];var logger=require(_0x4c89('0x4'))(_0x4c89('0x5'));config[_0x4c89('0x6')]=_[_0x4c89('0x7')](config['redis'],{'host':_0x4c89('0x8'),'port':0x18eb});var io=require(_0x4c89('0x9'))(new Redis(config[_0x4c89('0x6')]));function closeInteractions(){var _0x501fc7=[];return db[_0x4c89('0xa')][_0x4c89('0xb')]({'raw':!![],'attributes':['id','lastMsgAt'],'where':{'closed':![],'lastMsgDirection':'in','lastMsgAt':{'$lt':moment()[_0x4c89('0xc')](0x18,_0x4c89('0xd'))}}})[_0x4c89('0xe')](function(_0x392a80){if(_0x392a80&&_0x392a80[_0x4c89('0xf')]){_0x501fc7=_[_0x4c89('0x10')](_0x392a80||[],'id');logger['info'](_0x4c89('0x11'),_0x501fc7['join']());return db[_0x4c89('0xa')][_0x4c89('0x12')]({'closeReason':'system','disposition':_0x4c89('0x13'),'closed':!![],'closedAt':moment()[_0x4c89('0x14')](_0x4c89('0x15'))},{'where':{'id':_0x501fc7}});}})[_0x4c89('0xe')](function(){if(_0x501fc7&&_0x501fc7[_0x4c89('0xf')]){logger[_0x4c89('0x16')](_0x4c89('0x17'),_0x501fc7[_0x4c89('0x18')]());for(var _0xc3e591=0x0;_0xc3e591<_0x501fc7['length'];_0xc3e591++){io[_0x4c89('0x19')]('whatsappInteraction:update',{'id':_0x501fc7[_0xc3e591],'closed':!![]});}}})[_0x4c89('0x1a')](function(_0x129a99){logger['error']('[WHATSAPP]\x20Error\x20closing\x20interactions',_0x129a99?util[_0x4c89('0x1b')](_0x129a99,{'showHidden':![],'depth':null}):'');});}exports[_0x4c89('0x1c')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};