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