861c1a192bdb7b3ada1b60795b0e26b1b2865dab
[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 _0x0c80=['Setting','find','then','chatTimeout','findAll','lastMsgAt','subtract','minutes','length','map','info','[CHAT]\x20Interactions\x20to\x20close:','join','ChatInteraction','system','format','YYYY-MM-DD\x20HH:mm:ss','[CHAT]\x20Sending\x20updates\x20for\x20interactions:','emit','catch','inspect','start','lodash','moment','ioredis','util','../../config/environment','../../mysqldb','../logger','schedule','redis','localhost','socket.io-emitter'];(function(_0x4d2222,_0x1f605d){var _0x4df934=function(_0x3fcf21){while(--_0x3fcf21){_0x4d2222['push'](_0x4d2222['shift']());}};_0x4df934(++_0x1f605d);}(_0x0c80,0x11e));var _0x00c8=function(_0x53ccf2,_0x13cb67){_0x53ccf2=_0x53ccf2-0x0;var _0x5a2964=_0x0c80[_0x53ccf2];return _0x5a2964;};'use strict';var _=require(_0x00c8('0x0'));var moment=require(_0x00c8('0x1'));var Redis=require(_0x00c8('0x2'));var util=require(_0x00c8('0x3'));var config=require(_0x00c8('0x4'));var db=require(_0x00c8('0x5'))['db'];var logger=require(_0x00c8('0x6'))(_0x00c8('0x7'));config['redis']=_['defaults'](config[_0x00c8('0x8')],{'host':_0x00c8('0x9'),'port':0x18eb});var io=require(_0x00c8('0xa'))(new Redis(config[_0x00c8('0x8')]));function closeInteractions(){var _0x4e8c77=0x0;var _0x36be7e=[];return db[_0x00c8('0xb')][_0x00c8('0xc')]({'raw':!![],'attributes':['id','chatTimeout'],'where':{'id':0x1}})[_0x00c8('0xd')](function(_0x2b1729){_0x4e8c77=_0x2b1729[_0x00c8('0xe')];if(_0x4e8c77){return db['ChatInteraction'][_0x00c8('0xf')]({'raw':!![],'attributes':['id',_0x00c8('0x10')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0x00c8('0x11')](_0x2b1729[_0x00c8('0xe')],_0x00c8('0x12'))}}});}else{return[];}})[_0x00c8('0xd')](function(_0x5db58b){if(_0x5db58b&&_0x5db58b[_0x00c8('0x13')]){_0x36be7e=_[_0x00c8('0x14')](_0x5db58b||[],'id');logger[_0x00c8('0x15')](_0x00c8('0x16'),_0x36be7e[_0x00c8('0x17')]());return db[_0x00c8('0x18')]['update']({'closeReason':_0x00c8('0x19'),'disposition':'timeout','closed':!![],'closedAt':moment()[_0x00c8('0x1a')](_0x00c8('0x1b'))},{'where':{'id':_0x36be7e}});}})[_0x00c8('0xd')](function(){if(_0x36be7e&&_0x36be7e[_0x00c8('0x13')]){logger[_0x00c8('0x15')](_0x00c8('0x1c'),_0x36be7e['join']());for(var _0x17f3e5=0x0;_0x17f3e5<_0x36be7e[_0x00c8('0x13')];_0x17f3e5++){io[_0x00c8('0x1d')]('chatInteraction:update',{'id':_0x36be7e[_0x17f3e5],'closed':!![]});}}})[_0x00c8('0x1e')](function(_0x57f783){logger['error']('[CHAT]\x20Error\x20closing\x20interactions',_0x57f783?util[_0x00c8('0x1f')](_0x57f783,{'showHidden':![],'depth':null}):'');});}exports[_0x00c8('0x20')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};