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