Built motion from commit fd055180.|2.6.30
[motion2.git] / server / config / schedule / chat.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 _0xccec=['defaults','redis','localhost','socket.io-emitter','Setting','find','chatTimeout','then','ChatInteraction','findAll','lastMsgAt','subtract','minutes','length','map','info','[CHAT]\x20Interactions\x20to\x20close:','join','system','timeout','format','YYYY-MM-DD\x20HH:mm:ss','[CHAT]\x20Sending\x20updates\x20for\x20interactions:','emit','catch','[CHAT]\x20Error\x20closing\x20interactions','inspect','start','lodash','moment','ioredis','util','../../config/environment','../../mysqldb','../logger','schedule'];(function(_0x3acdef,_0x2a7ae7){var _0x3a252a=function(_0x43b100){while(--_0x43b100){_0x3acdef['push'](_0x3acdef['shift']());}};_0x3a252a(++_0x2a7ae7);}(_0xccec,0x118));var _0xccce=function(_0x41010e,_0x25e9c5){_0x41010e=_0x41010e-0x0;var _0x59e342=_0xccec[_0x41010e];return _0x59e342;};'use strict';var _=require(_0xccce('0x0'));var moment=require(_0xccce('0x1'));var Redis=require(_0xccce('0x2'));var util=require(_0xccce('0x3'));var config=require(_0xccce('0x4'));var db=require(_0xccce('0x5'))['db'];var logger=require(_0xccce('0x6'))(_0xccce('0x7'));config['redis']=_[_0xccce('0x8')](config[_0xccce('0x9')],{'host':_0xccce('0xa'),'port':0x18eb});var io=require(_0xccce('0xb'))(new Redis(config[_0xccce('0x9')]));function closeInteractions(){var _0x24e1bd=0x0;var _0x95f579=[];return db[_0xccce('0xc')][_0xccce('0xd')]({'raw':!![],'attributes':['id',_0xccce('0xe')],'where':{'id':0x1}})[_0xccce('0xf')](function(_0x596cc4){_0x24e1bd=_0x596cc4[_0xccce('0xe')];if(_0x24e1bd){return db[_0xccce('0x10')][_0xccce('0x11')]({'raw':!![],'attributes':['id',_0xccce('0x12')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0xccce('0x13')](_0x596cc4[_0xccce('0xe')],_0xccce('0x14'))}}});}else{return[];}})[_0xccce('0xf')](function(_0x26925a){if(_0x26925a&&_0x26925a[_0xccce('0x15')]){_0x95f579=_[_0xccce('0x16')](_0x26925a||[],'id');logger[_0xccce('0x17')](_0xccce('0x18'),_0x95f579[_0xccce('0x19')]());return db[_0xccce('0x10')]['update']({'closeReason':_0xccce('0x1a'),'disposition':_0xccce('0x1b'),'closed':!![],'closedAt':moment()[_0xccce('0x1c')](_0xccce('0x1d'))},{'where':{'id':_0x95f579}});}})[_0xccce('0xf')](function(){if(_0x95f579&&_0x95f579['length']){logger[_0xccce('0x17')](_0xccce('0x1e'),_0x95f579[_0xccce('0x19')]());for(var _0x5cb068=0x0;_0x5cb068<_0x95f579[_0xccce('0x15')];_0x5cb068++){io[_0xccce('0x1f')]('chatInteraction:update',{'id':_0x95f579[_0x5cb068],'closed':!![]});}}})[_0xccce('0x20')](function(_0x3c137c){logger['error'](_0xccce('0x21'),_0x3c137c?util[_0xccce('0x22')](_0x3c137c,{'showHidden':![],'depth':null}):'');});}exports[_0xccce('0x23')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};