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