Built motion from commit (unavailable).|2.5.11
[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 _0x45d7=['start','lodash','moment','ioredis','util','../../config/environment','../../mysqldb','../logger','schedule','redis','defaults','localhost','socket.io-emitter','Setting','find','chatTimeout','then','ChatInteraction','lastMsgAt','subtract','length','info','[CHAT]\x20Interactions\x20to\x20close:','join','update','timeout','format','YYYY-MM-DD\x20HH:mm:ss','emit','chatInteraction:update','catch','error','[CHAT]\x20Error\x20closing\x20interactions','inspect'];(function(_0x465028,_0x4570ac){var _0xb783d4=function(_0x5458c5){while(--_0x5458c5){_0x465028['push'](_0x465028['shift']());}};_0xb783d4(++_0x4570ac);}(_0x45d7,0x1dd));var _0x745d=function(_0x502c7d,_0x2f1285){_0x502c7d=_0x502c7d-0x0;var _0x30b7ed=_0x45d7[_0x502c7d];return _0x30b7ed;};'use strict';var _=require(_0x745d('0x0'));var moment=require(_0x745d('0x1'));var Redis=require(_0x745d('0x2'));var util=require(_0x745d('0x3'));var config=require(_0x745d('0x4'));var db=require(_0x745d('0x5'))['db'];var logger=require(_0x745d('0x6'))(_0x745d('0x7'));config[_0x745d('0x8')]=_[_0x745d('0x9')](config[_0x745d('0x8')],{'host':_0x745d('0xa'),'port':0x18eb});var io=require(_0x745d('0xb'))(new Redis(config[_0x745d('0x8')]));function closeInteractions(){var _0x190357=0x0;var _0x3621f0=[];return db[_0x745d('0xc')][_0x745d('0xd')]({'raw':!![],'attributes':['id',_0x745d('0xe')],'where':{'id':0x1}})[_0x745d('0xf')](function(_0x1ea3ec){_0x190357=_0x1ea3ec[_0x745d('0xe')];if(_0x190357){return db[_0x745d('0x10')]['findAll']({'raw':!![],'attributes':['id',_0x745d('0x11')],'where':{'closed':![],'lastMsgAt':{'$lt':moment()[_0x745d('0x12')](_0x1ea3ec[_0x745d('0xe')],'minutes')}}});}else{return[];}})[_0x745d('0xf')](function(_0x1a2dff){if(_0x1a2dff&&_0x1a2dff[_0x745d('0x13')]){_0x3621f0=_['map'](_0x1a2dff||[],'id');logger[_0x745d('0x14')](_0x745d('0x15'),_0x3621f0[_0x745d('0x16')]());return db[_0x745d('0x10')][_0x745d('0x17')]({'closeReason':'system','disposition':_0x745d('0x18'),'closed':!![],'closedAt':moment()[_0x745d('0x19')](_0x745d('0x1a'))},{'where':{'id':_0x3621f0}});}})[_0x745d('0xf')](function(){if(_0x3621f0&&_0x3621f0['length']){logger[_0x745d('0x14')]('[CHAT]\x20Sending\x20updates\x20for\x20interactions:',_0x3621f0['join']());for(var _0x15cb39=0x0;_0x15cb39<_0x3621f0[_0x745d('0x13')];_0x15cb39++){io[_0x745d('0x1b')](_0x745d('0x1c'),{'id':_0x3621f0[_0x15cb39],'closed':!![]});}}})[_0x745d('0x1d')](function(_0x562ea1){logger[_0x745d('0x1e')](_0x745d('0x1f'),_0x562ea1?util[_0x745d('0x20')](_0x562ea1,{'showHidden':![],'depth':null}):'');});}exports[_0x745d('0x21')]=function(){setInterval(function(){return closeInteractions();},0x3c*0x3e8);return closeInteractions();};