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