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